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_URL: <%= SERVER_URL.to_json %>,
10 API_VERSION: <%= API_VERSION.to_json %>,
11 STATUS: <%= STATUS.to_json %>,
12 MAX_NOTE_REQUEST_AREA: <%= MAX_NOTE_REQUEST_AREA.to_json %>,
13 OVERPASS_URL: <%= OVERPASS_URL.to_json %>,
14 NOMINATIM_URL: <%= NOMINATIM_URL.to_json %>,
15 GRAPHHOPPER_URL: <%= GRAPHHOPPER_URL.to_json %>,
16 MAPQUEST_DIRECTIONS_URL: <%= MAPQUEST_DIRECTIONS_URL.to_json %>,
17 OSRM_URL: <%= OSRM_URL.to_json %>,
18 DEFAULT_LOCALE: <%= I18n.default_locale.to_json %>,
20 <% if defined?(MAPQUEST_KEY) %>
21 MAPQUEST_KEY: <%= MAPQUEST_KEY.to_json %>,
23 <% if defined?(THUNDERFOREST_KEY) %>
24 THUNDERFOREST_KEY: <%= THUNDERFOREST_KEY.to_json %>,
27 MARKER_GREEN: <%= image_path("marker-green.png").to_json %>,
28 MARKER_RED: <%= image_path("marker-red.png").to_json %>,
30 MARKER_ICON: <%= image_path("images/marker-icon.png").to_json %>,
31 MARKER_ICON_2X: <%= image_path("images/marker-icon-2x.png").to_json %>,
32 MARKER_SHADOW: <%= image_path("images/marker-shadow.png").to_json %>,
34 NEW_NOTE_MARKER: <%= image_path("new_note_marker.png").to_json %>,
35 OPEN_NOTE_MARKER: <%= image_path("open_note_marker.png").to_json %>,
36 CLOSED_NOTE_MARKER: <%= image_path("closed_note_marker.png").to_json %>,
38 SEARCHING: <%= image_path("searching.gif").to_json %>,
40 apiUrl: function (object) {
41 var url = "/api/" + OSM.API_VERSION + "/" + object.type + "/" + 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)};
91 var hash = OSM.parseHash(location.hash);
93 // Decide on a map starting position. Various ways of doing this.
95 mapParams.lon = hash.center.lng;
96 mapParams.lat = hash.center.lat;
97 mapParams.zoom = hash.zoom;
98 } else if (params.bbox) {
99 var bbox = params.bbox.split(',');
100 mapParams.bounds = L.latLngBounds(
101 [parseFloat(bbox[1]), parseFloat(bbox[0])],
102 [parseFloat(bbox[3]), parseFloat(bbox[2])]);
103 } else if (params.minlon && params.minlat && params.maxlon && params.maxlat) {
104 mapParams.bounds = L.latLngBounds(
105 [parseFloat(params.minlat), parseFloat(params.minlon)],
106 [parseFloat(params.maxlat), parseFloat(params.maxlon)]);
107 } else if (params.mlon && params.mlat) {
108 mapParams.lon = parseFloat(params.mlon);
109 mapParams.lat = parseFloat(params.mlat);
110 mapParams.zoom = parseInt(params.zoom || 12);
111 } else if (loc = $.cookie('_osm_location')) {
112 loc = loc.split("|");
113 mapParams.lon = parseFloat(loc[0]);
114 mapParams.lat = parseFloat(loc[1]);
115 mapParams.zoom = parseInt(loc[2]);
116 } else if (OSM.home) {
117 mapParams.lon = OSM.home.lon;
118 mapParams.lat = OSM.home.lat;
120 } else if (OSM.location) {
121 mapParams.bounds = L.latLngBounds(
122 [OSM.location.minlat,
123 OSM.location.minlon],
124 [OSM.location.maxlat,
125 OSM.location.maxlon]);
127 mapParams.lon = -0.1;
128 mapParams.lat = 51.5;
129 mapParams.zoom = parseInt(params.zoom || 5);
132 mapParams.layers = hash.layers || (loc && loc[3]) || '';
134 var scale = parseFloat(params.scale);
136 mapParams.zoom = Math.log(360.0 / (scale * 512.0)) / Math.log(2.0);
142 parseHash: function(hash) {
145 var i = hash.indexOf('#');
150 hash = querystring.parse(hash.substr(i + 1));
152 var map = (hash.map || '').split('/'),
153 zoom = parseInt(map[0], 10),
154 lat = parseFloat(map[1]),
155 lon = parseFloat(map[2]);
157 if (!isNaN(zoom) && !isNaN(lat) && !isNaN(lon)) {
158 args.center = new L.LatLng(lat, lon);
163 args.layers = hash.layers;
169 formatHash: function(args) {
170 var center, zoom, layers;
172 if (args instanceof L.Map) {
173 center = args.getCenter();
174 zoom = args.getZoom();
175 layers = args.getLayersCode();
177 center = args.center || L.latLng(args.lat, args.lon);
179 layers = args.layers || '';
182 center = center.wrap();
183 layers = layers.replace('M', '');
185 var precision = OSM.zoomPrecision(zoom),
186 hash = '#map=' + zoom +
187 '/' + center.lat.toFixed(precision) +
188 '/' + center.lng.toFixed(precision);
191 hash += '&layers=' + layers;
197 zoomPrecision: function(zoom) {
198 return Math.max(0, Math.ceil(Math.log(zoom) / Math.LN2));
201 locationCookie: function(map) {
202 var center = map.getCenter().wrap(),
203 zoom = map.getZoom(),
204 precision = OSM.zoomPrecision(zoom);
205 return [center.lng.toFixed(precision), center.lat.toFixed(precision), zoom, map.getLayersCode()].join('|');
208 distance: function(latlng1, latlng2) {
209 var lat1 = latlng1.lat * Math.PI / 180,
210 lng1 = latlng1.lng * Math.PI / 180,
211 lat2 = latlng2.lat * Math.PI / 180,
212 lng2 = latlng2.lng * Math.PI / 180,
213 latdiff = lat2 - lat1,
214 lngdiff = lng2 - lng1;
216 return 6372795 * 2 * Math.asin(
218 Math.pow(Math.sin(latdiff / 2), 2) +
219 Math.cos(lat1) * Math.cos(lat2) * Math.pow(Math.sin(lngdiff / 2), 2)