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 %>,
16 <% if defined?(MAPQUEST_KEY) %>
17 MAPQUEST_KEY: <%= MAPQUEST_KEY.to_json %>,
19 <% if defined?(MAPZEN_VALHALLA_KEY) %>
20 MAPZEN_VALHALLA_KEY: <%= MAPZEN_VALHALLA_KEY.to_json %>,
23 MARKER_GREEN: <%= image_path("marker-green.png").to_json %>,
24 MARKER_RED: <%= image_path("marker-red.png").to_json %>,
26 MARKER_ICON: <%= image_path("images/marker-icon.png").to_json %>,
27 MARKER_ICON_2X: <%= image_path("images/marker-icon-2x.png").to_json %>,
28 MARKER_SHADOW: <%= image_path("images/marker-shadow.png").to_json %>,
30 NEW_NOTE_MARKER: <%= image_path("new_note_marker.png").to_json %>,
31 OPEN_NOTE_MARKER: <%= image_path("open_note_marker.png").to_json %>,
32 CLOSED_NOTE_MARKER: <%= image_path("closed_note_marker.png").to_json %>,
34 apiUrl: function (object) {
35 var url = "/api/" + OSM.API_VERSION + "/" + object.type + "/" + object.id;
37 if (object.type === "way" || object.type === "relation") {
39 } else if (object.version) {
40 url += "/" + object.version;
46 params: function(search) {
49 search = (search || window.location.search).replace('?', '').split(/&|;/);
51 for (var i = 0; i < search.length; ++i) {
53 j = pair.indexOf('='),
54 key = pair.slice(0, j),
55 val = pair.slice(++j);
58 params[key] = decodeURIComponent(val);
60 // Ignore parse exceptions
67 mapParams: function (search) {
68 var params = OSM.params(search), mapParams = {}, loc, match;
70 if (params.mlon && params.mlat) {
71 mapParams.marker = true;
72 mapParams.mlon = parseFloat(params.mlon);
73 mapParams.mlat = parseFloat(params.mlat);
76 // Old-style object parameters; still in use for edit links e.g. /edit?way=1234
78 mapParams.object = {type: 'node', id: parseInt(params.node)};
79 } else if (params.way) {
80 mapParams.object = {type: 'way', id: parseInt(params.way)};
81 } else if (params.relation) {
82 mapParams.object = {type: 'relation', id: parseInt(params.relation)};
85 var hash = OSM.parseHash(location.hash);
87 // Decide on a map starting position. Various ways of doing this.
89 mapParams.lon = hash.center.lng;
90 mapParams.lat = hash.center.lat;
91 mapParams.zoom = hash.zoom;
92 } else if (params.bbox) {
93 var bbox = params.bbox.split(',');
94 mapParams.bounds = L.latLngBounds(
95 [parseFloat(bbox[1]), parseFloat(bbox[0])],
96 [parseFloat(bbox[3]), parseFloat(bbox[2])]);
97 } else if (params.minlon && params.minlat && params.maxlon && params.maxlat) {
98 mapParams.bounds = L.latLngBounds(
99 [parseFloat(params.minlat), parseFloat(params.minlon)],
100 [parseFloat(params.maxlat), parseFloat(params.maxlon)]);
101 } else if (params.mlon && params.mlat) {
102 mapParams.lon = parseFloat(params.mlon);
103 mapParams.lat = parseFloat(params.mlat);
104 mapParams.zoom = parseInt(params.zoom || 12);
105 } else if (loc = $.cookie('_osm_location')) {
106 loc = loc.split("|");
107 mapParams.lon = parseFloat(loc[0]);
108 mapParams.lat = parseFloat(loc[1]);
109 mapParams.zoom = parseInt(loc[2]);
110 } else if (OSM.home) {
111 mapParams.lon = OSM.home.lon;
112 mapParams.lat = OSM.home.lat;
114 } else if (OSM.location) {
115 mapParams.bounds = L.latLngBounds(
116 [OSM.location.minlat,
117 OSM.location.minlon],
118 [OSM.location.maxlat,
119 OSM.location.maxlon]);
121 mapParams.lon = -0.1;
122 mapParams.lat = 51.5;
123 mapParams.zoom = parseInt(params.zoom || 5);
126 mapParams.layers = hash.layers || (loc && loc[3]) || '';
128 var scale = parseFloat(params.scale);
130 mapParams.zoom = Math.log(360.0 / (scale * 512.0)) / Math.log(2.0);
136 parseHash: function(hash) {
139 var i = hash.indexOf('#');
144 hash = querystring.parse(hash.substr(i + 1));
146 var map = (hash.map || '').split('/'),
147 zoom = parseInt(map[0], 10),
148 lat = parseFloat(map[1]),
149 lon = parseFloat(map[2]);
151 if (!isNaN(zoom) && !isNaN(lat) && !isNaN(lon)) {
152 args.center = new L.LatLng(lat, lon);
157 args.layers = hash.layers;
163 formatHash: function(args) {
164 var center, zoom, layers;
166 if (args instanceof L.Map) {
167 center = args.getCenter();
168 zoom = args.getZoom();
169 layers = args.getLayersCode();
171 center = args.center || L.latLng(args.lat, args.lon);
173 layers = args.layers || '';
176 center = center.wrap();
177 layers = layers.replace('M', '');
179 var precision = OSM.zoomPrecision(zoom),
180 hash = '#map=' + zoom +
181 '/' + center.lat.toFixed(precision) +
182 '/' + center.lng.toFixed(precision);
185 hash += '&layers=' + layers;
191 zoomPrecision: function(zoom) {
192 return Math.max(0, Math.ceil(Math.log(zoom) / Math.LN2));
195 locationCookie: function(map) {
196 var center = map.getCenter().wrap(),
197 zoom = map.getZoom(),
198 precision = OSM.zoomPrecision(zoom);
199 return [center.lng.toFixed(precision), center.lat.toFixed(precision), zoom, map.getLayersCode()].join('|');
202 distance: function(latlng1, latlng2) {
203 var lat1 = latlng1.lat * Math.PI / 180,
204 lng1 = latlng1.lng * Math.PI / 180,
205 lat2 = latlng2.lat * Math.PI / 180,
206 lng2 = latlng2.lng * Math.PI / 180,
207 latdiff = lat2 - lat1,
208 lngdiff = lng2 - lng1;
210 return 6372795 * 2 * Math.asin(
212 Math.pow(Math.sin(latdiff / 2), 2) +
213 Math.cos(lat1) * Math.cos(lat2) * Math.pow(Math.sin(lngdiff / 2), 2)