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 %>,
12 apiUrl: function (object) {
13 var url = "/api/" + OSM.API_VERSION + "/" + object.type + "/" + object.id;
15 if (object.type != "node") {
17 } else if (object.version) {
18 url += "/" + object.version;
24 params: function(search) {
27 search = (search || window.location.search).replace('?', '').split(/&|;/);
29 for (var i = 0; i < search.length; ++i) {
31 j = pair.indexOf('='),
32 key = pair.slice(0, j),
33 val = pair.slice(++j);
34 params[key] = decodeURIComponent(val);
40 mapParams: function (search) {
41 var params = OSM.params(search), mapParams = {}, bounds, loc;
43 if (params.mlon && params.mlat) {
44 mapParams.marker = true;
45 mapParams.mlon = parseFloat(params.mlon);
46 mapParams.mlat = parseFloat(params.mlat);
49 if (params.node || params.way || params.relation) {
50 mapParams.object_zoom = true;
53 mapParams.object = {type: 'node', id: parseInt(params.node)};
54 } else if (params.way) {
55 mapParams.object = {type: 'way', id: parseInt(params.way)};
56 } else if (params.relation) {
57 mapParams.object = {type: 'relation', id: parseInt(params.relation)};
62 params.bbox = params.bbox.split(',');
63 bounds = L.latLngBounds(
64 [parseFloat(params.bbox[1]),
65 parseFloat(params.bbox[0])],
66 [parseFloat(params.bbox[3]),
67 parseFloat(params.bbox[2])]);
68 } else if (params.minlon && params.minlat && params.maxlon && params.maxlat) {
69 bounds = L.latLngBounds(
70 [parseFloat(params.minlat),
71 parseFloat(params.minlon)],
72 [parseFloat(params.maxlat),
73 parseFloat(params.maxlon)]);
76 if (params.box === 'yes') {
77 mapParams.box = bounds;
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 mapParams.object_zoom = false;
89 mapParams.lon = bounds.getCenter().lng; // Not used by main map, but
90 mapParams.lat = bounds.getCenter().lat; // are used by iD/Potlatch.
91 mapParams.bounds = bounds;
92 mapParams.object_zoom = false;
93 } else if (params.lon && params.lat) {
94 mapParams.lon = parseFloat(params.lon);
95 mapParams.lat = parseFloat(params.lat);
96 mapParams.zoom = parseInt(params.zoom || 5);
97 mapParams.object_zoom = false;
98 } else if (params.mlon && params.mlat) {
99 mapParams.lon = parseFloat(params.mlon);
100 mapParams.lat = parseFloat(params.mlat);
101 mapParams.zoom = parseInt(params.zoom || 12);
102 mapParams.object_zoom = false;
103 } else if (loc = $.cookie('_osm_location')) {
104 loc = loc.split("|");
105 mapParams.lon = parseFloat(loc[0]);
106 mapParams.lat = parseFloat(loc[1]);
107 mapParams.zoom = parseInt(loc[2]);
108 } else if (OSM.home) {
109 mapParams.lon = OSM.home.lon;
110 mapParams.lat = OSM.home.lat;
112 } else if (OSM.location) {
113 mapParams.bounds = L.latLngBounds(
114 [OSM.location.minlat,
115 OSM.location.minlon],
116 [OSM.location.maxlat,
117 OSM.location.maxlon]);
119 mapParams.lon = -0.1;
120 mapParams.lat = 51.5;
121 mapParams.zoom = parseInt(params.zoom || 5);
124 mapParams.layers = hash.layers || (loc && loc[3]) || '';
127 mapParams.note = parseInt(params.note);
130 var scale = parseFloat(params.scale);
132 mapParams.zoom = Math.log(360.0 / (scale * 512.0)) / Math.log(2.0);
138 parseHash: function(hash) {
139 if (hash.indexOf('#') === 0) {
140 hash = hash.substr(1);
142 hash = querystring.parse(hash);
143 var args = L.Hash.parseHash(hash.map || '') || {};
144 if (hash.layers) args.layers = hash.layers;
148 formatHash: function(args) {
149 var center, zoom, layers;
151 if (args instanceof L.Map) {
152 center = args.getCenter();
153 zoom = args.getZoom();
154 layers = args.getLayersCode();
156 center = L.latLng(args.lat, args.lon);
158 layers = args.layers || '';
161 center = center.wrap();
162 layers = layers.replace('M', '');
164 var precision = zoomPrecision(zoom),
165 hash = '#map=' + zoom +
166 '/' + center.lat.toFixed(precision) +
167 '/' + center.lng.toFixed(precision);
170 hash += '&layers=' + layers;