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.lon && params.lat) {
66 mapParams.lon = parseFloat(params.lon);
67 mapParams.lat = parseFloat(params.lat);
68 mapParams.zoom = parseInt(params.zoom || 5);
69 } else if (params.mlon && params.mlat) {
70 mapParams.lon = parseFloat(params.mlon);
71 mapParams.lat = parseFloat(params.mlat);
72 mapParams.zoom = parseInt(params.zoom || 12);
73 } else if (loc = $.cookie('_osm_location')) {
75 mapParams.lon = parseFloat(loc[0]);
76 mapParams.lat = parseFloat(loc[1]);
77 mapParams.zoom = parseInt(loc[2]);
78 } else if (OSM.home) {
79 mapParams.lon = OSM.home.lon;
80 mapParams.lat = OSM.home.lat;
82 } else if (OSM.location) {
83 mapParams.bounds = L.latLngBounds(
87 OSM.location.maxlon]);
91 mapParams.zoom = parseInt(params.zoom || 5);
94 mapParams.layers = hash.layers || (loc && loc[3]) || '';
96 var scale = parseFloat(params.scale);
98 mapParams.zoom = Math.log(360.0 / (scale * 512.0)) / Math.log(2.0);
104 parseHash: function(hash) {
105 var i = hash.indexOf('#');
110 hash = hash.substr(i + 1);
116 hash = querystring.parse(hash);
118 var args = hash.map.split("/");
119 if (args.length !== 3) {
123 var zoom = parseInt(args[0], 10),
124 lat = parseFloat(args[1]),
125 lon = parseFloat(args[2]);
127 if (isNaN(zoom) || isNaN(lat) || isNaN(lon)) {
132 center: new L.LatLng(lat, lon),
137 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 = args.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;