3 //= require jquery.timers
4 //= require jquery.cookie
5 //= require jquery.throttle-debounce
6 //= require bootstrap.tooltip
7 //= require bootstrap.dropdown
11 //= require leaflet.osm
12 //= require leaflet.hash
13 //= require leaflet.zoom
14 //= require leaflet.extend
15 //= require leaflet.locationfilter
16 //= require i18n/translations
24 //= require querystring
26 var querystring = require('querystring-component');
28 function zoomPrecision(zoom) {
29 return Math.max(0, Math.ceil(Math.log(zoom) / Math.LN2));
32 function normalBounds(bounds) {
33 if (bounds instanceof L.LatLngBounds) return bounds;
34 return new L.LatLngBounds(
35 new L.LatLng(bounds[0][0], bounds[0][1]),
36 new L.LatLng(bounds[1][0], bounds[1][1]));
39 function remoteEditHandler(bbox, select) {
42 left: bbox.getWest() - 0.0001,
43 top: bbox.getNorth() + 0.0001,
44 right: bbox.getEast() + 0.0001,
45 bottom: bbox.getSouth() - 0.0001
48 if (select) query.select = select;
50 var iframe = $('<iframe>')
53 .attr("src", "http://127.0.0.1:8111/load_and_zoom?" + querystring.stringify(query))
54 .on('load', function() {
59 setTimeout(function () {
61 alert(I18n.t('site.index.remote_failed'));
70 * Called as the user scrolls/zooms around to maniplate hrefs of the
71 * view tab and various other links
73 function updatelinks(loc, zoom, layers, bounds, object) {
74 $(".geolink").each(function(index, link) {
75 var href = link.href.split(/[?#]/)[0],
76 args = querystring.parse(link.search.substring(1));
78 if (bounds && $(link).hasClass("bbox")) args.bbox = normalBounds(bounds).toBBoxString();
79 if (object && $(link).hasClass("object")) args[object.type] = object.id;
81 var query = querystring.stringify(args);
82 if (query) href += '?' + query;
84 if ($(link).hasClass("llz")) {
87 lon: loc.lon || loc.lng,
91 if (layers && $(link).hasClass("layers")) {
95 href += OSM.formatHash(args);
100 var minzoom = $(link).data("minzoom");
102 var name = link.id.replace(/anchor$/, "");
103 $(link).off("click.minzoom");
104 if (zoom >= minzoom) {
106 .attr("title", I18n.t("javascripts.site." + name + "_tooltip"))
107 .removeClass("disabled");
110 .attr("title", I18n.t("javascripts.site." + name + "_disabled_tooltip"))
111 .addClass("disabled")
112 .on("click.minzoom", function () {
113 alert(I18n.t("javascripts.site." + name + "_zoom_alert"));
121 // generate a cookie-safe string of map state
122 function cookieContent(map) {
123 var center = map.getCenter().wrap();
124 return [center.lng, center.lat, map.getZoom(), map.getLayersCode()].join('|');
127 function escapeHTML(string) {
135 return string == null ? '' : (string + '').replace(/[&<>"']/g, function(match) {
136 return htmlEscapes[match];
141 * Forms which have been cached by rails may have the wrong
142 * authenticity token, so patch up any forms with the correct
143 * token taken from the page header.
145 $(document).ready(function () {
146 var auth_token = $("meta[name=csrf-token]").attr("content");
147 $("form input[name=authenticity_token]").val(auth_token);