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 OVERPASS_CREDENTIALS: <%= Settings.overpass_credentials.to_json %>,
18 NOMINATIM_URL: <%= Settings.nominatim_url.to_json %>,
19 GRAPHHOPPER_URL: <%= Settings.graphhopper_url.to_json %>,
20 FOSSGIS_OSRM_URL: <%= Settings.fossgis_osrm_url.to_json %>,
21 DEFAULT_LOCALE: <%= I18n.default_locale.to_json %>,
23 <% if Settings.key?(:thunderforest_key) %>
24 THUNDERFOREST_KEY: <%= Settings.thunderforest_key.to_json %>,
27 MARKER_GREEN: <%= image_path("marker-green.png").to_json %>,
28 MARKER_RED: <%= image_path("marker-red.png").to_json %>,
30 MARKER_ICON: <%= image_path("leaflet/dist/images/marker-icon.png").to_json %>,
31 MARKER_ICON_2X: <%= image_path("leaflet/dist/images/marker-icon-2x.png").to_json %>,
32 MARKER_SHADOW: <%= image_path("leaflet/dist/images/marker-shadow.png").to_json %>,
34 NEW_NOTE_MARKER: <%= image_path("new_note_marker.png").to_json %>,
35 OPEN_NOTE_MARKER: <%= image_path("open_note_marker.png").to_json %>,
36 CLOSED_NOTE_MARKER: <%= image_path("closed_note_marker.png").to_json %>,
38 apiUrl: function (object) {
39 var apiType = object.type === "note" ? "notes" : object.type;
40 var url = "/api/" + OSM.API_VERSION + "/" + apiType + "/" + 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)};
88 } else if (params.note) {
89 mapParams.object = {type: 'note', id: parseInt(params.note)};
92 var hash = OSM.parseHash(location.hash);
94 // Decide on a map starting position. Various ways of doing this.
96 mapParams.lon = hash.center.lng;
97 mapParams.lat = hash.center.lat;
98 mapParams.zoom = hash.zoom;
99 } else if (params.bbox) {
100 var bbox = params.bbox.split(',');
101 mapParams.bounds = L.latLngBounds(
102 [parseFloat(bbox[1]), parseFloat(bbox[0])],
103 [parseFloat(bbox[3]), parseFloat(bbox[2])]);
104 } else if (params.minlon && params.minlat && params.maxlon && params.maxlat) {
105 mapParams.bounds = L.latLngBounds(
106 [parseFloat(params.minlat), parseFloat(params.minlon)],
107 [parseFloat(params.maxlat), parseFloat(params.maxlon)]);
108 } else if (params.mlon && params.mlat) {
109 mapParams.lon = parseFloat(params.mlon);
110 mapParams.lat = parseFloat(params.mlat);
111 mapParams.zoom = parseInt(params.zoom || 12);
112 } else if (loc = Cookies.get('_osm_location')) {
113 loc = loc.split("|");
114 mapParams.lon = parseFloat(loc[0]);
115 mapParams.lat = parseFloat(loc[1]);
116 mapParams.zoom = parseInt(loc[2]);
117 } else if (OSM.home) {
118 mapParams.lon = OSM.home.lon;
119 mapParams.lat = OSM.home.lat;
121 } else if (OSM.location) {
122 mapParams.bounds = L.latLngBounds(
123 [OSM.location.minlat,
124 OSM.location.minlon],
125 [OSM.location.maxlat,
126 OSM.location.maxlon]);
128 mapParams.lon = -0.1;
129 mapParams.lat = 51.5;
130 mapParams.zoom = parseInt(params.zoom || 5);
133 mapParams.layers = hash.layers || (loc && loc[3]) || '';
135 var scale = parseFloat(params.scale);
137 mapParams.zoom = Math.log(360.0 / (scale * 512.0)) / Math.log(2.0);
143 parseHash: function(hash) {
146 var i = hash.indexOf('#');
151 hash = Qs.parse(hash.slice(i + 1));
153 var map = (hash.map || '').split('/'),
154 zoom = parseInt(map[0], 10),
155 lat = parseFloat(map[1]),
156 lon = parseFloat(map[2]);
158 if (!isNaN(zoom) && !isNaN(lat) && !isNaN(lon)) {
159 args.center = new L.LatLng(lat, lon);
164 args.layers = hash.layers;
170 formatHash: function(args) {
171 var center, zoom, layers;
173 if (args instanceof L.Map) {
174 center = args.getCenter();
175 zoom = args.getZoom();
176 layers = args.getLayersCode();
178 center = args.center || L.latLng(args.lat, args.lon);
180 layers = args.layers || '';
183 center = center.wrap();
184 layers = layers.replace('M', '');
186 var precision = OSM.zoomPrecision(zoom),
187 hash = '#map=' + zoom +
188 '/' + center.lat.toFixed(precision) +
189 '/' + center.lng.toFixed(precision);
192 hash += '&layers=' + layers;
198 zoomPrecision: function(zoom) {
199 return Math.max(0, Math.ceil(Math.log(zoom) / Math.LN2));
202 locationCookie: function(map) {
203 var center = map.getCenter().wrap(),
204 zoom = map.getZoom(),
205 precision = OSM.zoomPrecision(zoom);
206 return [center.lng.toFixed(precision), center.lat.toFixed(precision), zoom, map.getLayersCode()].join('|');
209 distance: function(latlng1, latlng2) {
210 var lat1 = latlng1.lat * Math.PI / 180,
211 lng1 = latlng1.lng * Math.PI / 180,
212 lat2 = latlng2.lat * Math.PI / 180,
213 lng2 = latlng2.lng * Math.PI / 180,
214 latdiff = lat2 - lat1,
215 lngdiff = lng2 - lng1;
217 return 6372795 * 2 * Math.asin(
219 Math.pow(Math.sin(latdiff / 2), 2) +
220 Math.cos(lat1) * Math.cos(lat2) * Math.pow(Math.sin(lngdiff / 2), 2)