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 === "way" || object.type === "relation") {
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 = {}, loc, match;
43 if (params.mlon && params.mlat) {
44 mapParams.marker = true;
45 mapParams.mlon = parseFloat(params.mlon);
46 mapParams.mlat = parseFloat(params.mlat);
49 // Old-style object parameters; still in use for edit links e.g. /edit?way=1234
51 mapParams.object = {type: 'node', id: parseInt(params.node)};
52 } else if (params.way) {
53 mapParams.object = {type: 'way', id: parseInt(params.way)};
54 } else if (params.relation) {
55 mapParams.object = {type: 'relation', id: parseInt(params.relation)};
58 var hash = OSM.parseHash(location.hash);
60 // Decide on a map starting position. Various ways of doing this.
62 mapParams.lon = hash.center.lng;
63 mapParams.lat = hash.center.lat;
64 mapParams.zoom = hash.zoom;
65 } else if (params.bbox) {
66 var bbox = params.bbox.split(',');
67 mapParams.bounds = L.latLngBounds(
68 [parseFloat(bbox[1]), parseFloat(bbox[0])],
69 [parseFloat(bbox[3]), parseFloat(bbox[2])]);
70 } else if (params.minlon && params.minlat && params.maxlon && params.maxlat) {
71 mapParams.bounds = L.latLngBounds(
72 [parseFloat(params.minlat), parseFloat(params.minlon)],
73 [parseFloat(params.maxlat), parseFloat(params.maxlon)]);
74 } else if (params.lon && params.lat) {
75 mapParams.lon = parseFloat(params.lon);
76 mapParams.lat = parseFloat(params.lat);
77 mapParams.zoom = parseInt(params.zoom || 5);
78 } else if (params.mlon && params.mlat) {
79 mapParams.lon = parseFloat(params.mlon);
80 mapParams.lat = parseFloat(params.mlat);
81 mapParams.zoom = parseInt(params.zoom || 12);
82 } else if (loc = $.cookie('_osm_location')) {
84 mapParams.lon = parseFloat(loc[0]);
85 mapParams.lat = parseFloat(loc[1]);
86 mapParams.zoom = parseInt(loc[2]);
87 } else if (OSM.home) {
88 mapParams.lon = OSM.home.lon;
89 mapParams.lat = OSM.home.lat;
91 } else if (OSM.location) {
92 mapParams.bounds = L.latLngBounds(
96 OSM.location.maxlon]);
100 mapParams.zoom = parseInt(params.zoom || 5);
103 mapParams.layers = hash.layers || (loc && loc[3]) || '';
105 var scale = parseFloat(params.scale);
107 mapParams.zoom = Math.log(360.0 / (scale * 512.0)) / Math.log(2.0);
113 parseHash: function(hash) {
114 var i = hash.indexOf('#');
119 hash = hash.substr(i + 1);
125 hash = querystring.parse(hash);
127 if (hash.map === undefined) {
131 var args = hash.map.split("/");
132 if (args.length !== 3) {
136 var zoom = parseInt(args[0], 10),
137 lat = parseFloat(args[1]),
138 lon = parseFloat(args[2]);
140 if (isNaN(zoom) || isNaN(lat) || isNaN(lon)) {
145 center: new L.LatLng(lat, lon),
150 args.layers = hash.layers;
156 formatHash: function(args) {
157 var center, zoom, layers;
159 if (args instanceof L.Map) {
160 center = args.getCenter();
161 zoom = args.getZoom();
162 layers = args.getLayersCode();
164 center = args.center || L.latLng(args.lat, args.lon);
166 layers = args.layers || '';
169 center = center.wrap();
170 layers = layers.replace('M', '');
172 var precision = zoomPrecision(zoom),
173 hash = '#map=' + zoom +
174 '/' + center.lat.toFixed(precision) +
175 '/' + center.lng.toFixed(precision);
178 hash += '&layers=' + layers;