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 %>,
20 <% if defined?(MAPQUEST_KEY) %>
21 MAPQUEST_KEY: <%= MAPQUEST_KEY.to_json %>,
23 <% if defined?(MAPZEN_VALHALLA_KEY) %>
24 MAPZEN_VALHALLA_KEY: <%= MAPZEN_VALHALLA_KEY.to_json %>,
26 <% if defined?(THUNDERFOREST_KEY) %>
27 THUNDERFOREST_KEY: <%= THUNDERFOREST_KEY.to_json %>,
30 MARKER_GREEN: <%= image_path("marker-green.png").to_json %>,
31 MARKER_RED: <%= image_path("marker-red.png").to_json %>,
33 MARKER_ICON: <%= image_path("images/marker-icon.png").to_json %>,
34 MARKER_ICON_2X: <%= image_path("images/marker-icon-2x.png").to_json %>,
35 MARKER_SHADOW: <%= image_path("images/marker-shadow.png").to_json %>,
37 NEW_NOTE_MARKER: <%= image_path("new_note_marker.png").to_json %>,
38 OPEN_NOTE_MARKER: <%= image_path("open_note_marker.png").to_json %>,
39 CLOSED_NOTE_MARKER: <%= image_path("closed_note_marker.png").to_json %>,
41 SEARCHING: <%= image_path("searching.gif").to_json %>,
43 apiUrl: function (object) {
44 var url = "/api/" + OSM.API_VERSION + "/" + object.type + "/" + object.id;
46 if (object.type === "way" || object.type === "relation") {
48 } else if (object.version) {
49 url += "/" + object.version;
55 params: function(search) {
58 search = (search || window.location.search).replace('?', '').split(/&|;/);
60 for (var i = 0; i < search.length; ++i) {
62 j = pair.indexOf('='),
63 key = pair.slice(0, j),
64 val = pair.slice(++j);
67 params[key] = decodeURIComponent(val);
69 // Ignore parse exceptions
76 mapParams: function (search) {
77 var params = OSM.params(search), mapParams = {}, loc, match;
79 if (params.mlon && params.mlat) {
80 mapParams.marker = true;
81 mapParams.mlon = parseFloat(params.mlon);
82 mapParams.mlat = parseFloat(params.mlat);
85 // Old-style object parameters; still in use for edit links e.g. /edit?way=1234
87 mapParams.object = {type: 'node', id: parseInt(params.node)};
88 } else if (params.way) {
89 mapParams.object = {type: 'way', id: parseInt(params.way)};
90 } else if (params.relation) {
91 mapParams.object = {type: 'relation', id: parseInt(params.relation)};
94 var hash = OSM.parseHash(location.hash);
96 // Decide on a map starting position. Various ways of doing this.
98 mapParams.lon = hash.center.lng;
99 mapParams.lat = hash.center.lat;
100 mapParams.zoom = hash.zoom;
101 } else if (params.bbox) {
102 var bbox = params.bbox.split(',');
103 mapParams.bounds = L.latLngBounds(
104 [parseFloat(bbox[1]), parseFloat(bbox[0])],
105 [parseFloat(bbox[3]), parseFloat(bbox[2])]);
106 } else if (params.minlon && params.minlat && params.maxlon && params.maxlat) {
107 mapParams.bounds = L.latLngBounds(
108 [parseFloat(params.minlat), parseFloat(params.minlon)],
109 [parseFloat(params.maxlat), parseFloat(params.maxlon)]);
110 } else if (params.mlon && params.mlat) {
111 mapParams.lon = parseFloat(params.mlon);
112 mapParams.lat = parseFloat(params.mlat);
113 mapParams.zoom = parseInt(params.zoom || 12);
114 } else if (loc = $.cookie('_osm_location')) {
115 loc = loc.split("|");
116 mapParams.lon = parseFloat(loc[0]);
117 mapParams.lat = parseFloat(loc[1]);
118 mapParams.zoom = parseInt(loc[2]);
119 } else if (OSM.home) {
120 mapParams.lon = OSM.home.lon;
121 mapParams.lat = OSM.home.lat;
123 } else if (OSM.location) {
124 mapParams.bounds = L.latLngBounds(
125 [OSM.location.minlat,
126 OSM.location.minlon],
127 [OSM.location.maxlat,
128 OSM.location.maxlon]);
130 mapParams.lon = -0.1;
131 mapParams.lat = 51.5;
132 mapParams.zoom = parseInt(params.zoom || 5);
135 mapParams.layers = hash.layers || (loc && loc[3]) || '';
137 var scale = parseFloat(params.scale);
139 mapParams.zoom = Math.log(360.0 / (scale * 512.0)) / Math.log(2.0);
145 parseHash: function(hash) {
148 var i = hash.indexOf('#');
153 hash = querystring.parse(hash.substr(i + 1));
155 var map = (hash.map || '').split('/'),
156 zoom = parseInt(map[0], 10),
157 lat = parseFloat(map[1]),
158 lon = parseFloat(map[2]);
160 if (!isNaN(zoom) && !isNaN(lat) && !isNaN(lon)) {
161 args.center = new L.LatLng(lat, lon);
166 args.layers = hash.layers;
172 formatHash: function(args) {
173 var center, zoom, layers;
175 if (args instanceof L.Map) {
176 center = args.getCenter();
177 zoom = args.getZoom();
178 layers = args.getLayersCode();
180 center = args.center || L.latLng(args.lat, args.lon);
182 layers = args.layers || '';
185 center = center.wrap();
186 layers = layers.replace('M', '');
188 var precision = OSM.zoomPrecision(zoom),
189 hash = '#map=' + zoom +
190 '/' + center.lat.toFixed(precision) +
191 '/' + center.lng.toFixed(precision);
194 hash += '&layers=' + layers;
200 zoomPrecision: function(zoom) {
201 return Math.max(0, Math.ceil(Math.log(zoom) / Math.LN2));
204 locationCookie: function(map) {
205 var center = map.getCenter().wrap(),
206 zoom = map.getZoom(),
207 precision = OSM.zoomPrecision(zoom);
208 return [center.lng.toFixed(precision), center.lat.toFixed(precision), zoom, map.getLayersCode()].join('|');
211 distance: function(latlng1, latlng2) {
212 var lat1 = latlng1.lat * Math.PI / 180,
213 lng1 = latlng1.lng * Math.PI / 180,
214 lat2 = latlng2.lat * Math.PI / 180,
215 lng2 = latlng2.lng * Math.PI / 180,
216 latdiff = lat2 - lat1,
217 lngdiff = lng2 - lng1;
219 return 6372795 * 2 * Math.asin(
221 Math.pow(Math.sin(latdiff / 2), 2) +
222 Math.cos(lat1) * Math.cos(lat2) * Math.pow(Math.sin(lngdiff / 2), 2)