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 = {}, loc, 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 // Decide on a map starting position. Various ways of doing this.
106 mapParams.lon = hash.center.lng;
107 mapParams.lat = hash.center.lat;
108 mapParams.zoom = hash.zoom;
109 } else if (params.bbox) {
110 var bbox = params.bbox.split(',');
111 mapParams.bounds = L.latLngBounds(
112 [parseFloat(bbox[1]), parseFloat(bbox[0])],
113 [parseFloat(bbox[3]), parseFloat(bbox[2])]);
114 } else if (params.minlon && params.minlat && params.maxlon && params.maxlat) {
115 mapParams.bounds = L.latLngBounds(
116 [parseFloat(params.minlat), parseFloat(params.minlon)],
117 [parseFloat(params.maxlat), parseFloat(params.maxlon)]);
118 } else if (params.mlon && params.mlat) {
119 mapParams.lon = parseFloat(params.mlon);
120 mapParams.lat = parseFloat(params.mlat);
121 mapParams.zoom = parseInt(params.zoom || 12);
122 } else if (loc = Cookies.get('_osm_location')) {
123 loc = loc.split("|");
124 mapParams.lon = parseFloat(loc[0]);
125 mapParams.lat = parseFloat(loc[1]);
126 mapParams.zoom = parseInt(loc[2]);
127 } else if (OSM.home) {
128 mapParams.lon = OSM.home.lon;
129 mapParams.lat = OSM.home.lat;
131 } else if (OSM.location) {
132 mapParams.bounds = L.latLngBounds(
133 [OSM.location.minlat,
134 OSM.location.minlon],
135 [OSM.location.maxlat,
136 OSM.location.maxlon]);
138 mapParams.lon = -0.1;
139 mapParams.lat = 51.5;
140 mapParams.zoom = parseInt(params.zoom || 5);
143 mapParams.layers = hash.layers || (loc && loc[3]) || '';
145 var scale = parseFloat(params.scale);
147 mapParams.zoom = Math.log(360.0 / (scale * 512.0)) / Math.log(2.0);
153 parseHash: function(hash) {
156 var i = hash.indexOf('#');
161 hash = Qs.parse(hash.slice(i + 1));
163 var map = (hash.map || '').split('/'),
164 zoom = parseInt(map[0], 10),
165 lat = parseFloat(map[1]),
166 lon = parseFloat(map[2]);
168 if (!isNaN(zoom) && !isNaN(lat) && !isNaN(lon)) {
169 args.center = new L.LatLng(lat, lon);
174 args.layers = hash.layers;
180 formatHash: function(args) {
181 var center, zoom, layers;
183 if (args instanceof L.Map) {
184 center = args.getCenter();
185 zoom = args.getZoom();
186 layers = args.getLayersCode();
188 center = args.center || L.latLng(args.lat, args.lon);
190 layers = args.layers || '';
193 center = center.wrap();
194 layers = layers.replace('M', '');
196 var precision = OSM.zoomPrecision(zoom),
197 hash = '#map=' + zoom +
198 '/' + center.lat.toFixed(precision) +
199 '/' + center.lng.toFixed(precision);
202 hash += '&layers=' + layers;
208 zoomPrecision: function(zoom) {
209 var pixels = Math.pow(2, 8 + zoom);
211 return Math.ceil(Math.log10(pixels / degrees));
214 locationCookie: function(map) {
215 var center = map.getCenter().wrap(),
216 zoom = map.getZoom(),
217 precision = OSM.zoomPrecision(zoom);
218 return [center.lng.toFixed(precision), center.lat.toFixed(precision), zoom, map.getLayersCode()].join('|');
221 distance: function(latlng1, latlng2) {
222 var lat1 = latlng1.lat * Math.PI / 180,
223 lng1 = latlng1.lng * Math.PI / 180,
224 lat2 = latlng2.lat * Math.PI / 180,
225 lng2 = latlng2.lng * Math.PI / 180,
226 latdiff = lat2 - lat1,
227 lngdiff = lng2 - lng1;
229 return 6372795 * 2 * Math.asin(
231 Math.pow(Math.sin(latdiff / 2), 2) +
232 Math.cos(lat1) * Math.cos(lat2) * Math.pow(Math.sin(lngdiff / 2), 2)