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 %>,
17 MARKER_ICON: <%= image_path("images/marker-icon.png").to_json %>,
18 MARKER_ICON_2X: <%= image_path("images/marker-icon-2x.png").to_json %>,
19 MARKER_SHADOW: <%= image_path("images/marker-shadow.png").to_json %>,
21 NEW_NOTE_MARKER: <%= image_path("new_note_marker.png").to_json %>,
22 OPEN_NOTE_MARKER: <%= image_path("open_note_marker.png").to_json %>,
23 CLOSED_NOTE_MARKER: <%= image_path("closed_note_marker.png").to_json %>,
25 apiUrl: function (object) {
26 var url = "/api/" + OSM.API_VERSION + "/" + object.type + "/" + object.id;
28 if (object.type === "way" || object.type === "relation") {
30 } else if (object.version) {
31 url += "/" + object.version;
37 params: function(search) {
40 search = (search || window.location.search).replace('?', '').split(/&|;/);
42 for (var i = 0; i < search.length; ++i) {
44 j = pair.indexOf('='),
45 key = pair.slice(0, j),
46 val = pair.slice(++j);
47 params[key] = decodeURIComponent(val);
53 mapParams: function (search) {
54 var params = OSM.params(search), mapParams = {}, loc, match;
56 if (params.mlon && params.mlat) {
57 mapParams.marker = true;
58 mapParams.mlon = parseFloat(params.mlon);
59 mapParams.mlat = parseFloat(params.mlat);
62 // Old-style object parameters; still in use for edit links e.g. /edit?way=1234
64 mapParams.object = {type: 'node', id: parseInt(params.node)};
65 } else if (params.way) {
66 mapParams.object = {type: 'way', id: parseInt(params.way)};
67 } else if (params.relation) {
68 mapParams.object = {type: 'relation', id: parseInt(params.relation)};
71 var hash = OSM.parseHash(location.hash);
73 // Decide on a map starting position. Various ways of doing this.
75 mapParams.lon = hash.center.lng;
76 mapParams.lat = hash.center.lat;
77 mapParams.zoom = hash.zoom;
78 } else if (params.bbox) {
79 var bbox = params.bbox.split(',');
80 mapParams.bounds = L.latLngBounds(
81 [parseFloat(bbox[1]), parseFloat(bbox[0])],
82 [parseFloat(bbox[3]), parseFloat(bbox[2])]);
83 } else if (params.minlon && params.minlat && params.maxlon && params.maxlat) {
84 mapParams.bounds = L.latLngBounds(
85 [parseFloat(params.minlat), parseFloat(params.minlon)],
86 [parseFloat(params.maxlat), parseFloat(params.maxlon)]);
87 } else if (params.mlon && params.mlat) {
88 mapParams.lon = parseFloat(params.mlon);
89 mapParams.lat = parseFloat(params.mlat);
90 mapParams.zoom = parseInt(params.zoom || 12);
91 } else if (loc = $.cookie('_osm_location')) {
93 mapParams.lon = parseFloat(loc[0]);
94 mapParams.lat = parseFloat(loc[1]);
95 mapParams.zoom = parseInt(loc[2]);
96 } else if (OSM.home) {
97 mapParams.lon = OSM.home.lon;
98 mapParams.lat = OSM.home.lat;
100 } else if (OSM.location) {
101 mapParams.bounds = L.latLngBounds(
102 [OSM.location.minlat,
103 OSM.location.minlon],
104 [OSM.location.maxlat,
105 OSM.location.maxlon]);
107 mapParams.lon = -0.1;
108 mapParams.lat = 51.5;
109 mapParams.zoom = parseInt(params.zoom || 5);
112 mapParams.layers = hash.layers || (loc && loc[3]) || '';
114 var scale = parseFloat(params.scale);
116 mapParams.zoom = Math.log(360.0 / (scale * 512.0)) / Math.log(2.0);
122 parseHash: function(hash) {
125 var i = hash.indexOf('#');
130 hash = querystring.parse(hash.substr(i + 1));
132 var map = (hash.map || '').split('/'),
133 zoom = parseInt(map[0], 10),
134 lat = parseFloat(map[1]),
135 lon = parseFloat(map[2]);
137 if (!isNaN(zoom) && !isNaN(lat) && !isNaN(lon)) {
138 args.center = new L.LatLng(lat, lon);
143 args.layers = hash.layers;
149 formatHash: function(args) {
150 var center, zoom, layers;
152 if (args instanceof L.Map) {
153 center = args.getCenter();
154 zoom = args.getZoom();
155 layers = args.getLayersCode();
157 center = args.center || L.latLng(args.lat, args.lon);
159 layers = args.layers || '';
162 center = center.wrap();
163 layers = layers.replace('M', '');
165 var precision = OSM.zoomPrecision(zoom),
166 hash = '#map=' + zoom +
167 '/' + center.lat.toFixed(precision) +
168 '/' + center.lng.toFixed(precision);
171 hash += '&layers=' + layers;
177 zoomPrecision: function(zoom) {
178 return Math.max(0, Math.ceil(Math.log(zoom) / Math.LN2));
181 locationCookie: function(map) {
182 var center = map.getCenter().wrap(),
183 zoom = map.getZoom(),
184 precision = OSM.zoomPrecision(zoom);
185 return [center.lng.toFixed(precision), center.lat.toFixed(precision), zoom, map.getLayersCode()].join('|');
188 distance: function(latlng1, latlng2) {
189 var lat1 = latlng1.lat * Math.PI / 180,
190 lng1 = latlng1.lng * Math.PI / 180,
191 lat2 = latlng2.lat * Math.PI / 180,
192 lng2 = latlng2.lng * Math.PI / 180,
193 latdiff = lat2 - lat1,
194 lngdiff = lng2 - lng1;
196 return 6372795 * 2 * Math.asin(
198 Math.pow(Math.sin(latdiff / 2), 2) +
199 Math.cos(lat1) * Math.cos(lat2) * Math.pow(Math.sin(lngdiff / 2), 2)