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
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);
100 var editDisabled = zoom < 13;
102 .tooltip({placement: 'bottom'})
103 .off('click.minzoom')
104 .on('click.minzoom', function() { return !editDisabled; })
105 .toggleClass('disabled', editDisabled)
106 .attr('data-original-title', editDisabled ?
107 I18n.t('javascripts.site.edit_disabled_tooltip') : '');
109 var historyDisabled = zoom < 11;
111 .tooltip({placement: 'bottom'})
112 .off('click.minzoom')
113 .on('click.minzoom', function() { return !historyDisabled; })
114 .toggleClass('disabled', historyDisabled)
115 .attr('data-original-title', historyDisabled ?
116 I18n.t('javascripts.site.history_disabled_tooltip') : '');
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('|');
125 function escapeHTML(string) {
133 return string == null ? '' : (string + '').replace(/[&<>"']/g, function(match) {
134 return htmlEscapes[match];
139 * Forms which have been cached by rails may have the wrong
140 * authenticity token, so patch up any forms with the correct
141 * token taken from the page header.
143 $(document).ready(function () {
144 var auth_token = $("meta[name=csrf-token]").attr("content");
145 $("form input[name=authenticity_token]").val(auth_token);