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 apiType = object.type === "note" ? "notes" : object.type;
41 var url = "/api/" + OSM.API_VERSION + "/" + apiType + "/" + object.id;
43 if (object.type === "way" || object.type === "relation") {
45 } else if (object.version) {
46 url += "/" + object.version;
52 params: function(search) {
55 search = (search || window.location.search).replace('?', '').split(/&|;/);
57 for (var i = 0; i < search.length; ++i) {
59 j = pair.indexOf('='),
60 key = pair.slice(0, j),
61 val = pair.slice(++j);
64 params[key] = decodeURIComponent(val);
66 // Ignore parse exceptions
73 mapParams: function (search) {
74 var params = OSM.params(search), mapParams = {}, loc, match;
76 if (params.mlon && params.mlat) {
77 mapParams.marker = true;
78 mapParams.mlon = parseFloat(params.mlon);
79 mapParams.mlat = parseFloat(params.mlat);
82 // Old-style object parameters; still in use for edit links e.g. /edit?way=1234
84 mapParams.object = {type: 'node', id: parseInt(params.node)};
85 } else if (params.way) {
86 mapParams.object = {type: 'way', id: parseInt(params.way)};
87 } else if (params.relation) {
88 mapParams.object = {type: 'relation', id: parseInt(params.relation)};
89 } else if (params.note) {
90 mapParams.object = {type: 'note', id: parseInt(params.note)};
93 var hash = OSM.parseHash(location.hash);
95 // Decide on a map starting position. Various ways of doing this.
97 mapParams.lon = hash.center.lng;
98 mapParams.lat = hash.center.lat;
99 mapParams.zoom = hash.zoom;
100 } else if (params.bbox) {
101 var bbox = params.bbox.split(',');
102 mapParams.bounds = L.latLngBounds(
103 [parseFloat(bbox[1]), parseFloat(bbox[0])],
104 [parseFloat(bbox[3]), parseFloat(bbox[2])]);
105 } else if (params.minlon && params.minlat && params.maxlon && params.maxlat) {
106 mapParams.bounds = L.latLngBounds(
107 [parseFloat(params.minlat), parseFloat(params.minlon)],
108 [parseFloat(params.maxlat), parseFloat(params.maxlon)]);
109 } else if (params.mlon && params.mlat) {
110 mapParams.lon = parseFloat(params.mlon);
111 mapParams.lat = parseFloat(params.mlat);
112 mapParams.zoom = parseInt(params.zoom || 12);
113 } else if (loc = Cookies.get('_osm_location')) {
114 loc = loc.split("|");
115 mapParams.lon = parseFloat(loc[0]);
116 mapParams.lat = parseFloat(loc[1]);
117 mapParams.zoom = parseInt(loc[2]);
118 } else if (OSM.home) {
119 mapParams.lon = OSM.home.lon;
120 mapParams.lat = OSM.home.lat;
122 } else if (OSM.location) {
123 mapParams.bounds = L.latLngBounds(
124 [OSM.location.minlat,
125 OSM.location.minlon],
126 [OSM.location.maxlat,
127 OSM.location.maxlon]);
129 mapParams.lon = -0.1;
130 mapParams.lat = 51.5;
131 mapParams.zoom = parseInt(params.zoom || 5);
134 mapParams.layers = hash.layers || (loc && loc[3]) || '';
136 var scale = parseFloat(params.scale);
138 mapParams.zoom = Math.log(360.0 / (scale * 512.0)) / Math.log(2.0);
144 parseHash: function(hash) {
147 var i = hash.indexOf('#');
152 hash = Qs.parse(hash.slice(i + 1));
154 var map = (hash.map || '').split('/'),
155 zoom = parseInt(map[0], 10),
156 lat = parseFloat(map[1]),
157 lon = parseFloat(map[2]);
159 if (!isNaN(zoom) && !isNaN(lat) && !isNaN(lon)) {
160 args.center = new L.LatLng(lat, lon);
165 args.layers = hash.layers;
171 formatHash: function(args) {
172 var center, zoom, layers;
174 if (args instanceof L.Map) {
175 center = args.getCenter();
176 zoom = args.getZoom();
177 layers = args.getLayersCode();
179 center = args.center || L.latLng(args.lat, args.lon);
181 layers = args.layers || '';
184 center = center.wrap();
185 layers = layers.replace('M', '');
187 var precision = OSM.zoomPrecision(zoom),
188 hash = '#map=' + zoom +
189 '/' + center.lat.toFixed(precision) +
190 '/' + center.lng.toFixed(precision);
193 hash += '&layers=' + layers;
199 zoomPrecision: function(zoom) {
200 return Math.max(0, Math.ceil(Math.log(zoom) / Math.LN2));
203 locationCookie: function(map) {
204 var center = map.getCenter().wrap(),
205 zoom = map.getZoom(),
206 precision = OSM.zoomPrecision(zoom);
207 return [center.lng.toFixed(precision), center.lat.toFixed(precision), zoom, map.getLayersCode()].join('|');
210 distance: function(latlng1, latlng2) {
211 var lat1 = latlng1.lat * Math.PI / 180,
212 lng1 = latlng1.lng * Math.PI / 180,
213 lat2 = latlng2.lat * Math.PI / 180,
214 lng2 = latlng2.lng * Math.PI / 180,
215 latdiff = lat2 - lat1,
216 lngdiff = lng2 - lng1;
218 return 6372795 * 2 * Math.asin(
220 Math.pow(Math.sin(latdiff / 2), 2) +
221 Math.cos(lat1) * Math.cos(lat2) * Math.pow(Math.sin(lngdiff / 2), 2)