1 //= depend_on settings.yml
2 //= depend_on settings.local.yml
7 <% if defined?(Settings.matomo) %>
8 MATOMO: <%= Settings.matomo.to_json %>,
11 MAX_REQUEST_AREA: <%= Settings.max_request_area.to_json %>,
12 SERVER_PROTOCOL: <%= Settings.server_protocol.to_json %>,
13 SERVER_URL: <%= Settings.server_url.to_json %>,
14 API_VERSION: <%= Settings.api_version.to_json %>,
15 STATUS: <%= Settings.status.to_json %>,
16 MAX_NOTE_REQUEST_AREA: <%= Settings.max_note_request_area.to_json %>,
17 OVERPASS_URL: <%= Settings.overpass_url.to_json %>,
18 OVERPASS_CREDENTIALS: <%= Settings.overpass_credentials.to_json %>,
19 NOMINATIM_URL: <%= Settings.nominatim_url.to_json %>,
20 GRAPHHOPPER_URL: <%= Settings.graphhopper_url.to_json %>,
21 FOSSGIS_OSRM_URL: <%= Settings.fossgis_osrm_url.to_json %>,
22 FOSSGIS_VALHALLA_URL: <%= Settings.fossgis_valhalla_url.to_json %>,
23 DEFAULT_LOCALE: <%= I18n.default_locale.to_json %>,
25 <% if Settings.key?(:thunderforest_key) %>
26 THUNDERFOREST_KEY: <%= Settings.thunderforest_key.to_json %>,
29 <% if Settings.key?(:tracestrack_key) %>
30 TRACESTRACK_KEY: <%= Settings.tracestrack_key.to_json %>,
33 LAYERS_WITH_MAP_KEY: <%= YAML.load_file(Rails.root.join("config/key.yml")).keys.to_json %>,
35 MARKER_GREEN: <%= image_path("marker-green.png").to_json %>,
36 MARKER_RED: <%= image_path("marker-red.png").to_json %>,
38 MARKER_ICON: <%= image_path("leaflet/dist/images/marker-icon.png").to_json %>,
39 MARKER_ICON_2X: <%= image_path("leaflet/dist/images/marker-icon-2x.png").to_json %>,
40 MARKER_SHADOW: <%= image_path("leaflet/dist/images/marker-shadow.png").to_json %>,
42 NEW_NOTE_MARKER: <%= image_path("new_note_marker.svg").to_json %>,
43 OPEN_NOTE_MARKER: <%= image_path("open_note_marker.svg").to_json %>,
44 CLOSED_NOTE_MARKER: <%= image_path("closed_note_marker.svg").to_json %>,
46 apiUrl: function (object) {
47 var apiType = object.type === "note" ? "notes" : object.type;
48 var url = "/api/" + OSM.API_VERSION + "/" + apiType + "/" + object.id;
50 if (object.type === "way" || object.type === "relation") {
52 } else if (object.version) {
53 url += "/" + object.version;
59 params: function(search) {
62 search = (search || window.location.search).replace('?', '').split(/&|;/);
64 for (var i = 0; i < search.length; ++i) {
66 j = pair.indexOf('='),
67 key = pair.slice(0, j),
68 val = pair.slice(++j);
71 params[key] = decodeURIComponent(val);
73 // Ignore parse exceptions
80 mapParams: function (search) {
81 var params = OSM.params(search), mapParams = {}, loc, match;
83 if (params.mlon && params.mlat) {
84 mapParams.marker = true;
85 mapParams.mlon = parseFloat(params.mlon);
86 mapParams.mlat = parseFloat(params.mlat);
89 // Old-style object parameters; still in use for edit links e.g. /edit?way=1234
91 mapParams.object = {type: 'node', id: parseInt(params.node)};
92 } else if (params.way) {
93 mapParams.object = {type: 'way', id: parseInt(params.way)};
94 } else if (params.relation) {
95 mapParams.object = {type: 'relation', id: parseInt(params.relation)};
96 } else if (params.note) {
97 mapParams.object = {type: 'note', id: parseInt(params.note)};
100 var hash = OSM.parseHash(location.hash);
102 // Decide on a map starting position. Various ways of doing this.
104 mapParams.lon = hash.center.lng;
105 mapParams.lat = hash.center.lat;
106 mapParams.zoom = hash.zoom;
107 } else if (params.bbox) {
108 var bbox = params.bbox.split(',');
109 mapParams.bounds = L.latLngBounds(
110 [parseFloat(bbox[1]), parseFloat(bbox[0])],
111 [parseFloat(bbox[3]), parseFloat(bbox[2])]);
112 } else if (params.minlon && params.minlat && params.maxlon && params.maxlat) {
113 mapParams.bounds = L.latLngBounds(
114 [parseFloat(params.minlat), parseFloat(params.minlon)],
115 [parseFloat(params.maxlat), parseFloat(params.maxlon)]);
116 } else if (params.mlon && params.mlat) {
117 mapParams.lon = parseFloat(params.mlon);
118 mapParams.lat = parseFloat(params.mlat);
119 mapParams.zoom = parseInt(params.zoom || 12);
120 } else if (loc = Cookies.get('_osm_location')) {
121 loc = loc.split("|");
122 mapParams.lon = parseFloat(loc[0]);
123 mapParams.lat = parseFloat(loc[1]);
124 mapParams.zoom = parseInt(loc[2]);
125 } else if (OSM.home) {
126 mapParams.lon = OSM.home.lon;
127 mapParams.lat = OSM.home.lat;
129 } else if (OSM.location) {
130 mapParams.bounds = L.latLngBounds(
131 [OSM.location.minlat,
132 OSM.location.minlon],
133 [OSM.location.maxlat,
134 OSM.location.maxlon]);
136 mapParams.lon = -0.1;
137 mapParams.lat = 51.5;
138 mapParams.zoom = parseInt(params.zoom || 5);
141 mapParams.layers = hash.layers || (loc && loc[3]) || '';
143 var scale = parseFloat(params.scale);
145 mapParams.zoom = Math.log(360.0 / (scale * 512.0)) / Math.log(2.0);
151 parseHash: function(hash) {
154 var i = hash.indexOf('#');
159 hash = Qs.parse(hash.slice(i + 1));
161 var map = (hash.map || '').split('/'),
162 zoom = parseInt(map[0], 10),
163 lat = parseFloat(map[1]),
164 lon = parseFloat(map[2]);
166 if (!isNaN(zoom) && !isNaN(lat) && !isNaN(lon)) {
167 args.center = new L.LatLng(lat, lon);
172 args.layers = hash.layers;
178 formatHash: function(args) {
179 var center, zoom, layers;
181 if (args instanceof L.Map) {
182 center = args.getCenter();
183 zoom = args.getZoom();
184 layers = args.getLayersCode();
186 center = args.center || L.latLng(args.lat, args.lon);
188 layers = args.layers || '';
191 center = center.wrap();
192 layers = layers.replace('M', '');
194 var precision = OSM.zoomPrecision(zoom),
195 hash = '#map=' + zoom +
196 '/' + center.lat.toFixed(precision) +
197 '/' + center.lng.toFixed(precision);
200 hash += '&layers=' + layers;
206 zoomPrecision: function(zoom) {
207 return Math.max(0, Math.ceil(Math.log(zoom) / Math.LN2));
210 locationCookie: function(map) {
211 var center = map.getCenter().wrap(),
212 zoom = map.getZoom(),
213 precision = OSM.zoomPrecision(zoom);
214 return [center.lng.toFixed(precision), center.lat.toFixed(precision), zoom, map.getLayersCode()].join('|');
217 distance: function(latlng1, latlng2) {
218 var lat1 = latlng1.lat * Math.PI / 180,
219 lng1 = latlng1.lng * Math.PI / 180,
220 lat2 = latlng2.lat * Math.PI / 180,
221 lng2 = latlng2.lng * Math.PI / 180,
222 latdiff = lat2 - lat1,
223 lngdiff = lng2 - lng1;
225 return 6372795 * 2 * Math.asin(
227 Math.pow(Math.sin(latdiff / 2), 2) +
228 Math.cos(lat1) * Math.cos(lat2) * Math.pow(Math.sin(lngdiff / 2), 2)