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
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 remoteEditHandler(bbox, select) {
33 left: bbox.getWest() - 0.0001,
34 top: bbox.getNorth() + 0.0001,
35 right: bbox.getEast() + 0.0001,
36 bottom: bbox.getSouth() - 0.0001
39 if (select) query.select = select;
41 var iframe = $('<iframe>')
44 .attr("src", "http://127.0.0.1:8111/load_and_zoom?" + querystring.stringify(query))
45 .on('load', function() {
50 setTimeout(function () {
52 alert(I18n.t('site.index.remote_failed'));
61 * Called as the user scrolls/zooms around to maniplate hrefs of the
62 * view tab and various other links
64 function updatelinks(loc, zoom, layers, object) {
65 $(".geolink").each(function(index, link) {
66 var href = link.href.split(/[?#]/)[0],
67 args = querystring.parse(link.search.substring(1));
69 if (object && $(link).hasClass("object")) args[object.type] = object.id;
71 var query = querystring.stringify(args);
72 if (query) href += '?' + query;
76 lon: loc.lon || loc.lng,
80 if (layers && $(link).hasClass("layers")) {
84 href += OSM.formatHash(args);
89 var editDisabled = zoom < 13;
91 .tooltip({placement: 'bottom'})
93 .on('click.minzoom', function() { return !editDisabled; })
94 .toggleClass('disabled', editDisabled)
95 .attr('data-original-title', editDisabled ?
96 I18n.t('javascripts.site.edit_disabled_tooltip') : '');
99 // generate a cookie-safe string of map state
100 function cookieContent(map) {
101 var center = map.getCenter().wrap();
102 return [center.lng, center.lat, map.getZoom(), map.getLayersCode()].join('|');
105 function escapeHTML(string) {
113 return string == null ? '' : (string + '').replace(/[&<>"']/g, function(match) {
114 return htmlEscapes[match];
118 function maximiseMap() {
119 $("#content").addClass("maximised");
122 function minimiseMap() {
123 $("#content").removeClass("maximised");
127 * Forms which have been cached by rails may have the wrong
128 * authenticity token, so patch up any forms with the correct
129 * token taken from the page header.
131 $(document).ready(function () {
132 var auth_token = $("meta[name=csrf-token]").attr("content");
133 $("form input[name=authenticity_token]").val(auth_token);