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
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 remoteEditHandler(bbox, select) {
32 left: bbox.getWest() - 0.0001,
33 top: bbox.getNorth() + 0.0001,
34 right: bbox.getEast() + 0.0001,
35 bottom: bbox.getSouth() - 0.0001
38 if (select) query.select = select;
40 var iframe = $('<iframe>')
43 .attr("src", "http://127.0.0.1:8111/load_and_zoom?" + querystring.stringify(query))
44 .on('load', function() {
49 setTimeout(function () {
51 alert(I18n.t('site.index.remote_failed'));
60 * Called as the user scrolls/zooms around to maniplate hrefs of the
61 * view tab and various other links
63 function updatelinks(loc, zoom, layers, object) {
64 $(".geolink").each(function(index, link) {
65 var href = link.href.split(/[?#]/)[0],
66 args = querystring.parse(link.search.substring(1));
68 if (object && $(link).hasClass("object")) args[object.type] = object.id;
70 var query = querystring.stringify(args);
71 if (query) href += '?' + query;
75 lon: loc.lon || loc.lng,
79 if (layers && $(link).hasClass("layers")) {
83 href += OSM.formatHash(args);
88 var editDisabled = zoom < 13;
90 .tooltip({placement: 'bottom'})
92 .on('click.minzoom', function() { return !editDisabled; })
93 .toggleClass('disabled', editDisabled)
94 .attr('data-original-title', editDisabled ?
95 I18n.t('javascripts.site.edit_disabled_tooltip') : '');
98 // generate a cookie-safe string of map state
99 function cookieContent(map) {
100 var center = map.getCenter().wrap();
101 return [center.lng, center.lat, map.getZoom(), map.getLayersCode()].join('|');
104 function escapeHTML(string) {
112 return string == null ? '' : (string + '').replace(/[&<>"']/g, function(match) {
113 return htmlEscapes[match];
117 function maximiseMap() {
118 $("#content").addClass("maximised");
121 function minimiseMap() {
122 $("#content").removeClass("maximised");
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);