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 var i = hash.indexOf('#');
109 hash = hash.substr(i + 1);
115 hash = querystring.parse(hash);
117 var args = hash.map.split("/");
118 if (args.length !== 3) {
122 var zoom = parseInt(args[0], 10),
123 lat = parseFloat(args[1]),
124 lon = parseFloat(args[2]);
126 if (isNaN(zoom) || isNaN(lat) || isNaN(lon)) {
131 center: new L.LatLng(lat, lon),
136 args.layers = hash.layers;
142 formatHash: function(args) {
143 var center, zoom, layers;
145 if (args instanceof L.Map) {
146 center = args.getCenter();
147 zoom = args.getZoom();
148 layers = args.getLayersCode();
150 center = args.center || L.latLng(args.lat, args.lon);
152 layers = args.layers || '';
155 center = center.wrap();
156 layers = layers.replace('M', '');
158 var precision = zoomPrecision(zoom),
159 hash = '#map=' + zoom +
160 '/' + center.lat.toFixed(precision) +
161 '/' + center.lng.toFixed(precision);
164 hash += '&layers=' + layers;