2 <% if defined?(PIWIK_LOCATION) and defined?(PIWIK_SITE) %>
3 PIWIK_LOCATION: <%= PIWIK_LOCATION.to_json %>,
4 PIWIK_SITE: <%= PIWIK_SITE.to_json %>,
7 MAX_REQUEST_AREA: <%= MAX_REQUEST_AREA.to_json %>,
8 SERVER_URL: <%= SERVER_URL.to_json %>,
9 API_VERSION: <%= API_VERSION.to_json %>,
10 STATUS: <%= STATUS.to_json %>,
11 MAX_NOTE_REQUEST_AREA: <%= MAX_NOTE_REQUEST_AREA.to_json %>,
13 apiUrl: function (object) {
14 var url = "/api/" + OSM.API_VERSION + "/" + object.type + "/" + object.id;
16 if (object.type != "node") {
18 } else if (object.version) {
19 url += "/" + object.version;
25 mapParams: function (search) {
26 var params = {}, mapParams = {}, bounds, loc;
28 search = (search || window.location.search).replace('?', '').split(/&|;/);
30 for (var i = 0; i < search.length; ++i) {
32 j = pair.indexOf('='),
33 key = pair.slice(0, j),
34 val = pair.slice(++j);
35 params[key] = decodeURIComponent(val);
38 if (params.mlon && params.mlat) {
39 mapParams.marker = true;
40 mapParams.mlon = parseFloat(params.mlon);
41 mapParams.mlat = parseFloat(params.mlat);
44 if (params.node || params.way || params.relation) {
45 mapParams.object_zoom = true;
48 mapParams.object = {type: 'node', id: parseInt(params.node)};
49 } else if (params.way) {
50 mapParams.object = {type: 'way', id: parseInt(params.way)};
51 } else if (params.relation) {
52 mapParams.object = {type: 'relation', id: parseInt(params.relation)};
57 params.bbox = params.bbox.split(',');
58 bounds = L.latLngBounds(
59 [parseFloat(params.bbox[1]),
60 parseFloat(params.bbox[0])],
61 [parseFloat(params.bbox[3]),
62 parseFloat(params.bbox[2])]);
63 } else if (params.minlon && params.minlat && params.maxlon && params.maxlat) {
64 bounds = L.latLngBounds(
65 [parseFloat(params.minlat),
66 parseFloat(params.minlon)],
67 [parseFloat(params.maxlat),
68 parseFloat(params.maxlon)]);
71 if (params.box === 'yes') {
72 mapParams.box = bounds;
75 var hash = OSM.parseHash(location.hash);
77 // Decide on a map starting position. Various ways of doing this.
79 mapParams.lon = hash.center.lng;
80 mapParams.lat = hash.center.lat;
81 mapParams.zoom = hash.zoom;
82 mapParams.object_zoom = false;
84 mapParams.lon = bounds.getCenter().lng; // Not used by main map, but
85 mapParams.lat = bounds.getCenter().lat; // are used by iD/Potlatch.
86 mapParams.bounds = bounds;
87 mapParams.object_zoom = false;
88 } else if (params.lon && params.lat) {
89 mapParams.lon = parseFloat(params.lon);
90 mapParams.lat = parseFloat(params.lat);
91 mapParams.zoom = parseInt(params.zoom || 5);
92 mapParams.object_zoom = false;
93 } else if (params.mlon && params.mlat) {
94 mapParams.lon = parseFloat(params.mlon);
95 mapParams.lat = parseFloat(params.mlat);
96 mapParams.zoom = parseInt(params.zoom || 12);
97 mapParams.object_zoom = false;
98 } else if (loc = $.cookie('_osm_location')) {
100 mapParams.lon = parseFloat(loc[0]);
101 mapParams.lat = parseFloat(loc[1]);
102 mapParams.zoom = parseInt(loc[2]);
103 } else if (OSM.home) {
104 mapParams.lon = OSM.home.lon;
105 mapParams.lat = OSM.home.lat;
107 } else if (OSM.location) {
108 mapParams.bounds = L.latLngBounds(
109 [OSM.location.minlat,
110 OSM.location.minlon],
111 [OSM.location.maxlat,
112 OSM.location.maxlon]);
114 mapParams.lon = -0.1;
115 mapParams.lat = 51.5;
116 mapParams.zoom = parseInt(params.zoom || 5);
119 mapParams.layers = hash.layers || (loc && loc[3]) || '';
122 mapParams.note = parseInt(params.note);
125 var scale = parseFloat(params.scale);
127 mapParams.zoom = Math.log(360.0 / (scale * 512.0)) / Math.log(2.0);
133 parseHash: function(hash) {
134 if (hash.indexOf('#') === 0) {
135 hash = hash.substr(1);
137 hash = querystring.parse(hash);
138 var args = L.Hash.parseHash(hash.map || '') || {};
139 if (hash.layers) args.layers = hash.layers;
143 formatHash: function(args) {
144 var center, zoom, layers;
146 if (args instanceof L.Map) {
147 center = args.getCenter();
148 zoom = args.getZoom();
149 layers = args.getLayersCode();
151 center = L.latLng(args.lat, args.lon);
153 layers = args.layers || '';
156 center = center.wrap();
157 layers = layers.replace('M', '');
159 var precision = zoomPrecision(zoom),
160 hash = '#map=' + zoom +
161 '/' + center.lat.toFixed(precision) +
162 '/' + center.lng.toFixed(precision);
165 hash += '&layers=' + layers;