2 <% if defined?(PIWIK) %>
3 PIWIK: <%= PIWIK.to_json %>,
6 MAX_REQUEST_AREA: <%= MAX_REQUEST_AREA.to_json %>,
7 SERVER_URL: <%= SERVER_URL.to_json %>,
8 API_VERSION: <%= API_VERSION.to_json %>,
9 STATUS: <%= STATUS.to_json %>,
10 MAX_NOTE_REQUEST_AREA: <%= MAX_NOTE_REQUEST_AREA.to_json %>,
11 OVERPASS_URL: <%= OVERPASS_URL.to_json %>,
12 NOMINATIM_URL: <%= NOMINATIM_URL.to_json %>,
14 MARKER_GREEN: <%= image_path("marker-green.png").to_json %>,
15 MARKER_RED: <%= image_path("marker-red.png").to_json %>,
16 MARKER_ICON: <%= image_path("marker-icon.png").to_json %>,
17 MARKER_ICON_2X: <%= image_path("marker-icon-2x.png").to_json %>,
18 MARKER_SHADOW: <%= image_path("marker-shadow.png").to_json %>,
20 NEW_NOTE_MARKER: <%= image_path("new_note_marker.png").to_json %>,
21 OPEN_NOTE_MARKER: <%= image_path("open_note_marker.png").to_json %>,
22 CLOSED_NOTE_MARKER: <%= image_path("closed_note_marker.png").to_json %>,
24 apiUrl: function (object) {
25 var url = "/api/" + OSM.API_VERSION + "/" + object.type + "/" + object.id;
27 if (object.type === "way" || object.type === "relation") {
29 } else if (object.version) {
30 url += "/" + object.version;
36 params: function(search) {
39 search = (search || window.location.search).replace('?', '').split(/&|;/);
41 for (var i = 0; i < search.length; ++i) {
43 j = pair.indexOf('='),
44 key = pair.slice(0, j),
45 val = pair.slice(++j);
46 params[key] = decodeURIComponent(val);
52 mapParams: function (search) {
53 var params = OSM.params(search), mapParams = {}, loc, match;
55 if (params.mlon && params.mlat) {
56 mapParams.marker = true;
57 mapParams.mlon = parseFloat(params.mlon);
58 mapParams.mlat = parseFloat(params.mlat);
61 // Old-style object parameters; still in use for edit links e.g. /edit?way=1234
63 mapParams.object = {type: 'node', id: parseInt(params.node)};
64 } else if (params.way) {
65 mapParams.object = {type: 'way', id: parseInt(params.way)};
66 } else if (params.relation) {
67 mapParams.object = {type: 'relation', id: parseInt(params.relation)};
70 var hash = OSM.parseHash(location.hash);
72 // Decide on a map starting position. Various ways of doing this.
74 mapParams.lon = hash.center.lng;
75 mapParams.lat = hash.center.lat;
76 mapParams.zoom = hash.zoom;
77 } else if (params.bbox) {
78 var bbox = params.bbox.split(',');
79 mapParams.bounds = L.latLngBounds(
80 [parseFloat(bbox[1]), parseFloat(bbox[0])],
81 [parseFloat(bbox[3]), parseFloat(bbox[2])]);
82 } else if (params.minlon && params.minlat && params.maxlon && params.maxlat) {
83 mapParams.bounds = L.latLngBounds(
84 [parseFloat(params.minlat), parseFloat(params.minlon)],
85 [parseFloat(params.maxlat), parseFloat(params.maxlon)]);
86 } else if (params.mlon && params.mlat) {
87 mapParams.lon = parseFloat(params.mlon);
88 mapParams.lat = parseFloat(params.mlat);
89 mapParams.zoom = parseInt(params.zoom || 12);
90 } else if (loc = $.cookie('_osm_location')) {
92 mapParams.lon = parseFloat(loc[0]);
93 mapParams.lat = parseFloat(loc[1]);
94 mapParams.zoom = parseInt(loc[2]);
95 } else if (OSM.home) {
96 mapParams.lon = OSM.home.lon;
97 mapParams.lat = OSM.home.lat;
99 } else if (OSM.location) {
100 mapParams.bounds = L.latLngBounds(
101 [OSM.location.minlat,
102 OSM.location.minlon],
103 [OSM.location.maxlat,
104 OSM.location.maxlon]);
106 mapParams.lon = -0.1;
107 mapParams.lat = 51.5;
108 mapParams.zoom = parseInt(params.zoom || 5);
111 mapParams.layers = hash.layers || (loc && loc[3]) || '';
113 var scale = parseFloat(params.scale);
115 mapParams.zoom = Math.log(360.0 / (scale * 512.0)) / Math.log(2.0);
121 parseHash: function(hash) {
124 var i = hash.indexOf('#');
129 hash = querystring.parse(hash.substr(i + 1));
131 var map = (hash.map || '').split('/'),
132 zoom = parseInt(map[0], 10),
133 lat = parseFloat(map[1]),
134 lon = parseFloat(map[2]);
136 if (!isNaN(zoom) && !isNaN(lat) && !isNaN(lon)) {
137 args.center = new L.LatLng(lat, lon);
142 args.layers = hash.layers;
148 formatHash: function(args) {
149 var center, zoom, layers;
151 if (args instanceof L.Map) {
152 center = args.getCenter();
153 zoom = args.getZoom();
154 layers = args.getLayersCode();
156 center = args.center || L.latLng(args.lat, args.lon);
158 layers = args.layers || '';
161 center = center.wrap();
162 layers = layers.replace('M', '');
164 var precision = OSM.zoomPrecision(zoom),
165 hash = '#map=' + zoom +
166 '/' + center.lat.toFixed(precision) +
167 '/' + center.lng.toFixed(precision);
170 hash += '&layers=' + layers;
176 zoomPrecision: function(zoom) {
177 return Math.max(0, Math.ceil(Math.log(zoom) / Math.LN2));
180 locationCookie: function(map) {
181 var center = map.getCenter().wrap(),
182 zoom = map.getZoom(),
183 precision = OSM.zoomPrecision(zoom);
184 return [center.lng.toFixed(precision), center.lat.toFixed(precision), zoom, map.getLayersCode()].join('|');
187 distance: function(latlng1, latlng2) {
188 var lat1 = latlng1.lat * Math.PI / 180,
189 lng1 = latlng1.lng * Math.PI / 180,
190 lat2 = latlng2.lat * Math.PI / 180,
191 lng2 = latlng2.lng * Math.PI / 180,
192 latdiff = lat2 - lat1,
193 lngdiff = lng2 - lng1;
195 return 6372795 * 2 * Math.asin(
197 Math.pow(Math.sin(latdiff / 2), 2) +
198 Math.cos(lat1) * Math.cos(lat2) * Math.pow(Math.sin(lngdiff / 2), 2)