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 FOSSGIS_OSRM_URL: <%= FOSSGIS_OSRM_URL.to_json %>,
18 DEFAULT_LOCALE: <%= I18n.default_locale.to_json %>,
20 <% if defined?(THUNDERFOREST_KEY) %>
21 THUNDERFOREST_KEY: <%= THUNDERFOREST_KEY.to_json %>,
24 MARKER_GREEN: <%= image_path("marker-green.png").to_json %>,
25 MARKER_RED: <%= image_path("marker-red.png").to_json %>,
27 MARKER_ICON: <%= image_path("images/marker-icon.png").to_json %>,
28 MARKER_ICON_2X: <%= image_path("images/marker-icon-2x.png").to_json %>,
29 MARKER_SHADOW: <%= image_path("images/marker-shadow.png").to_json %>,
31 NEW_NOTE_MARKER: <%= image_path("new_note_marker.png").to_json %>,
32 OPEN_NOTE_MARKER: <%= image_path("open_note_marker.png").to_json %>,
33 CLOSED_NOTE_MARKER: <%= image_path("closed_note_marker.png").to_json %>,
35 SEARCHING: <%= image_path("searching.gif").to_json %>,
37 apiUrl: function (object) {
38 var url = "/api/" + OSM.API_VERSION + "/" + object.type + "/" + object.id;
40 if (object.type === "way" || object.type === "relation") {
42 } else if (object.version) {
43 url += "/" + object.version;
49 params: function(search) {
52 search = (search || window.location.search).replace('?', '').split(/&|;/);
54 for (var i = 0; i < search.length; ++i) {
56 j = pair.indexOf('='),
57 key = pair.slice(0, j),
58 val = pair.slice(++j);
61 params[key] = decodeURIComponent(val);
63 // Ignore parse exceptions
70 mapParams: function (search) {
71 var params = OSM.params(search), mapParams = {}, loc, match;
73 if (params.mlon && params.mlat) {
74 mapParams.marker = true;
75 mapParams.mlon = parseFloat(params.mlon);
76 mapParams.mlat = parseFloat(params.mlat);
79 // Old-style object parameters; still in use for edit links e.g. /edit?way=1234
81 mapParams.object = {type: 'node', id: parseInt(params.node)};
82 } else if (params.way) {
83 mapParams.object = {type: 'way', id: parseInt(params.way)};
84 } else if (params.relation) {
85 mapParams.object = {type: 'relation', id: parseInt(params.relation)};
88 var hash = OSM.parseHash(location.hash);
90 // Decide on a map starting position. Various ways of doing this.
92 mapParams.lon = hash.center.lng;
93 mapParams.lat = hash.center.lat;
94 mapParams.zoom = hash.zoom;
95 } else if (params.bbox) {
96 var bbox = params.bbox.split(',');
97 mapParams.bounds = L.latLngBounds(
98 [parseFloat(bbox[1]), parseFloat(bbox[0])],
99 [parseFloat(bbox[3]), parseFloat(bbox[2])]);
100 } else if (params.minlon && params.minlat && params.maxlon && params.maxlat) {
101 mapParams.bounds = L.latLngBounds(
102 [parseFloat(params.minlat), parseFloat(params.minlon)],
103 [parseFloat(params.maxlat), parseFloat(params.maxlon)]);
104 } else if (params.mlon && params.mlat) {
105 mapParams.lon = parseFloat(params.mlon);
106 mapParams.lat = parseFloat(params.mlat);
107 mapParams.zoom = parseInt(params.zoom || 12);
108 } else if (loc = $.cookie('_osm_location')) {
109 loc = loc.split("|");
110 mapParams.lon = parseFloat(loc[0]);
111 mapParams.lat = parseFloat(loc[1]);
112 mapParams.zoom = parseInt(loc[2]);
113 } else if (OSM.home) {
114 mapParams.lon = OSM.home.lon;
115 mapParams.lat = OSM.home.lat;
117 } else if (OSM.location) {
118 mapParams.bounds = L.latLngBounds(
119 [OSM.location.minlat,
120 OSM.location.minlon],
121 [OSM.location.maxlat,
122 OSM.location.maxlon]);
124 mapParams.lon = -0.1;
125 mapParams.lat = 51.5;
126 mapParams.zoom = parseInt(params.zoom || 5);
129 mapParams.layers = hash.layers || (loc && loc[3]) || '';
131 var scale = parseFloat(params.scale);
133 mapParams.zoom = Math.log(360.0 / (scale * 512.0)) / Math.log(2.0);
139 parseHash: function(hash) {
142 var i = hash.indexOf('#');
147 hash = querystring.parse(hash.substr(i + 1));
149 var map = (hash.map || '').split('/'),
150 zoom = parseInt(map[0], 10),
151 lat = parseFloat(map[1]),
152 lon = parseFloat(map[2]);
154 if (!isNaN(zoom) && !isNaN(lat) && !isNaN(lon)) {
155 args.center = new L.LatLng(lat, lon);
160 args.layers = hash.layers;
166 formatHash: function(args) {
167 var center, zoom, layers;
169 if (args instanceof L.Map) {
170 center = args.getCenter();
171 zoom = args.getZoom();
172 layers = args.getLayersCode();
174 center = args.center || L.latLng(args.lat, args.lon);
176 layers = args.layers || '';
179 center = center.wrap();
180 layers = layers.replace('M', '');
182 var precision = OSM.zoomPrecision(zoom),
183 hash = '#map=' + zoom +
184 '/' + center.lat.toFixed(precision) +
185 '/' + center.lng.toFixed(precision);
188 hash += '&layers=' + layers;
194 zoomPrecision: function(zoom) {
195 return Math.max(0, Math.ceil(Math.log(zoom) / Math.LN2));
198 locationCookie: function(map) {
199 var center = map.getCenter().wrap(),
200 zoom = map.getZoom(),
201 precision = OSM.zoomPrecision(zoom);
202 return [center.lng.toFixed(precision), center.lat.toFixed(precision), zoom, map.getLayersCode()].join('|');
205 distance: function(latlng1, latlng2) {
206 var lat1 = latlng1.lat * Math.PI / 180,
207 lng1 = latlng1.lng * Math.PI / 180,
208 lat2 = latlng2.lat * Math.PI / 180,
209 lng2 = latlng2.lng * Math.PI / 180,
210 latdiff = lat2 - lat1,
211 lngdiff = lng2 - lng1;
213 return 6372795 * 2 * Math.asin(
215 Math.pow(Math.sin(latdiff / 2), 2) +
216 Math.cos(lat1) * Math.cos(lat2) * Math.pow(Math.sin(lngdiff / 2), 2)