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 FOSSGIS_VALHALLA_URL: <%= Settings.fossgis_valhalla_url.to_json %>,
22 DEFAULT_LOCALE: <%= I18n.default_locale.to_json %>,
24 <% if Settings.key?(:thunderforest_key) %>
25 THUNDERFOREST_KEY: <%= Settings.thunderforest_key.to_json %>,
28 <% if Settings.key?(:tracestrack_key) %>
29 TRACESTRACK_KEY: <%= Settings.tracestrack_key.to_json %>,
32 MARKER_GREEN: <%= image_path("marker-green.png").to_json %>,
33 MARKER_RED: <%= image_path("marker-red.png").to_json %>,
35 MARKER_ICON: <%= image_path("leaflet/dist/images/marker-icon.png").to_json %>,
36 MARKER_ICON_2X: <%= image_path("leaflet/dist/images/marker-icon-2x.png").to_json %>,
37 MARKER_SHADOW: <%= image_path("leaflet/dist/images/marker-shadow.png").to_json %>,
39 NEW_NOTE_MARKER: <%= image_path("new_note_marker.png").to_json %>,
40 OPEN_NOTE_MARKER: <%= image_path("open_note_marker.png").to_json %>,
41 CLOSED_NOTE_MARKER: <%= image_path("closed_note_marker.png").to_json %>,
43 apiUrl: function (object) {
44 var apiType = object.type === "note" ? "notes" : object.type;
45 var url = "/api/" + OSM.API_VERSION + "/" + apiType + "/" + object.id;
47 if (object.type === "way" || object.type === "relation") {
49 } else if (object.version) {
50 url += "/" + object.version;
56 params: function(search) {
59 search = (search || window.location.search).replace('?', '').split(/&|;/);
61 for (var i = 0; i < search.length; ++i) {
63 j = pair.indexOf('='),
64 key = pair.slice(0, j),
65 val = pair.slice(++j);
68 params[key] = decodeURIComponent(val);
70 // Ignore parse exceptions
77 mapParams: function (search) {
78 var params = OSM.params(search), mapParams = {}, loc, match;
80 if (params.mlon && params.mlat) {
81 mapParams.marker = true;
82 mapParams.mlon = parseFloat(params.mlon);
83 mapParams.mlat = parseFloat(params.mlat);
86 // Old-style object parameters; still in use for edit links e.g. /edit?way=1234
88 mapParams.object = {type: 'node', id: parseInt(params.node)};
89 } else if (params.way) {
90 mapParams.object = {type: 'way', id: parseInt(params.way)};
91 } else if (params.relation) {
92 mapParams.object = {type: 'relation', id: parseInt(params.relation)};
93 } else if (params.note) {
94 mapParams.object = {type: 'note', id: parseInt(params.note)};
97 var hash = OSM.parseHash(location.hash);
99 // Decide on a map starting position. Various ways of doing this.
101 mapParams.lon = hash.center.lng;
102 mapParams.lat = hash.center.lat;
103 mapParams.zoom = hash.zoom;
104 } else if (params.bbox) {
105 var bbox = params.bbox.split(',');
106 mapParams.bounds = L.latLngBounds(
107 [parseFloat(bbox[1]), parseFloat(bbox[0])],
108 [parseFloat(bbox[3]), parseFloat(bbox[2])]);
109 } else if (params.minlon && params.minlat && params.maxlon && params.maxlat) {
110 mapParams.bounds = L.latLngBounds(
111 [parseFloat(params.minlat), parseFloat(params.minlon)],
112 [parseFloat(params.maxlat), parseFloat(params.maxlon)]);
113 } else if (params.mlon && params.mlat) {
114 mapParams.lon = parseFloat(params.mlon);
115 mapParams.lat = parseFloat(params.mlat);
116 mapParams.zoom = parseInt(params.zoom || 12);
117 } else if (loc = Cookies.get('_osm_location')) {
118 loc = loc.split("|");
119 mapParams.lon = parseFloat(loc[0]);
120 mapParams.lat = parseFloat(loc[1]);
121 mapParams.zoom = parseInt(loc[2]);
122 } else if (OSM.home) {
123 mapParams.lon = OSM.home.lon;
124 mapParams.lat = OSM.home.lat;
126 } else if (OSM.location) {
127 mapParams.bounds = L.latLngBounds(
128 [OSM.location.minlat,
129 OSM.location.minlon],
130 [OSM.location.maxlat,
131 OSM.location.maxlon]);
133 mapParams.lon = -0.1;
134 mapParams.lat = 51.5;
135 mapParams.zoom = parseInt(params.zoom || 5);
138 mapParams.layers = hash.layers || (loc && loc[3]) || '';
140 var scale = parseFloat(params.scale);
142 mapParams.zoom = Math.log(360.0 / (scale * 512.0)) / Math.log(2.0);
148 parseHash: function(hash) {
151 var i = hash.indexOf('#');
156 hash = Qs.parse(hash.slice(i + 1));
158 var map = (hash.map || '').split('/'),
159 zoom = parseInt(map[0], 10),
160 lat = parseFloat(map[1]),
161 lon = parseFloat(map[2]);
163 if (!isNaN(zoom) && !isNaN(lat) && !isNaN(lon)) {
164 args.center = new L.LatLng(lat, lon);
169 args.layers = hash.layers;
175 formatHash: function(args) {
176 var center, zoom, layers;
178 if (args instanceof L.Map) {
179 center = args.getCenter();
180 zoom = args.getZoom();
181 layers = args.getLayersCode();
183 center = args.center || L.latLng(args.lat, args.lon);
185 layers = args.layers || '';
188 center = center.wrap();
189 layers = layers.replace('M', '');
191 var precision = OSM.zoomPrecision(zoom),
192 hash = '#map=' + zoom +
193 '/' + center.lat.toFixed(precision) +
194 '/' + center.lng.toFixed(precision);
197 hash += '&layers=' + layers;
203 zoomPrecision: function(zoom) {
204 return Math.max(0, Math.ceil(Math.log(zoom) / Math.LN2));
207 locationCookie: function(map) {
208 var center = map.getCenter().wrap(),
209 zoom = map.getZoom(),
210 precision = OSM.zoomPrecision(zoom);
211 return [center.lng.toFixed(precision), center.lat.toFixed(precision), zoom, map.getLayersCode()].join('|');
214 distance: function(latlng1, latlng2) {
215 var lat1 = latlng1.lat * Math.PI / 180,
216 lng1 = latlng1.lng * Math.PI / 180,
217 lat2 = latlng2.lat * Math.PI / 180,
218 lng2 = latlng2.lng * Math.PI / 180,
219 latdiff = lat2 - lat1,
220 lngdiff = lng2 - lng1;
222 return 6372795 * 2 * Math.asin(
224 Math.pow(Math.sin(latdiff / 2), 2) +
225 Math.cos(lat1) * Math.cos(lat2) * Math.pow(Math.sin(lngdiff / 2), 2)