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 MAPZEN_VALHALLA_URL: <%= MAPZEN_VALHALLA_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?(MAPZEN_VALHALLA_KEY) %>
25 MAPZEN_VALHALLA_KEY: <%= MAPZEN_VALHALLA_KEY.to_json %>,
27 <% if defined?(THUNDERFOREST_KEY) %>
28 THUNDERFOREST_KEY: <%= THUNDERFOREST_KEY.to_json %>,
31 MARKER_GREEN: <%= image_path("marker-green.png").to_json %>,
32 MARKER_RED: <%= image_path("marker-red.png").to_json %>,
34 MARKER_ICON: <%= image_path("images/marker-icon.png").to_json %>,
35 MARKER_ICON_2X: <%= image_path("images/marker-icon-2x.png").to_json %>,
36 MARKER_SHADOW: <%= image_path("images/marker-shadow.png").to_json %>,
38 NEW_NOTE_MARKER: <%= image_path("new_note_marker.png").to_json %>,
39 OPEN_NOTE_MARKER: <%= image_path("open_note_marker.png").to_json %>,
40 CLOSED_NOTE_MARKER: <%= image_path("closed_note_marker.png").to_json %>,
42 SEARCHING: <%= image_path("searching.gif").to_json %>,
44 apiUrl: function (object) {
45 var url = "/api/" + OSM.API_VERSION + "/" + object.type + "/" + object.id;
47 if (object.type === "way" || object.type === "relation") {
49 } else if (object.version) {
50 url += "/" + object.version;
56 params: function(search) {
59 search = (search || window.location.search).replace('?', '').split(/&|;/);
61 for (var i = 0; i < search.length; ++i) {
63 j = pair.indexOf('='),
64 key = pair.slice(0, j),
65 val = pair.slice(++j);
68 params[key] = decodeURIComponent(val);
70 // Ignore parse exceptions
77 mapParams: function (search) {
78 var params = OSM.params(search), mapParams = {}, loc, match;
80 if (params.mlon && params.mlat) {
81 mapParams.marker = true;
82 mapParams.mlon = parseFloat(params.mlon);
83 mapParams.mlat = parseFloat(params.mlat);
86 // Old-style object parameters; still in use for edit links e.g. /edit?way=1234
88 mapParams.object = {type: 'node', id: parseInt(params.node)};
89 } else if (params.way) {
90 mapParams.object = {type: 'way', id: parseInt(params.way)};
91 } else if (params.relation) {
92 mapParams.object = {type: 'relation', id: parseInt(params.relation)};
95 var hash = OSM.parseHash(location.hash);
97 // Decide on a map starting position. Various ways of doing this.
99 mapParams.lon = hash.center.lng;
100 mapParams.lat = hash.center.lat;
101 mapParams.zoom = hash.zoom;
102 } else if (params.bbox) {
103 var bbox = params.bbox.split(',');
104 mapParams.bounds = L.latLngBounds(
105 [parseFloat(bbox[1]), parseFloat(bbox[0])],
106 [parseFloat(bbox[3]), parseFloat(bbox[2])]);
107 } else if (params.minlon && params.minlat && params.maxlon && params.maxlat) {
108 mapParams.bounds = L.latLngBounds(
109 [parseFloat(params.minlat), parseFloat(params.minlon)],
110 [parseFloat(params.maxlat), parseFloat(params.maxlon)]);
111 } else if (params.mlon && params.mlat) {
112 mapParams.lon = parseFloat(params.mlon);
113 mapParams.lat = parseFloat(params.mlat);
114 mapParams.zoom = parseInt(params.zoom || 12);
115 } else if (loc = $.cookie('_osm_location')) {
116 loc = loc.split("|");
117 mapParams.lon = parseFloat(loc[0]);
118 mapParams.lat = parseFloat(loc[1]);
119 mapParams.zoom = parseInt(loc[2]);
120 } else if (OSM.home) {
121 mapParams.lon = OSM.home.lon;
122 mapParams.lat = OSM.home.lat;
124 } else if (OSM.location) {
125 mapParams.bounds = L.latLngBounds(
126 [OSM.location.minlat,
127 OSM.location.minlon],
128 [OSM.location.maxlat,
129 OSM.location.maxlon]);
131 mapParams.lon = -0.1;
132 mapParams.lat = 51.5;
133 mapParams.zoom = parseInt(params.zoom || 5);
136 mapParams.layers = hash.layers || (loc && loc[3]) || '';
138 var scale = parseFloat(params.scale);
140 mapParams.zoom = Math.log(360.0 / (scale * 512.0)) / Math.log(2.0);
146 parseHash: function(hash) {
149 var i = hash.indexOf('#');
154 hash = querystring.parse(hash.substr(i + 1));
156 var map = (hash.map || '').split('/'),
157 zoom = parseInt(map[0], 10),
158 lat = parseFloat(map[1]),
159 lon = parseFloat(map[2]);
161 if (!isNaN(zoom) && !isNaN(lat) && !isNaN(lon)) {
162 args.center = new L.LatLng(lat, lon);
167 args.layers = hash.layers;
173 formatHash: function(args) {
174 var center, zoom, layers;
176 if (args instanceof L.Map) {
177 center = args.getCenter();
178 zoom = args.getZoom();
179 layers = args.getLayersCode();
181 center = args.center || L.latLng(args.lat, args.lon);
183 layers = args.layers || '';
186 center = center.wrap();
187 layers = layers.replace('M', '');
189 var precision = OSM.zoomPrecision(zoom),
190 hash = '#map=' + zoom +
191 '/' + center.lat.toFixed(precision) +
192 '/' + center.lng.toFixed(precision);
195 hash += '&layers=' + layers;
201 zoomPrecision: function(zoom) {
202 return Math.max(0, Math.ceil(Math.log(zoom) / Math.LN2));
205 locationCookie: function(map) {
206 var center = map.getCenter().wrap(),
207 zoom = map.getZoom(),
208 precision = OSM.zoomPrecision(zoom);
209 return [center.lng.toFixed(precision), center.lat.toFixed(precision), zoom, map.getLayersCode()].join('|');
212 distance: function(latlng1, latlng2) {
213 var lat1 = latlng1.lat * Math.PI / 180,
214 lng1 = latlng1.lng * Math.PI / 180,
215 lat2 = latlng2.lat * Math.PI / 180,
216 lng2 = latlng2.lng * Math.PI / 180,
217 latdiff = lat2 - lat1,
218 lngdiff = lng2 - lng1;
220 return 6372795 * 2 * Math.asin(
222 Math.pow(Math.sin(latdiff / 2), 2) +
223 Math.cos(lat1) * Math.cos(lat2) * Math.pow(Math.sin(lngdiff / 2), 2)