1 //= depend_on application.yml
4 <% if defined?(PIWIK) %>
5 PIWIK: <%= PIWIK.to_json %>,
8 MAX_REQUEST_AREA: <%= MAX_REQUEST_AREA.to_json %>,
9 SERVER_PROTOCOL: <%= SERVER_PROTOCOL.to_json %>,
10 SERVER_URL: <%= SERVER_URL.to_json %>,
11 API_VERSION: <%= API_VERSION.to_json %>,
12 STATUS: <%= STATUS.to_json %>,
13 MAX_NOTE_REQUEST_AREA: <%= MAX_NOTE_REQUEST_AREA.to_json %>,
14 OVERPASS_URL: <%= OVERPASS_URL.to_json %>,
15 NOMINATIM_URL: <%= NOMINATIM_URL.to_json %>,
16 GRAPHHOPPER_URL: <%= GRAPHHOPPER_URL.to_json %>,
17 MAPQUEST_DIRECTIONS_URL: <%= MAPQUEST_DIRECTIONS_URL.to_json %>,
18 OSRM_URL: <%= OSRM_URL.to_json %>,
19 DEFAULT_LOCALE: <%= I18n.default_locale.to_json %>,
21 <% if defined?(MAPQUEST_KEY) %>
22 MAPQUEST_KEY: <%= MAPQUEST_KEY.to_json %>,
24 <% if defined?(THUNDERFOREST_KEY) %>
25 THUNDERFOREST_KEY: <%= THUNDERFOREST_KEY.to_json %>,
28 MARKER_GREEN: <%= image_path("marker-green.png").to_json %>,
29 MARKER_RED: <%= image_path("marker-red.png").to_json %>,
31 MARKER_ICON: <%= image_path("images/marker-icon.png").to_json %>,
32 MARKER_ICON_2X: <%= image_path("images/marker-icon-2x.png").to_json %>,
33 MARKER_SHADOW: <%= image_path("images/marker-shadow.png").to_json %>,
35 NEW_NOTE_MARKER: <%= image_path("new_note_marker.png").to_json %>,
36 OPEN_NOTE_MARKER: <%= image_path("open_note_marker.png").to_json %>,
37 CLOSED_NOTE_MARKER: <%= image_path("closed_note_marker.png").to_json %>,
39 SEARCHING: <%= image_path("searching.gif").to_json %>,
41 apiUrl: function (object) {
42 var url = "/api/" + OSM.API_VERSION + "/" + object.type + "/" + object.id;
44 if (object.type === "way" || object.type === "relation") {
46 } else if (object.version) {
47 url += "/" + object.version;
53 params: function(search) {
56 search = (search || window.location.search).replace('?', '').split(/&|;/);
58 for (var i = 0; i < search.length; ++i) {
60 j = pair.indexOf('='),
61 key = pair.slice(0, j),
62 val = pair.slice(++j);
65 params[key] = decodeURIComponent(val);
67 // Ignore parse exceptions
74 mapParams: function (search) {
75 var params = OSM.params(search), mapParams = {}, loc, match;
77 if (params.mlon && params.mlat) {
78 mapParams.marker = true;
79 mapParams.mlon = parseFloat(params.mlon);
80 mapParams.mlat = parseFloat(params.mlat);
83 // Old-style object parameters; still in use for edit links e.g. /edit?way=1234
85 mapParams.object = {type: 'node', id: parseInt(params.node)};
86 } else if (params.way) {
87 mapParams.object = {type: 'way', id: parseInt(params.way)};
88 } else if (params.relation) {
89 mapParams.object = {type: 'relation', id: parseInt(params.relation)};
92 var hash = OSM.parseHash(location.hash);
94 // Decide on a map starting position. Various ways of doing this.
96 mapParams.lon = hash.center.lng;
97 mapParams.lat = hash.center.lat;
98 mapParams.zoom = hash.zoom;
99 } else if (params.bbox) {
100 var bbox = params.bbox.split(',');
101 mapParams.bounds = L.latLngBounds(
102 [parseFloat(bbox[1]), parseFloat(bbox[0])],
103 [parseFloat(bbox[3]), parseFloat(bbox[2])]);
104 } else if (params.minlon && params.minlat && params.maxlon && params.maxlat) {
105 mapParams.bounds = L.latLngBounds(
106 [parseFloat(params.minlat), parseFloat(params.minlon)],
107 [parseFloat(params.maxlat), parseFloat(params.maxlon)]);
108 } else if (params.mlon && params.mlat) {
109 mapParams.lon = parseFloat(params.mlon);
110 mapParams.lat = parseFloat(params.mlat);
111 mapParams.zoom = parseInt(params.zoom || 12);
112 } else if (loc = $.cookie('_osm_location')) {
113 loc = loc.split("|");
114 mapParams.lon = parseFloat(loc[0]);
115 mapParams.lat = parseFloat(loc[1]);
116 mapParams.zoom = parseInt(loc[2]);
117 } else if (OSM.home) {
118 mapParams.lon = OSM.home.lon;
119 mapParams.lat = OSM.home.lat;
121 } else if (OSM.location) {
122 mapParams.bounds = L.latLngBounds(
123 [OSM.location.minlat,
124 OSM.location.minlon],
125 [OSM.location.maxlat,
126 OSM.location.maxlon]);
128 mapParams.lon = -0.1;
129 mapParams.lat = 51.5;
130 mapParams.zoom = parseInt(params.zoom || 5);
133 mapParams.layers = hash.layers || (loc && loc[3]) || '';
135 var scale = parseFloat(params.scale);
137 mapParams.zoom = Math.log(360.0 / (scale * 512.0)) / Math.log(2.0);
143 parseHash: function(hash) {
146 var i = hash.indexOf('#');
151 hash = querystring.parse(hash.substr(i + 1));
153 var map = (hash.map || '').split('/'),
154 zoom = parseInt(map[0], 10),
155 lat = parseFloat(map[1]),
156 lon = parseFloat(map[2]);
158 if (!isNaN(zoom) && !isNaN(lat) && !isNaN(lon)) {
159 args.center = new L.LatLng(lat, lon);
164 args.layers = hash.layers;
170 formatHash: function(args) {
171 var center, zoom, layers;
173 if (args instanceof L.Map) {
174 center = args.getCenter();
175 zoom = args.getZoom();
176 layers = args.getLayersCode();
178 center = args.center || L.latLng(args.lat, args.lon);
180 layers = args.layers || '';
183 center = center.wrap();
184 layers = layers.replace('M', '');
186 var precision = OSM.zoomPrecision(zoom),
187 hash = '#map=' + zoom +
188 '/' + center.lat.toFixed(precision) +
189 '/' + center.lng.toFixed(precision);
192 hash += '&layers=' + layers;
198 zoomPrecision: function(zoom) {
199 return Math.max(0, Math.ceil(Math.log(zoom) / Math.LN2));
202 locationCookie: function(map) {
203 var center = map.getCenter().wrap(),
204 zoom = map.getZoom(),
205 precision = OSM.zoomPrecision(zoom);
206 return [center.lng.toFixed(precision), center.lat.toFixed(precision), zoom, map.getLayersCode()].join('|');
209 distance: function(latlng1, latlng2) {
210 var lat1 = latlng1.lat * Math.PI / 180,
211 lng1 = latlng1.lng * Math.PI / 180,
212 lat2 = latlng2.lat * Math.PI / 180,
213 lng2 = latlng2.lng * Math.PI / 180,
214 latdiff = lat2 - lat1,
215 lngdiff = lng2 - lng1;
217 return 6372795 * 2 * Math.asin(
219 Math.pow(Math.sin(latdiff / 2), 2) +
220 Math.cos(lat1) * Math.cos(lat2) * Math.pow(Math.sin(lngdiff / 2), 2)