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 FOSSGIS_OSRM_URL: <%= FOSSGIS_OSRM_URL.to_json %>,
20 DEFAULT_LOCALE: <%= I18n.default_locale.to_json %>,
22 <% if defined?(MAPQUEST_KEY) %>
23 MAPQUEST_KEY: <%= MAPQUEST_KEY.to_json %>,
25 <% if defined?(THUNDERFOREST_KEY) %>
26 THUNDERFOREST_KEY: <%= THUNDERFOREST_KEY.to_json %>,
29 MARKER_GREEN: <%= image_path("marker-green.png").to_json %>,
30 MARKER_RED: <%= image_path("marker-red.png").to_json %>,
32 MARKER_ICON: <%= image_path("images/marker-icon.png").to_json %>,
33 MARKER_ICON_2X: <%= image_path("images/marker-icon-2x.png").to_json %>,
34 MARKER_SHADOW: <%= image_path("images/marker-shadow.png").to_json %>,
36 NEW_NOTE_MARKER: <%= image_path("new_note_marker.png").to_json %>,
37 OPEN_NOTE_MARKER: <%= image_path("open_note_marker.png").to_json %>,
38 CLOSED_NOTE_MARKER: <%= image_path("closed_note_marker.png").to_json %>,
40 SEARCHING: <%= image_path("searching.gif").to_json %>,
42 apiUrl: function (object) {
43 var url = "/api/" + OSM.API_VERSION + "/" + object.type + "/" + object.id;
45 if (object.type === "way" || object.type === "relation") {
47 } else if (object.version) {
48 url += "/" + object.version;
54 params: function(search) {
57 search = (search || window.location.search).replace('?', '').split(/&|;/);
59 for (var i = 0; i < search.length; ++i) {
61 j = pair.indexOf('='),
62 key = pair.slice(0, j),
63 val = pair.slice(++j);
66 params[key] = decodeURIComponent(val);
68 // Ignore parse exceptions
75 mapParams: function (search) {
76 var params = OSM.params(search), mapParams = {}, loc, match;
78 if (params.mlon && params.mlat) {
79 mapParams.marker = true;
80 mapParams.mlon = parseFloat(params.mlon);
81 mapParams.mlat = parseFloat(params.mlat);
84 // Old-style object parameters; still in use for edit links e.g. /edit?way=1234
86 mapParams.object = {type: 'node', id: parseInt(params.node)};
87 } else if (params.way) {
88 mapParams.object = {type: 'way', id: parseInt(params.way)};
89 } else if (params.relation) {
90 mapParams.object = {type: 'relation', id: parseInt(params.relation)};
93 var hash = OSM.parseHash(location.hash);
95 // Decide on a map starting position. Various ways of doing this.
97 mapParams.lon = hash.center.lng;
98 mapParams.lat = hash.center.lat;
99 mapParams.zoom = hash.zoom;
100 } else if (params.bbox) {
101 var bbox = params.bbox.split(',');
102 mapParams.bounds = L.latLngBounds(
103 [parseFloat(bbox[1]), parseFloat(bbox[0])],
104 [parseFloat(bbox[3]), parseFloat(bbox[2])]);
105 } else if (params.minlon && params.minlat && params.maxlon && params.maxlat) {
106 mapParams.bounds = L.latLngBounds(
107 [parseFloat(params.minlat), parseFloat(params.minlon)],
108 [parseFloat(params.maxlat), parseFloat(params.maxlon)]);
109 } else if (params.mlon && params.mlat) {
110 mapParams.lon = parseFloat(params.mlon);
111 mapParams.lat = parseFloat(params.mlat);
112 mapParams.zoom = parseInt(params.zoom || 12);
113 } else if (loc = $.cookie('_osm_location')) {
114 loc = loc.split("|");
115 mapParams.lon = parseFloat(loc[0]);
116 mapParams.lat = parseFloat(loc[1]);
117 mapParams.zoom = parseInt(loc[2]);
118 } else if (OSM.home) {
119 mapParams.lon = OSM.home.lon;
120 mapParams.lat = OSM.home.lat;
122 } else if (OSM.location) {
123 mapParams.bounds = L.latLngBounds(
124 [OSM.location.minlat,
125 OSM.location.minlon],
126 [OSM.location.maxlat,
127 OSM.location.maxlon]);
129 mapParams.lon = -0.1;
130 mapParams.lat = 51.5;
131 mapParams.zoom = parseInt(params.zoom || 5);
134 mapParams.layers = hash.layers || (loc && loc[3]) || '';
136 var scale = parseFloat(params.scale);
138 mapParams.zoom = Math.log(360.0 / (scale * 512.0)) / Math.log(2.0);
144 parseHash: function(hash) {
147 var i = hash.indexOf('#');
152 hash = querystring.parse(hash.substr(i + 1));
154 var map = (hash.map || '').split('/'),
155 zoom = parseInt(map[0], 10),
156 lat = parseFloat(map[1]),
157 lon = parseFloat(map[2]);
159 if (!isNaN(zoom) && !isNaN(lat) && !isNaN(lon)) {
160 args.center = new L.LatLng(lat, lon);
165 args.layers = hash.layers;
171 formatHash: function(args) {
172 var center, zoom, layers;
174 if (args instanceof L.Map) {
175 center = args.getCenter();
176 zoom = args.getZoom();
177 layers = args.getLayersCode();
179 center = args.center || L.latLng(args.lat, args.lon);
181 layers = args.layers || '';
184 center = center.wrap();
185 layers = layers.replace('M', '');
187 var precision = OSM.zoomPrecision(zoom),
188 hash = '#map=' + zoom +
189 '/' + center.lat.toFixed(precision) +
190 '/' + center.lng.toFixed(precision);
193 hash += '&layers=' + layers;
199 zoomPrecision: function(zoom) {
200 return Math.max(0, Math.ceil(Math.log(zoom) / Math.LN2));
203 locationCookie: function(map) {
204 var center = map.getCenter().wrap(),
205 zoom = map.getZoom(),
206 precision = OSM.zoomPrecision(zoom);
207 return [center.lng.toFixed(precision), center.lat.toFixed(precision), zoom, map.getLayersCode()].join('|');
210 distance: function(latlng1, latlng2) {
211 var lat1 = latlng1.lat * Math.PI / 180,
212 lng1 = latlng1.lng * Math.PI / 180,
213 lat2 = latlng2.lat * Math.PI / 180,
214 lng2 = latlng2.lng * Math.PI / 180,
215 latdiff = lat2 - lat1,
216 lngdiff = lng2 - lng1;
218 return 6372795 * 2 * Math.asin(
220 Math.pow(Math.sin(latdiff / 2), 2) +
221 Math.cos(lat1) * Math.cos(lat2) * Math.pow(Math.sin(lngdiff / 2), 2)