1 //= depend_on settings.yml
2 //= depend_on settings.local.yml
5 <% if defined?(PIWIK) %>
6 PIWIK: <%= PIWIK.to_json %>,
9 MAX_REQUEST_AREA: <%= Settings.max_request_area.to_json %>,
10 SERVER_PROTOCOL: <%= Settings.server_protocol.to_json %>,
11 SERVER_URL: <%= Settings.server_url.to_json %>,
12 API_VERSION: <%= Settings.api_version.to_json %>,
13 STATUS: <%= Settings.status.to_json %>,
14 MAX_NOTE_REQUEST_AREA: <%= Settings.max_note_request_area.to_json %>,
15 OVERPASS_URL: <%= Settings.overpass_url.to_json %>,
16 NOMINATIM_URL: <%= Settings.nominatim_url.to_json %>,
17 GRAPHHOPPER_URL: <%= Settings.graphhopper_url.to_json %>,
18 FOSSGIS_OSRM_URL: <%= Settings.fossgis_osrm_url.to_json %>,
19 DEFAULT_LOCALE: <%= I18n.default_locale.to_json %>,
21 <% if Settings.key?(:thunderforest_key) %>
22 THUNDERFOREST_KEY: <%= Settings.thunderforest_key.to_json %>,
25 MARKER_GREEN: <%= image_path("marker-green.png").to_json %>,
26 MARKER_RED: <%= image_path("marker-red.png").to_json %>,
28 MARKER_ICON: <%= image_path("images/marker-icon.png").to_json %>,
29 MARKER_ICON_2X: <%= image_path("images/marker-icon-2x.png").to_json %>,
30 MARKER_SHADOW: <%= image_path("images/marker-shadow.png").to_json %>,
32 NEW_NOTE_MARKER: <%= image_path("new_note_marker.png").to_json %>,
33 OPEN_NOTE_MARKER: <%= image_path("open_note_marker.png").to_json %>,
34 CLOSED_NOTE_MARKER: <%= image_path("closed_note_marker.png").to_json %>,
36 SEARCHING: <%= image_path("searching.gif").to_json %>,
38 apiUrl: function (object) {
39 var url = "/api/" + OSM.API_VERSION + "/" + object.type + "/" + object.id;
41 if (object.type === "way" || object.type === "relation") {
43 } else if (object.version) {
44 url += "/" + object.version;
50 params: function(search) {
53 search = (search || window.location.search).replace('?', '').split(/&|;/);
55 for (var i = 0; i < search.length; ++i) {
57 j = pair.indexOf('='),
58 key = pair.slice(0, j),
59 val = pair.slice(++j);
62 params[key] = decodeURIComponent(val);
64 // Ignore parse exceptions
71 mapParams: function (search) {
72 var params = OSM.params(search), mapParams = {}, loc, match;
74 if (params.mlon && params.mlat) {
75 mapParams.marker = true;
76 mapParams.mlon = parseFloat(params.mlon);
77 mapParams.mlat = parseFloat(params.mlat);
80 // Old-style object parameters; still in use for edit links e.g. /edit?way=1234
82 mapParams.object = {type: 'node', id: parseInt(params.node)};
83 } else if (params.way) {
84 mapParams.object = {type: 'way', id: parseInt(params.way)};
85 } else if (params.relation) {
86 mapParams.object = {type: 'relation', id: parseInt(params.relation)};
89 var hash = OSM.parseHash(location.hash);
91 // Decide on a map starting position. Various ways of doing this.
93 mapParams.lon = hash.center.lng;
94 mapParams.lat = hash.center.lat;
95 mapParams.zoom = hash.zoom;
96 } else if (params.bbox) {
97 var bbox = params.bbox.split(',');
98 mapParams.bounds = L.latLngBounds(
99 [parseFloat(bbox[1]), parseFloat(bbox[0])],
100 [parseFloat(bbox[3]), parseFloat(bbox[2])]);
101 } else if (params.minlon && params.minlat && params.maxlon && params.maxlat) {
102 mapParams.bounds = L.latLngBounds(
103 [parseFloat(params.minlat), parseFloat(params.minlon)],
104 [parseFloat(params.maxlat), parseFloat(params.maxlon)]);
105 } else if (params.mlon && params.mlat) {
106 mapParams.lon = parseFloat(params.mlon);
107 mapParams.lat = parseFloat(params.mlat);
108 mapParams.zoom = parseInt(params.zoom || 12);
109 } else if (loc = $.cookie('_osm_location')) {
110 loc = loc.split("|");
111 mapParams.lon = parseFloat(loc[0]);
112 mapParams.lat = parseFloat(loc[1]);
113 mapParams.zoom = parseInt(loc[2]);
114 } else if (OSM.home) {
115 mapParams.lon = OSM.home.lon;
116 mapParams.lat = OSM.home.lat;
118 } else if (OSM.location) {
119 mapParams.bounds = L.latLngBounds(
120 [OSM.location.minlat,
121 OSM.location.minlon],
122 [OSM.location.maxlat,
123 OSM.location.maxlon]);
125 mapParams.lon = -0.1;
126 mapParams.lat = 51.5;
127 mapParams.zoom = parseInt(params.zoom || 5);
130 mapParams.layers = hash.layers || (loc && loc[3]) || '';
132 var scale = parseFloat(params.scale);
134 mapParams.zoom = Math.log(360.0 / (scale * 512.0)) / Math.log(2.0);
140 parseHash: function(hash) {
143 var i = hash.indexOf('#');
148 hash = querystring.parse(hash.substr(i + 1));
150 var map = (hash.map || '').split('/'),
151 zoom = parseInt(map[0], 10),
152 lat = parseFloat(map[1]),
153 lon = parseFloat(map[2]);
155 if (!isNaN(zoom) && !isNaN(lat) && !isNaN(lon)) {
156 args.center = new L.LatLng(lat, lon);
161 args.layers = hash.layers;
167 formatHash: function(args) {
168 var center, zoom, layers;
170 if (args instanceof L.Map) {
171 center = args.getCenter();
172 zoom = args.getZoom();
173 layers = args.getLayersCode();
175 center = args.center || L.latLng(args.lat, args.lon);
177 layers = args.layers || '';
180 center = center.wrap();
181 layers = layers.replace('M', '');
183 var precision = OSM.zoomPrecision(zoom),
184 hash = '#map=' + zoom +
185 '/' + center.lat.toFixed(precision) +
186 '/' + center.lng.toFixed(precision);
189 hash += '&layers=' + layers;
195 zoomPrecision: function(zoom) {
196 return Math.max(0, Math.ceil(Math.log(zoom) / Math.LN2));
199 locationCookie: function(map) {
200 var center = map.getCenter().wrap(),
201 zoom = map.getZoom(),
202 precision = OSM.zoomPrecision(zoom);
203 return [center.lng.toFixed(precision), center.lat.toFixed(precision), zoom, map.getLayersCode()].join('|');
206 distance: function(latlng1, latlng2) {
207 var lat1 = latlng1.lat * Math.PI / 180,
208 lng1 = latlng1.lng * Math.PI / 180,
209 lat2 = latlng2.lat * Math.PI / 180,
210 lng2 = latlng2.lng * Math.PI / 180,
211 latdiff = lat2 - lat1,
212 lngdiff = lng2 - lng1;
214 return 6372795 * 2 * Math.asin(
216 Math.pow(Math.sin(latdiff / 2), 2) +
217 Math.cos(lat1) * Math.cos(lat2) * Math.pow(Math.sin(lngdiff / 2), 2)