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);
56 params[key] = decodeURIComponent(val);
62 mapParams: function (search) {
63 var params = OSM.params(search), mapParams = {}, loc, match;
65 if (params.mlon && params.mlat) {
66 mapParams.marker = true;
67 mapParams.mlon = parseFloat(params.mlon);
68 mapParams.mlat = parseFloat(params.mlat);
71 // Old-style object parameters; still in use for edit links e.g. /edit?way=1234
73 mapParams.object = {type: 'node', id: parseInt(params.node)};
74 } else if (params.way) {
75 mapParams.object = {type: 'way', id: parseInt(params.way)};
76 } else if (params.relation) {
77 mapParams.object = {type: 'relation', id: parseInt(params.relation)};
80 var hash = OSM.parseHash(location.hash);
82 // Decide on a map starting position. Various ways of doing this.
84 mapParams.lon = hash.center.lng;
85 mapParams.lat = hash.center.lat;
86 mapParams.zoom = hash.zoom;
87 } else if (params.bbox) {
88 var bbox = params.bbox.split(',');
89 mapParams.bounds = L.latLngBounds(
90 [parseFloat(bbox[1]), parseFloat(bbox[0])],
91 [parseFloat(bbox[3]), parseFloat(bbox[2])]);
92 } else if (params.minlon && params.minlat && params.maxlon && params.maxlat) {
93 mapParams.bounds = L.latLngBounds(
94 [parseFloat(params.minlat), parseFloat(params.minlon)],
95 [parseFloat(params.maxlat), parseFloat(params.maxlon)]);
96 } else if (params.mlon && params.mlat) {
97 mapParams.lon = parseFloat(params.mlon);
98 mapParams.lat = parseFloat(params.mlat);
99 mapParams.zoom = parseInt(params.zoom || 12);
100 } else if (loc = $.cookie('_osm_location')) {
101 loc = loc.split("|");
102 mapParams.lon = parseFloat(loc[0]);
103 mapParams.lat = parseFloat(loc[1]);
104 mapParams.zoom = parseInt(loc[2]);
105 } else if (OSM.home) {
106 mapParams.lon = OSM.home.lon;
107 mapParams.lat = OSM.home.lat;
109 } else if (OSM.location) {
110 mapParams.bounds = L.latLngBounds(
111 [OSM.location.minlat,
112 OSM.location.minlon],
113 [OSM.location.maxlat,
114 OSM.location.maxlon]);
116 mapParams.lon = -0.1;
117 mapParams.lat = 51.5;
118 mapParams.zoom = parseInt(params.zoom || 5);
121 mapParams.layers = hash.layers || (loc && loc[3]) || '';
123 var scale = parseFloat(params.scale);
125 mapParams.zoom = Math.log(360.0 / (scale * 512.0)) / Math.log(2.0);
131 parseHash: function(hash) {
134 var i = hash.indexOf('#');
139 hash = querystring.parse(hash.substr(i + 1));
141 var map = (hash.map || '').split('/'),
142 zoom = parseInt(map[0], 10),
143 lat = parseFloat(map[1]),
144 lon = parseFloat(map[2]);
146 if (!isNaN(zoom) && !isNaN(lat) && !isNaN(lon)) {
147 args.center = new L.LatLng(lat, lon);
152 args.layers = hash.layers;
158 formatHash: function(args) {
159 var center, zoom, layers;
161 if (args instanceof L.Map) {
162 center = args.getCenter();
163 zoom = args.getZoom();
164 layers = args.getLayersCode();
166 center = args.center || L.latLng(args.lat, args.lon);
168 layers = args.layers || '';
171 center = center.wrap();
172 layers = layers.replace('M', '');
174 var precision = OSM.zoomPrecision(zoom),
175 hash = '#map=' + zoom +
176 '/' + center.lat.toFixed(precision) +
177 '/' + center.lng.toFixed(precision);
180 hash += '&layers=' + layers;
186 zoomPrecision: function(zoom) {
187 return Math.max(0, Math.ceil(Math.log(zoom) / Math.LN2));
190 locationCookie: function(map) {
191 var center = map.getCenter().wrap(),
192 zoom = map.getZoom(),
193 precision = OSM.zoomPrecision(zoom);
194 return [center.lng.toFixed(precision), center.lat.toFixed(precision), zoom, map.getLayersCode()].join('|');
197 distance: function(latlng1, latlng2) {
198 var lat1 = latlng1.lat * Math.PI / 180,
199 lng1 = latlng1.lng * Math.PI / 180,
200 lat2 = latlng2.lat * Math.PI / 180,
201 lng2 = latlng2.lng * Math.PI / 180,
202 latdiff = lat2 - lat1,
203 lngdiff = lng2 - lng1;
205 return 6372795 * 2 * Math.asin(
207 Math.pow(Math.sin(latdiff / 2), 2) +
208 Math.cos(lat1) * Math.cos(lat2) * Math.pow(Math.sin(lngdiff / 2), 2)