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 SEARCHING: <%= image_path("searching.gif").to_json %>,
40 apiUrl: function (object) {
41 var apiType = object.type === "note" ? "notes" : object.type;
42 var url = "/api/" + OSM.API_VERSION + "/" + apiType + "/" + object.id;
44 if (object.type === "way" || object.type === "relation") {
46 } else if (object.version) {
47 url += "/" + object.version;
53 params: function(search) {
56 search = (search || window.location.search).replace('?', '').split(/&|;/);
58 for (var i = 0; i < search.length; ++i) {
60 j = pair.indexOf('='),
61 key = pair.slice(0, j),
62 val = pair.slice(++j);
65 params[key] = decodeURIComponent(val);
67 // Ignore parse exceptions
74 mapParams: function (search) {
75 var params = OSM.params(search), mapParams = {}, loc, match;
77 if (params.mlon && params.mlat) {
78 mapParams.marker = true;
79 mapParams.mlon = parseFloat(params.mlon);
80 mapParams.mlat = parseFloat(params.mlat);
83 // Old-style object parameters; still in use for edit links e.g. /edit?way=1234
85 mapParams.object = {type: 'node', id: parseInt(params.node)};
86 } else if (params.way) {
87 mapParams.object = {type: 'way', id: parseInt(params.way)};
88 } else if (params.relation) {
89 mapParams.object = {type: 'relation', id: parseInt(params.relation)};
90 } else if (params.note) {
91 mapParams.object = {type: 'note', id: parseInt(params.note)};
94 var hash = OSM.parseHash(location.hash);
96 // Decide on a map starting position. Various ways of doing this.
98 mapParams.lon = hash.center.lng;
99 mapParams.lat = hash.center.lat;
100 mapParams.zoom = hash.zoom;
101 } else if (params.bbox) {
102 var bbox = params.bbox.split(',');
103 mapParams.bounds = L.latLngBounds(
104 [parseFloat(bbox[1]), parseFloat(bbox[0])],
105 [parseFloat(bbox[3]), parseFloat(bbox[2])]);
106 } else if (params.minlon && params.minlat && params.maxlon && params.maxlat) {
107 mapParams.bounds = L.latLngBounds(
108 [parseFloat(params.minlat), parseFloat(params.minlon)],
109 [parseFloat(params.maxlat), parseFloat(params.maxlon)]);
110 } else if (params.mlon && params.mlat) {
111 mapParams.lon = parseFloat(params.mlon);
112 mapParams.lat = parseFloat(params.mlat);
113 mapParams.zoom = parseInt(params.zoom || 12);
114 } else if (loc = Cookies.get('_osm_location')) {
115 loc = loc.split("|");
116 mapParams.lon = parseFloat(loc[0]);
117 mapParams.lat = parseFloat(loc[1]);
118 mapParams.zoom = parseInt(loc[2]);
119 } else if (OSM.home) {
120 mapParams.lon = OSM.home.lon;
121 mapParams.lat = OSM.home.lat;
123 } else if (OSM.location) {
124 mapParams.bounds = L.latLngBounds(
125 [OSM.location.minlat,
126 OSM.location.minlon],
127 [OSM.location.maxlat,
128 OSM.location.maxlon]);
130 mapParams.lon = -0.1;
131 mapParams.lat = 51.5;
132 mapParams.zoom = parseInt(params.zoom || 5);
135 mapParams.layers = hash.layers || (loc && loc[3]) || '';
137 var scale = parseFloat(params.scale);
139 mapParams.zoom = Math.log(360.0 / (scale * 512.0)) / Math.log(2.0);
145 parseHash: function(hash) {
148 var i = hash.indexOf('#');
153 hash = Qs.parse(hash.slice(i + 1));
155 var map = (hash.map || '').split('/'),
156 zoom = parseInt(map[0], 10),
157 lat = parseFloat(map[1]),
158 lon = parseFloat(map[2]);
160 if (!isNaN(zoom) && !isNaN(lat) && !isNaN(lon)) {
161 args.center = new L.LatLng(lat, lon);
166 args.layers = hash.layers;
172 formatHash: function(args) {
173 var center, zoom, layers;
175 if (args instanceof L.Map) {
176 center = args.getCenter();
177 zoom = args.getZoom();
178 layers = args.getLayersCode();
180 center = args.center || L.latLng(args.lat, args.lon);
182 layers = args.layers || '';
185 center = center.wrap();
186 layers = layers.replace('M', '');
188 var precision = OSM.zoomPrecision(zoom),
189 hash = '#map=' + zoom +
190 '/' + center.lat.toFixed(precision) +
191 '/' + center.lng.toFixed(precision);
194 hash += '&layers=' + layers;
200 zoomPrecision: function(zoom) {
201 return Math.max(0, Math.ceil(Math.log(zoom) / Math.LN2));
204 locationCookie: function(map) {
205 var center = map.getCenter().wrap(),
206 zoom = map.getZoom(),
207 precision = OSM.zoomPrecision(zoom);
208 return [center.lng.toFixed(precision), center.lat.toFixed(precision), zoom, map.getLayersCode()].join('|');
211 distance: function(latlng1, latlng2) {
212 var lat1 = latlng1.lat * Math.PI / 180,
213 lng1 = latlng1.lng * Math.PI / 180,
214 lat2 = latlng2.lat * Math.PI / 180,
215 lng2 = latlng2.lng * Math.PI / 180,
216 latdiff = lat2 - lat1,
217 lngdiff = lng2 - lng1;
219 return 6372795 * 2 * Math.asin(
221 Math.pow(Math.sin(latdiff / 2), 2) +
222 Math.cos(lat1) * Math.cos(lat2) * Math.pow(Math.sin(lngdiff / 2), 2)