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 params: function(search) {
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);
41 mapParams: function (search) {
42 var params = OSM.params(search), mapParams = {}, bounds, loc;
44 if (params.mlon && params.mlat) {
45 mapParams.marker = true;
46 mapParams.mlon = parseFloat(params.mlon);
47 mapParams.mlat = parseFloat(params.mlat);
50 if (params.node || params.way || params.relation) {
51 mapParams.object_zoom = true;
54 mapParams.object = {type: 'node', id: parseInt(params.node)};
55 } else if (params.way) {
56 mapParams.object = {type: 'way', id: parseInt(params.way)};
57 } else if (params.relation) {
58 mapParams.object = {type: 'relation', id: parseInt(params.relation)};
63 params.bbox = params.bbox.split(',');
64 bounds = L.latLngBounds(
65 [parseFloat(params.bbox[1]),
66 parseFloat(params.bbox[0])],
67 [parseFloat(params.bbox[3]),
68 parseFloat(params.bbox[2])]);
69 } else if (params.minlon && params.minlat && params.maxlon && params.maxlat) {
70 bounds = L.latLngBounds(
71 [parseFloat(params.minlat),
72 parseFloat(params.minlon)],
73 [parseFloat(params.maxlat),
74 parseFloat(params.maxlon)]);
77 if (params.box === 'yes') {
78 mapParams.box = bounds;
81 var hash = OSM.parseHash(location.hash);
83 // Decide on a map starting position. Various ways of doing this.
85 mapParams.lon = hash.center.lng;
86 mapParams.lat = hash.center.lat;
87 mapParams.zoom = hash.zoom;
88 mapParams.object_zoom = false;
90 mapParams.lon = bounds.getCenter().lng; // Not used by main map, but
91 mapParams.lat = bounds.getCenter().lat; // are used by iD/Potlatch.
92 mapParams.bounds = bounds;
93 mapParams.object_zoom = false;
94 } else if (params.lon && params.lat) {
95 mapParams.lon = parseFloat(params.lon);
96 mapParams.lat = parseFloat(params.lat);
97 mapParams.zoom = parseInt(params.zoom || 5);
98 mapParams.object_zoom = false;
99 } else if (params.mlon && params.mlat) {
100 mapParams.lon = parseFloat(params.mlon);
101 mapParams.lat = parseFloat(params.mlat);
102 mapParams.zoom = parseInt(params.zoom || 12);
103 mapParams.object_zoom = false;
104 } else if (loc = $.cookie('_osm_location')) {
105 loc = loc.split("|");
106 mapParams.lon = parseFloat(loc[0]);
107 mapParams.lat = parseFloat(loc[1]);
108 mapParams.zoom = parseInt(loc[2]);
109 } else if (OSM.home) {
110 mapParams.lon = OSM.home.lon;
111 mapParams.lat = OSM.home.lat;
113 } else if (OSM.location) {
114 mapParams.bounds = L.latLngBounds(
115 [OSM.location.minlat,
116 OSM.location.minlon],
117 [OSM.location.maxlat,
118 OSM.location.maxlon]);
120 mapParams.lon = -0.1;
121 mapParams.lat = 51.5;
122 mapParams.zoom = parseInt(params.zoom || 5);
125 mapParams.layers = hash.layers || (loc && loc[3]) || '';
128 mapParams.note = parseInt(params.note);
131 var scale = parseFloat(params.scale);
133 mapParams.zoom = Math.log(360.0 / (scale * 512.0)) / Math.log(2.0);
139 parseHash: function(hash) {
140 if (hash.indexOf('#') === 0) {
141 hash = hash.substr(1);
143 hash = querystring.parse(hash);
144 var args = L.Hash.parseHash(hash.map || '') || {};
145 if (hash.layers) 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 = L.latLng(args.lat, args.lon);
159 layers = args.layers || '';
162 center = center.wrap();
163 layers = layers.replace('M', '');
165 var precision = zoomPrecision(zoom),
166 hash = '#map=' + zoom +
167 '/' + center.lat.toFixed(precision) +
168 '/' + center.lng.toFixed(precision);
171 hash += '&layers=' + layers;