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);
50 mapParams.object = {type: 'node', id: parseInt(params.node)};
51 } else if (params.way) {
52 mapParams.object = {type: 'way', id: parseInt(params.way)};
53 } else if (params.relation) {
54 mapParams.object = {type: 'relation', id: parseInt(params.relation)};
57 var hash = OSM.parseHash(location.hash);
59 // Decide on a map starting position. Various ways of doing this.
61 mapParams.lon = hash.center.lng;
62 mapParams.lat = hash.center.lat;
63 mapParams.zoom = hash.zoom;
64 } else if (params.lon && params.lat) {
65 mapParams.lon = parseFloat(params.lon);
66 mapParams.lat = parseFloat(params.lat);
67 mapParams.zoom = parseInt(params.zoom || 5);
68 } else if (params.mlon && params.mlat) {
69 mapParams.lon = parseFloat(params.mlon);
70 mapParams.lat = parseFloat(params.mlat);
71 mapParams.zoom = parseInt(params.zoom || 12);
72 } else if (loc = $.cookie('_osm_location')) {
74 mapParams.lon = parseFloat(loc[0]);
75 mapParams.lat = parseFloat(loc[1]);
76 mapParams.zoom = parseInt(loc[2]);
77 } else if (OSM.home) {
78 mapParams.lon = OSM.home.lon;
79 mapParams.lat = OSM.home.lat;
81 } else if (OSM.location) {
82 mapParams.bounds = L.latLngBounds(
86 OSM.location.maxlon]);
90 mapParams.zoom = parseInt(params.zoom || 5);
93 mapParams.layers = hash.layers || (loc && loc[3]) || '';
95 var scale = parseFloat(params.scale);
97 mapParams.zoom = Math.log(360.0 / (scale * 512.0)) / Math.log(2.0);
103 parseHash: function(hash) {
104 if (hash.indexOf('#') === 0) {
105 hash = hash.substr(1);
107 hash = querystring.parse(hash);
108 var args = L.Hash.parseHash(hash.map || '') || {};
109 if (hash.layers) args.layers = hash.layers;
113 formatHash: function(args) {
114 var center, zoom, layers;
116 if (args instanceof L.Map) {
117 center = args.getCenter();
118 zoom = args.getZoom();
119 layers = args.getLayersCode();
121 center = L.latLng(args.lat, args.lon);
123 layers = args.layers || '';
126 center = center.wrap();
127 layers = layers.replace('M', '');
129 var precision = zoomPrecision(zoom),
130 hash = '#map=' + zoom +
131 '/' + center.lat.toFixed(precision) +
132 '/' + center.lng.toFixed(precision);
135 hash += '&layers=' + layers;