1 //= depend_on settings.yml
2 //= depend_on settings.local.yml
6 <% if defined?(Settings.matomo) %>
7 MATOMO: <%= Settings.matomo.to_json %>,
10 MAX_REQUEST_AREA: <%= Settings.max_request_area.to_json %>,
11 SERVER_PROTOCOL: <%= Settings.server_protocol.to_json %>,
12 SERVER_URL: <%= Settings.server_url.to_json %>,
13 API_VERSION: <%= Settings.api_version.to_json %>,
14 STATUS: <%= Settings.status.to_json %>,
15 MAX_NOTE_REQUEST_AREA: <%= Settings.max_note_request_area.to_json %>,
16 OVERPASS_URL: <%= Settings.overpass_url.to_json %>,
17 NOMINATIM_URL: <%= Settings.nominatim_url.to_json %>,
18 GRAPHHOPPER_URL: <%= Settings.graphhopper_url.to_json %>,
19 FOSSGIS_OSRM_URL: <%= Settings.fossgis_osrm_url.to_json %>,
20 DEFAULT_LOCALE: <%= I18n.default_locale.to_json %>,
22 <% if Settings.key?(:thunderforest_key) %>
23 THUNDERFOREST_KEY: <%= Settings.thunderforest_key.to_json %>,
26 MARKER_GREEN: <%= image_path("marker-green.png").to_json %>,
27 MARKER_RED: <%= image_path("marker-red.png").to_json %>,
29 MARKER_ICON: <%= image_path("leaflet/dist/images/marker-icon.png").to_json %>,
30 MARKER_ICON_2X: <%= image_path("leaflet/dist/images/marker-icon-2x.png").to_json %>,
31 MARKER_SHADOW: <%= image_path("leaflet/dist/images/marker-shadow.png").to_json %>,
33 NEW_NOTE_MARKER: <%= image_path("new_note_marker.png").to_json %>,
34 OPEN_NOTE_MARKER: <%= image_path("open_note_marker.png").to_json %>,
35 CLOSED_NOTE_MARKER: <%= image_path("closed_note_marker.png").to_json %>,
37 SEARCHING: <%= image_path("searching.gif").to_json %>,
39 apiUrl: function (object) {
40 var url = "/api/" + OSM.API_VERSION + "/" + object.type + "/" + object.id;
42 if (object.type === "way" || object.type === "relation") {
44 } else if (object.version) {
45 url += "/" + object.version;
51 params: function(search) {
54 search = (search || window.location.search).replace('?', '').split(/&|;/);
56 for (var i = 0; i < search.length; ++i) {
58 j = pair.indexOf('='),
59 key = pair.slice(0, j),
60 val = pair.slice(++j);
63 params[key] = decodeURIComponent(val);
65 // Ignore parse exceptions
72 mapParams: function (search) {
73 var params = OSM.params(search), mapParams = {}, loc, match;
75 if (params.mlon && params.mlat) {
76 mapParams.marker = true;
77 mapParams.mlon = parseFloat(params.mlon);
78 mapParams.mlat = parseFloat(params.mlat);
81 // Old-style object parameters; still in use for edit links e.g. /edit?way=1234
83 mapParams.object = {type: 'node', id: parseInt(params.node)};
84 } else if (params.way) {
85 mapParams.object = {type: 'way', id: parseInt(params.way)};
86 } else if (params.relation) {
87 mapParams.object = {type: 'relation', id: parseInt(params.relation)};
90 var hash = OSM.parseHash(location.hash);
92 // Decide on a map starting position. Various ways of doing this.
94 mapParams.lon = hash.center.lng;
95 mapParams.lat = hash.center.lat;
96 mapParams.zoom = hash.zoom;
97 } else if (params.bbox) {
98 var bbox = params.bbox.split(',');
99 mapParams.bounds = L.latLngBounds(
100 [parseFloat(bbox[1]), parseFloat(bbox[0])],
101 [parseFloat(bbox[3]), parseFloat(bbox[2])]);
102 } else if (params.minlon && params.minlat && params.maxlon && params.maxlat) {
103 mapParams.bounds = L.latLngBounds(
104 [parseFloat(params.minlat), parseFloat(params.minlon)],
105 [parseFloat(params.maxlat), parseFloat(params.maxlon)]);
106 } else if (params.mlon && params.mlat) {
107 mapParams.lon = parseFloat(params.mlon);
108 mapParams.lat = parseFloat(params.mlat);
109 mapParams.zoom = parseInt(params.zoom || 12);
110 } else if (loc = Cookies.get('_osm_location')) {
111 loc = loc.split("|");
112 mapParams.lon = parseFloat(loc[0]);
113 mapParams.lat = parseFloat(loc[1]);
114 mapParams.zoom = parseInt(loc[2]);
115 } else if (OSM.home) {
116 mapParams.lon = OSM.home.lon;
117 mapParams.lat = OSM.home.lat;
119 } else if (OSM.location) {
120 mapParams.bounds = L.latLngBounds(
121 [OSM.location.minlat,
122 OSM.location.minlon],
123 [OSM.location.maxlat,
124 OSM.location.maxlon]);
126 mapParams.lon = -0.1;
127 mapParams.lat = 51.5;
128 mapParams.zoom = parseInt(params.zoom || 5);
131 mapParams.layers = hash.layers || (loc && loc[3]) || '';
133 var scale = parseFloat(params.scale);
135 mapParams.zoom = Math.log(360.0 / (scale * 512.0)) / Math.log(2.0);
141 parseHash: function(hash) {
144 var i = hash.indexOf('#');
149 hash = Qs.parse(hash.slice(i + 1));
151 var map = (hash.map || '').split('/'),
152 zoom = parseInt(map[0], 10),
153 lat = parseFloat(map[1]),
154 lon = parseFloat(map[2]);
156 if (!isNaN(zoom) && !isNaN(lat) && !isNaN(lon)) {
157 args.center = new L.LatLng(lat, lon);
162 args.layers = hash.layers;
168 formatHash: function(args) {
169 var center, zoom, layers;
171 if (args instanceof L.Map) {
172 center = args.getCenter();
173 zoom = args.getZoom();
174 layers = args.getLayersCode();
176 center = args.center || L.latLng(args.lat, args.lon);
178 layers = args.layers || '';
181 center = center.wrap();
182 layers = layers.replace('M', '');
184 var precision = OSM.zoomPrecision(zoom),
185 hash = '#map=' + zoom +
186 '/' + center.lat.toFixed(precision) +
187 '/' + center.lng.toFixed(precision);
190 hash += '&layers=' + layers;
196 zoomPrecision: function(zoom) {
197 return Math.max(0, Math.ceil(Math.log(zoom) / Math.LN2));
200 locationCookie: function(map) {
201 var center = map.getCenter().wrap(),
202 zoom = map.getZoom(),
203 precision = OSM.zoomPrecision(zoom);
204 return [center.lng.toFixed(precision), center.lat.toFixed(precision), zoom, map.getLayersCode()].join('|');
207 distance: function(latlng1, latlng2) {
208 var lat1 = latlng1.lat * Math.PI / 180,
209 lng1 = latlng1.lng * Math.PI / 180,
210 lat2 = latlng2.lat * Math.PI / 180,
211 lng2 = latlng2.lng * Math.PI / 180,
212 latdiff = lat2 - lat1,
213 lngdiff = lng2 - lng1;
215 return 6372795 * 2 * Math.asin(
217 Math.pow(Math.sin(latdiff / 2), 2) +
218 Math.cos(lat1) * Math.cos(lat2) * Math.pow(Math.sin(lngdiff / 2), 2)