1 //= depend_on settings.yml
2 //= depend_on settings.local.yml
3 //= depend_on layers.yml
8 <% if defined?(Settings.matomo) %>
9 MATOMO: <%= Settings.matomo.to_json %>,
12 MAX_REQUEST_AREA: <%= Settings.max_request_area.to_json %>,
13 SERVER_PROTOCOL: <%= Settings.server_protocol.to_json %>,
14 SERVER_URL: <%= Settings.server_url.to_json %>,
15 API_VERSION: <%= Settings.api_version.to_json %>,
16 STATUS: <%= Settings.status.to_json %>,
17 MAX_NOTE_REQUEST_AREA: <%= Settings.max_note_request_area.to_json %>,
18 OVERPASS_URL: <%= Settings.overpass_url.to_json %>,
19 OVERPASS_CREDENTIALS: <%= Settings.overpass_credentials.to_json %>,
20 NOMINATIM_URL: <%= Settings.nominatim_url.to_json %>,
21 GRAPHHOPPER_URL: <%= Settings.graphhopper_url.to_json %>,
22 FOSSGIS_OSRM_URL: <%= Settings.fossgis_osrm_url.to_json %>,
23 FOSSGIS_VALHALLA_URL: <%= Settings.fossgis_valhalla_url.to_json %>,
24 DEFAULT_LOCALE: <%= I18n.default_locale.to_json %>,
26 <% if Settings.key?(:thunderforest_key) %>
27 THUNDERFOREST_KEY: <%= Settings.thunderforest_key.to_json %>,
30 <% if Settings.key?(:tracestrack_key) %>
31 TRACESTRACK_KEY: <%= Settings.tracestrack_key.to_json %>,
34 LAYER_DEFINITIONS: <%= YAML.load_file(Rails.root.join("config/layers.yml")).to_json %>,
35 LAYERS_WITH_MAP_KEY: <%= YAML.load_file(Rails.root.join("config/key.yml")).keys.to_json %>,
37 MARKER_GREEN: <%= image_path("marker-green.png").to_json %>,
38 MARKER_RED: <%= image_path("marker-red.png").to_json %>,
40 MARKER_ICON: <%= image_path("leaflet/dist/images/marker-icon.png").to_json %>,
41 MARKER_ICON_2X: <%= image_path("leaflet/dist/images/marker-icon-2x.png").to_json %>,
42 MARKER_SHADOW: <%= image_path("leaflet/dist/images/marker-shadow.png").to_json %>,
44 NEW_NOTE_MARKER: <%= image_path("new_note_marker.svg").to_json %>,
45 OPEN_NOTE_MARKER: <%= image_path("open_note_marker.svg").to_json %>,
46 CLOSED_NOTE_MARKER: <%= image_path("closed_note_marker.svg").to_json %>,
48 apiUrl: function (object) {
49 var apiType = object.type === "note" ? "notes" : object.type;
50 var url = "/api/" + OSM.API_VERSION + "/" + apiType + "/" + object.id;
52 if (object.type === "way" || object.type === "relation") {
54 } else if (object.version) {
55 url += "/" + object.version;
61 params: function(search) {
64 search = (search || window.location.search).replace('?', '').split(/&|;/);
66 for (var i = 0; i < search.length; ++i) {
68 j = pair.indexOf('='),
69 key = pair.slice(0, j),
70 val = pair.slice(++j);
73 params[key] = decodeURIComponent(val);
75 // Ignore parse exceptions
82 mapParams: function (search) {
83 var params = OSM.params(search), mapParams = {}, match;
85 if (params.mlon && params.mlat) {
86 mapParams.marker = true;
87 mapParams.mlon = parseFloat(params.mlon);
88 mapParams.mlat = parseFloat(params.mlat);
91 // Old-style object parameters; still in use for edit links e.g. /edit?way=1234
93 mapParams.object = {type: 'node', id: parseInt(params.node)};
94 } else if (params.way) {
95 mapParams.object = {type: 'way', id: parseInt(params.way)};
96 } else if (params.relation) {
97 mapParams.object = {type: 'relation', id: parseInt(params.relation)};
98 } else if (params.note) {
99 mapParams.object = {type: 'note', id: parseInt(params.note)};
102 var hash = OSM.parseHash(location.hash);
104 const loc = Cookies.get('_osm_location')?.split("|");
106 // Decide on a map starting position. Various ways of doing this.
108 mapParams.lon = hash.center.lng;
109 mapParams.lat = hash.center.lat;
110 mapParams.zoom = hash.zoom;
111 } else if (params.bbox) {
112 var bbox = params.bbox.split(',');
113 mapParams.bounds = L.latLngBounds(
114 [parseFloat(bbox[1]), parseFloat(bbox[0])],
115 [parseFloat(bbox[3]), parseFloat(bbox[2])]);
116 } else if (params.minlon && params.minlat && params.maxlon && params.maxlat) {
117 mapParams.bounds = L.latLngBounds(
118 [parseFloat(params.minlat), parseFloat(params.minlon)],
119 [parseFloat(params.maxlat), parseFloat(params.maxlon)]);
120 } else if (params.mlon && params.mlat) {
121 mapParams.lon = parseFloat(params.mlon);
122 mapParams.lat = parseFloat(params.mlat);
123 mapParams.zoom = parseInt(params.zoom || 12);
125 mapParams.lon = parseFloat(loc[0]);
126 mapParams.lat = parseFloat(loc[1]);
127 mapParams.zoom = parseInt(loc[2]);
128 } else if (OSM.home) {
129 mapParams.lon = OSM.home.lon;
130 mapParams.lat = OSM.home.lat;
132 } else if (OSM.location) {
133 mapParams.bounds = L.latLngBounds(
134 [OSM.location.minlat,
135 OSM.location.minlon],
136 [OSM.location.maxlat,
137 OSM.location.maxlon]);
139 mapParams.lon = -0.1;
140 mapParams.lat = 51.5;
141 mapParams.zoom = parseInt(params.zoom || 5);
144 mapParams.layers = hash.layers || (loc && loc[3]) || '';
146 var scale = parseFloat(params.scale);
148 mapParams.zoom = Math.log(360.0 / (scale * 512.0)) / Math.log(2.0);
154 parseHash: function(hash) {
157 var i = hash.indexOf('#');
162 hash = Qs.parse(hash.slice(i + 1));
164 var map = (hash.map || '').split('/'),
165 zoom = parseInt(map[0], 10),
166 lat = parseFloat(map[1]),
167 lon = parseFloat(map[2]);
169 if (!isNaN(zoom) && !isNaN(lat) && !isNaN(lon)) {
170 args.center = new L.LatLng(lat, lon);
175 args.layers = hash.layers;
181 formatHash: function(args) {
182 var center, zoom, layers;
184 if (args instanceof L.Map) {
185 center = args.getCenter();
186 zoom = args.getZoom();
187 layers = args.getLayersCode();
189 center = args.center || L.latLng(args.lat, args.lon);
191 layers = args.layers || '';
194 center = center.wrap();
195 layers = layers.replace('M', '');
197 var precision = OSM.zoomPrecision(zoom),
198 hash = '#map=' + zoom +
199 '/' + center.lat.toFixed(precision) +
200 '/' + center.lng.toFixed(precision);
203 hash += '&layers=' + layers;
209 zoomPrecision: function(zoom) {
210 var pixels = Math.pow(2, 8 + zoom);
212 return Math.ceil(Math.log10(pixels / degrees));
215 locationCookie: function(map) {
216 var center = map.getCenter().wrap(),
217 zoom = map.getZoom(),
218 precision = OSM.zoomPrecision(zoom);
219 return [center.lng.toFixed(precision), center.lat.toFixed(precision), zoom, map.getLayersCode()].join('|');
222 distance: function(latlng1, latlng2) {
223 var lat1 = latlng1.lat * Math.PI / 180,
224 lng1 = latlng1.lng * Math.PI / 180,
225 lat2 = latlng2.lat * Math.PI / 180,
226 lng2 = latlng2.lng * Math.PI / 180,
227 latdiff = lat2 - lat1,
228 lngdiff = lng2 - lng1;
230 return 6372795 * 2 * Math.asin(
232 Math.pow(Math.sin(latdiff / 2), 2) +
233 Math.cos(lat1) * Math.cos(lat2) * Math.pow(Math.sin(lngdiff / 2), 2)