3 //= require jquery.timers
 
   4 //= require jquery.cookie
 
   7 //= require leaflet.osm
 
   8 //= require leaflet.hash
 
   9 //= require leaflet.zoom
 
  10 //= require leaflet.extend
 
  11 //= require leaflet.locationfilter
 
  12 //= require i18n/translations
 
  21 //= require querystring
 
  23 var querystring = require('querystring-component');
 
  25 function zoomPrecision(zoom) {
 
  26     return Math.max(0, Math.ceil(Math.log(zoom) / Math.LN2));
 
  29 function normalBounds(bounds) {
 
  30     if (bounds instanceof L.LatLngBounds) return bounds;
 
  31     return new L.LatLngBounds(
 
  32         new L.LatLng(bounds[0][0], bounds[0][1]),
 
  33         new L.LatLng(bounds[1][0], bounds[1][1]));
 
  36 function remoteEditHandler(bbox, select) {
 
  39           left: bbox.getWest() - 0.0001,
 
  40           top: bbox.getNorth() + 0.0001,
 
  41           right: bbox.getEast() + 0.0001,
 
  42           bottom: bbox.getSouth() - 0.0001
 
  45   if (select) query.select = select;
 
  47     .attr("src", "http://127.0.0.1:8111/load_and_zoom?" + querystring.stringify(query))
 
  48     .load(function() { loaded = true; });
 
  50   setTimeout(function () {
 
  51     if (!loaded) alert(I18n.t('site.index.remote_failed'));
 
  58  * Called as the user scrolls/zooms around to maniplate hrefs of the
 
  59  * view tab and various other links
 
  61 function updatelinks(loc, zoom, layers, bounds, object) {
 
  62   $(".geolink").each(function(index, link) {
 
  63     var base = link.href.split('?')[0],
 
  64         args = querystring.parse(link.search.substring(1));
 
  66     if (bounds && $(link).hasClass("bbox")) args.bbox = normalBounds(bounds).toBBoxString();
 
  67     if (layers && $(link).hasClass("layers")) args.layers = layers;
 
  68     if (object && $(link).hasClass("object")) args[object.type] = object.id;
 
  70     var href = base + '?' + querystring.stringify(args);
 
  72     if ($(link).hasClass("llz")) {
 
  73       href += OSM.formatHash({lat: loc.lat, lon: loc.lon || loc.lng, zoom: zoom});
 
  78     var minzoom = $(link).data("minzoom");
 
  80       var name = link.id.replace(/anchor$/, "");
 
  81       $(link).off("click.minzoom");
 
  82       if (zoom >= minzoom) {
 
  84           .attr("title", I18n.t("javascripts.site." + name + "_tooltip"))
 
  85           .removeClass("disabled");
 
  88           .attr("title", I18n.t("javascripts.site." + name + "_disabled_tooltip"))
 
  90           .on("click.minzoom", function () {
 
  91             alert(I18n.t("javascripts.site." + name + "_zoom_alert"));
 
  99 // generate a cookie-safe string of map state
 
 100 function cookieContent(map) {
 
 101   var center = map.getCenter().wrap();
 
 102   return [center.lng, center.lat, map.getZoom(), map.getLayersCode()].join('|');
 
 106  * Forms which have been cached by rails may have the wrong
 
 107  * authenticity token, so patch up any forms with the correct
 
 108  * token taken from the page header.
 
 110 $(document).ready(function () {
 
 111   var auth_token = $("meta[name=csrf-token]").attr("content");
 
 112   $("form input[name=authenticity_token]").val(auth_token);