3 //= require jquery.timers
4 //= require jquery.cookie
5 //= require jquery.throttle-debounce
9 //= require leaflet.osm
10 //= require leaflet.hash
11 //= require leaflet.zoom
12 //= require leaflet.extend
13 //= require leaflet.locationfilter
14 //= 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 normalBounds(bounds) {
31 if (bounds instanceof L.LatLngBounds) return bounds;
32 return new L.LatLngBounds(
33 new L.LatLng(bounds[0][0], bounds[0][1]),
34 new L.LatLng(bounds[1][0], bounds[1][1]));
37 function remoteEditHandler(bbox, select) {
40 left: bbox.getWest() - 0.0001,
41 top: bbox.getNorth() + 0.0001,
42 right: bbox.getEast() + 0.0001,
43 bottom: bbox.getSouth() - 0.0001
46 if (select) query.select = select;
48 var iframe = $('<iframe>')
51 .attr("src", "http://127.0.0.1:8111/load_and_zoom?" + querystring.stringify(query))
52 .on('load', function() {
57 setTimeout(function () {
59 alert(I18n.t('site.index.remote_failed'));
68 * Called as the user scrolls/zooms around to maniplate hrefs of the
69 * view tab and various other links
71 function updatelinks(loc, zoom, layers, bounds, object) {
72 $(".geolink").each(function(index, link) {
73 var href = link.href.split(/[?#]/)[0],
74 args = querystring.parse(link.search.substring(1));
76 if (bounds && $(link).hasClass("bbox")) args.bbox = normalBounds(bounds).toBBoxString();
77 if (object && $(link).hasClass("object")) args[object.type] = object.id;
79 var query = querystring.stringify(args);
80 if (query) href += '?' + query;
82 if ($(link).hasClass("llz")) {
85 lon: loc.lon || loc.lng,
89 if (layers && $(link).hasClass("layers")) {
93 href += OSM.formatHash(args);
98 var minzoom = $(link).data("minzoom");
100 var name = link.id.replace(/anchor$/, "");
101 $(link).off("click.minzoom");
102 if (zoom >= minzoom) {
104 .attr("title", I18n.t("javascripts.site." + name + "_tooltip"))
105 .removeClass("disabled");
108 .attr("title", I18n.t("javascripts.site." + name + "_disabled_tooltip"))
109 .addClass("disabled")
110 .on("click.minzoom", function () {
111 alert(I18n.t("javascripts.site." + name + "_zoom_alert"));
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);