3 //= require jquery.timers
4 //= require jquery.cookie
5 //= require jquery.throttle-debounce
9 //= require leaflet.osm
10 //= require leaflet.hash
11 //= require leaflet.zoom
12 //= require leaflet.extend
13 //= require leaflet.locationfilter
14 //= require i18n/translations
22 //= require querystring
24 var querystring = require('querystring-component');
26 function zoomPrecision(zoom) {
27 return Math.max(0, Math.ceil(Math.log(zoom) / Math.LN2));
30 function normalBounds(bounds) {
31 if (bounds instanceof L.LatLngBounds) return bounds;
32 return new L.LatLngBounds(
33 new L.LatLng(bounds[0][0], bounds[0][1]),
34 new L.LatLng(bounds[1][0], bounds[1][1]));
37 function remoteEditHandler(bbox, select) {
40 left: bbox.getWest() - 0.0001,
41 top: bbox.getNorth() + 0.0001,
42 right: bbox.getEast() + 0.0001,
43 bottom: bbox.getSouth() - 0.0001
46 if (select) query.select = select;
48 .attr("src", "http://127.0.0.1:8111/load_and_zoom?" + querystring.stringify(query))
49 .load(function() { loaded = true; });
51 setTimeout(function () {
52 if (!loaded) alert(I18n.t('site.index.remote_failed'));
59 * Called as the user scrolls/zooms around to maniplate hrefs of the
60 * view tab and various other links
62 function updatelinks(loc, zoom, layers, bounds, object) {
63 $(".geolink").each(function(index, link) {
64 var href = link.href.split(/[?#]/)[0],
65 args = querystring.parse(link.search.substring(1));
67 if (bounds && $(link).hasClass("bbox")) args.bbox = normalBounds(bounds).toBBoxString();
68 if (object && $(link).hasClass("object")) args[object.type] = object.id;
70 var query = querystring.stringify(args);
71 if (query) href += '?' + query;
73 if ($(link).hasClass("llz")) {
76 lon: loc.lon || loc.lng,
80 if (layers && $(link).hasClass("layers")) {
84 href += OSM.formatHash(args);
89 var minzoom = $(link).data("minzoom");
91 var name = link.id.replace(/anchor$/, "");
92 $(link).off("click.minzoom");
93 if (zoom >= minzoom) {
95 .attr("title", I18n.t("javascripts.site." + name + "_tooltip"))
96 .removeClass("disabled");
99 .attr("title", I18n.t("javascripts.site." + name + "_disabled_tooltip"))
100 .addClass("disabled")
101 .on("click.minzoom", function () {
102 alert(I18n.t("javascripts.site." + name + "_zoom_alert"));
110 // generate a cookie-safe string of map state
111 function cookieContent(map) {
112 var center = map.getCenter().wrap();
113 return [center.lng, center.lat, map.getZoom(), map.getLayersCode()].join('|');
117 * Forms which have been cached by rails may have the wrong
118 * authenticity token, so patch up any forms with the correct
119 * token taken from the page header.
121 $(document).ready(function () {
122 var auth_token = $("meta[name=csrf-token]").attr("content");
123 $("form input[name=authenticity_token]").val(auth_token);