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 var precision = zoomPrecision(zoom);
63 bounds = normalBounds(bounds);
65 var lat = loc.lat.toFixed(precision),
66 lon = (loc.lon || loc.lng).toFixed(precision);
69 var minlon = bounds.getWest().toFixed(precision),
70 minlat = bounds.getSouth().toFixed(precision),
71 maxlon = bounds.getEast().toFixed(precision),
72 maxlat = bounds.getNorth().toFixed(precision);
75 $(".geolink").each(setGeolink);
77 function setGeolink(index, link) {
78 var base = link.href.split('?')[0],
79 qs = link.href.split('?')[1],
80 args = querystring.parse(qs);
82 if ($(link).hasClass("llz")) {
88 } else if (minlon && $(link).hasClass("bbox")) {
90 bbox: minlon + "," + minlat + "," + maxlon + "," + maxlat
94 if (layers && $(link).hasClass("layers")) args.layers = layers;
95 if (object && $(link).hasClass("object")) args[object.type] = object.id;
97 var minzoom = $(link).data("minzoom");
99 var name = link.id.replace(/anchor$/, "");
100 $(link).off("click.minzoom");
101 if (zoom >= minzoom) {
103 .attr("title", I18n.t("javascripts.site." + name + "_tooltip"))
104 .removeClass("disabled");
107 .attr("title", I18n.t("javascripts.site." + name + "_disabled_tooltip"))
108 .addClass("disabled")
109 .on("click.minzoom", function () {
110 alert(I18n.t("javascripts.site." + name + "_zoom_alert"));
115 link.href = base + '?' + querystring.stringify(args);
119 // generate a cookie-safe string of map state
120 function cookieContent(map) {
121 var center = map.getCenter().wrap();
122 return [center.lng, center.lat, map.getZoom(), map.getLayersCode()].join('|');
126 * Forms which have been cached by rails may have the wrong
127 * authenticity token, so patch up any forms with the correct
128 * token taken from the page header.
130 $(document).ready(function () {
131 var auth_token = $("meta[name=csrf-token]").attr("content");
132 $("form input[name=authenticity_token]").val(auth_token);