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 if (hash.map === undefined) {
122 var args = hash.map.split("/");
123 if (args.length !== 3) {
127 var zoom = parseInt(args[0], 10),
128 lat = parseFloat(args[1]),
129 lon = parseFloat(args[2]);
131 if (isNaN(zoom) || isNaN(lat) || isNaN(lon)) {
136 center: new L.LatLng(lat, lon),
141 args.layers = hash.layers;
147 formatHash: function(args) {
148 var center, zoom, layers;
150 if (args instanceof L.Map) {
151 center = args.getCenter();
152 zoom = args.getZoom();
153 layers = args.getLayersCode();
155 center = args.center || L.latLng(args.lat, args.lon);
157 layers = args.layers || '';
160 center = center.wrap();
161 layers = layers.replace('M', '');
163 var precision = zoomPrecision(zoom),
164 hash = '#map=' + zoom +
165 '/' + center.lat.toFixed(precision) +
166 '/' + center.lng.toFixed(precision);
169 hash += '&layers=' + layers;