3 //= require jquery.timers
4 //= require jquery.cookie
5 //= require jquery.throttle-debounce
6 //= require bootstrap.tooltip
10 //= require leaflet.osm
11 //= require leaflet.hash
12 //= require leaflet.zoom
13 //= require leaflet.extend
14 //= require leaflet.locationfilter
15 //= require i18n/translations
23 //= require querystring
25 var querystring = require('querystring-component');
27 function zoomPrecision(zoom) {
28 return Math.max(0, Math.ceil(Math.log(zoom) / Math.LN2));
31 function normalBounds(bounds) {
32 if (bounds instanceof L.LatLngBounds) return bounds;
33 return new L.LatLngBounds(
34 new L.LatLng(bounds[0][0], bounds[0][1]),
35 new L.LatLng(bounds[1][0], bounds[1][1]));
38 function remoteEditHandler(bbox, select) {
41 left: bbox.getWest() - 0.0001,
42 top: bbox.getNorth() + 0.0001,
43 right: bbox.getEast() + 0.0001,
44 bottom: bbox.getSouth() - 0.0001
47 if (select) query.select = select;
49 var iframe = $('<iframe>')
52 .attr("src", "http://127.0.0.1:8111/load_and_zoom?" + querystring.stringify(query))
53 .on('load', function() {
58 setTimeout(function () {
60 alert(I18n.t('site.index.remote_failed'));
69 * Called as the user scrolls/zooms around to maniplate hrefs of the
70 * view tab and various other links
72 function updatelinks(loc, zoom, layers, bounds, object) {
73 $(".geolink").each(function(index, link) {
74 var href = link.href.split(/[?#]/)[0],
75 args = querystring.parse(link.search.substring(1));
77 if (bounds && $(link).hasClass("bbox")) args.bbox = normalBounds(bounds).toBBoxString();
78 if (object && $(link).hasClass("object")) args[object.type] = object.id;
80 var query = querystring.stringify(args);
81 if (query) href += '?' + query;
83 if ($(link).hasClass("llz")) {
86 lon: loc.lon || loc.lng,
90 if (layers && $(link).hasClass("layers")) {
94 href += OSM.formatHash(args);
99 var minzoom = $(link).data("minzoom");
101 var name = link.id.replace(/anchor$/, "");
102 $(link).off("click.minzoom");
103 if (zoom >= minzoom) {
105 .attr("title", I18n.t("javascripts.site." + name + "_tooltip"))
106 .removeClass("disabled");
109 .attr("title", I18n.t("javascripts.site." + name + "_disabled_tooltip"))
110 .addClass("disabled")
111 .on("click.minzoom", function () {
112 alert(I18n.t("javascripts.site." + name + "_zoom_alert"));
120 // generate a cookie-safe string of map state
121 function cookieContent(map) {
122 var center = map.getCenter().wrap();
123 return [center.lng, center.lat, map.getZoom(), map.getLayersCode()].join('|');
126 function escapeHTML(string) {
134 return string == null ? '' : (string + '').replace(/[&<>"']/g, function(match) {
135 return htmlEscapes[match];
140 * Forms which have been cached by rails may have the wrong
141 * authenticity token, so patch up any forms with the correct
142 * token taken from the page header.
144 $(document).ready(function () {
145 var auth_token = $("meta[name=csrf-token]").attr("content");
146 $("form input[name=authenticity_token]").val(auth_token);