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) {
116 var i = hash.indexOf('#');
121 hash = querystring.parse(hash.substr(i + 1));
123 var map = (hash.map || '').split('/'),
124 zoom = parseInt(map[0], 10),
125 lat = parseFloat(map[1]),
126 lon = parseFloat(map[2]);
128 if (!isNaN(zoom) && !isNaN(lat) && !isNaN(lon)) {
129 args.center = new L.LatLng(lat, lon);
134 args.layers = hash.layers;
140 formatHash: function(args) {
141 var center, zoom, layers;
143 if (args instanceof L.Map) {
144 center = args.getCenter();
145 zoom = args.getZoom();
146 layers = args.getLayersCode();
148 center = args.center || L.latLng(args.lat, args.lon);
150 layers = args.layers || '';
153 center = center.wrap();
154 layers = layers.replace('M', '');
156 var precision = zoomPrecision(zoom),
157 hash = '#map=' + zoom +
158 '/' + center.lat.toFixed(precision) +
159 '/' + center.lng.toFixed(precision);
162 hash += '&layers=' + layers;