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 %>,
13 MAPQUEST_KEY: <%= MAPQUEST_KEY.to_json %>,
15 MARKER_GREEN: <%= image_path("marker-green.png").to_json %>,
16 MARKER_RED: <%= image_path("marker-red.png").to_json %>,
18 MARKER_ICON: <%= image_path("images/marker-icon.png").to_json %>,
19 MARKER_ICON_2X: <%= image_path("images/marker-icon-2x.png").to_json %>,
20 MARKER_SHADOW: <%= image_path("images/marker-shadow.png").to_json %>,
22 NEW_NOTE_MARKER: <%= image_path("new_note_marker.png").to_json %>,
23 OPEN_NOTE_MARKER: <%= image_path("open_note_marker.png").to_json %>,
24 CLOSED_NOTE_MARKER: <%= image_path("closed_note_marker.png").to_json %>,
26 apiUrl: function (object) {
27 var url = "/api/" + OSM.API_VERSION + "/" + object.type + "/" + object.id;
29 if (object.type === "way" || object.type === "relation") {
31 } else if (object.version) {
32 url += "/" + object.version;
38 params: function(search) {
41 search = (search || window.location.search).replace('?', '').split(/&|;/);
43 for (var i = 0; i < search.length; ++i) {
45 j = pair.indexOf('='),
46 key = pair.slice(0, j),
47 val = pair.slice(++j);
48 params[key] = decodeURIComponent(val);
54 mapParams: function (search) {
55 var params = OSM.params(search), mapParams = {}, loc, match;
57 if (params.mlon && params.mlat) {
58 mapParams.marker = true;
59 mapParams.mlon = parseFloat(params.mlon);
60 mapParams.mlat = parseFloat(params.mlat);
63 // Old-style object parameters; still in use for edit links e.g. /edit?way=1234
65 mapParams.object = {type: 'node', id: parseInt(params.node)};
66 } else if (params.way) {
67 mapParams.object = {type: 'way', id: parseInt(params.way)};
68 } else if (params.relation) {
69 mapParams.object = {type: 'relation', id: parseInt(params.relation)};
72 var hash = OSM.parseHash(location.hash);
74 // Decide on a map starting position. Various ways of doing this.
76 mapParams.lon = hash.center.lng;
77 mapParams.lat = hash.center.lat;
78 mapParams.zoom = hash.zoom;
79 } else if (params.bbox) {
80 var bbox = params.bbox.split(',');
81 mapParams.bounds = L.latLngBounds(
82 [parseFloat(bbox[1]), parseFloat(bbox[0])],
83 [parseFloat(bbox[3]), parseFloat(bbox[2])]);
84 } else if (params.minlon && params.minlat && params.maxlon && params.maxlat) {
85 mapParams.bounds = L.latLngBounds(
86 [parseFloat(params.minlat), parseFloat(params.minlon)],
87 [parseFloat(params.maxlat), parseFloat(params.maxlon)]);
88 } else if (params.mlon && params.mlat) {
89 mapParams.lon = parseFloat(params.mlon);
90 mapParams.lat = parseFloat(params.mlat);
91 mapParams.zoom = parseInt(params.zoom || 12);
92 } else if (loc = $.cookie('_osm_location')) {
94 mapParams.lon = parseFloat(loc[0]);
95 mapParams.lat = parseFloat(loc[1]);
96 mapParams.zoom = parseInt(loc[2]);
97 } else if (OSM.home) {
98 mapParams.lon = OSM.home.lon;
99 mapParams.lat = OSM.home.lat;
101 } else if (OSM.location) {
102 mapParams.bounds = L.latLngBounds(
103 [OSM.location.minlat,
104 OSM.location.minlon],
105 [OSM.location.maxlat,
106 OSM.location.maxlon]);
108 mapParams.lon = -0.1;
109 mapParams.lat = 51.5;
110 mapParams.zoom = parseInt(params.zoom || 5);
113 mapParams.layers = hash.layers || (loc && loc[3]) || '';
115 var scale = parseFloat(params.scale);
117 mapParams.zoom = Math.log(360.0 / (scale * 512.0)) / Math.log(2.0);
123 parseHash: function(hash) {
126 var i = hash.indexOf('#');
131 hash = querystring.parse(hash.substr(i + 1));
133 var map = (hash.map || '').split('/'),
134 zoom = parseInt(map[0], 10),
135 lat = parseFloat(map[1]),
136 lon = parseFloat(map[2]);
138 if (!isNaN(zoom) && !isNaN(lat) && !isNaN(lon)) {
139 args.center = new L.LatLng(lat, lon);
144 args.layers = hash.layers;
150 formatHash: function(args) {
151 var center, zoom, layers;
153 if (args instanceof L.Map) {
154 center = args.getCenter();
155 zoom = args.getZoom();
156 layers = args.getLayersCode();
158 center = args.center || L.latLng(args.lat, args.lon);
160 layers = args.layers || '';
163 center = center.wrap();
164 layers = layers.replace('M', '');
166 var precision = OSM.zoomPrecision(zoom),
167 hash = '#map=' + zoom +
168 '/' + center.lat.toFixed(precision) +
169 '/' + center.lng.toFixed(precision);
172 hash += '&layers=' + layers;
178 zoomPrecision: function(zoom) {
179 return Math.max(0, Math.ceil(Math.log(zoom) / Math.LN2));
182 locationCookie: function(map) {
183 var center = map.getCenter().wrap(),
184 zoom = map.getZoom(),
185 precision = OSM.zoomPrecision(zoom);
186 return [center.lng.toFixed(precision), center.lat.toFixed(precision), zoom, map.getLayersCode()].join('|');
189 distance: function(latlng1, latlng2) {
190 var lat1 = latlng1.lat * Math.PI / 180,
191 lng1 = latlng1.lng * Math.PI / 180,
192 lat2 = latlng2.lat * Math.PI / 180,
193 lng2 = latlng2.lng * Math.PI / 180,
194 latdiff = lat2 - lat1,
195 lngdiff = lng2 - lng1;
197 return 6372795 * 2 * Math.asin(
199 Math.pow(Math.sin(latdiff / 2), 2) +
200 Math.cos(lat1) * Math.cos(lat2) * Math.pow(Math.sin(lngdiff / 2), 2)