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 match = window.location.pathname.match(/\/browse\/(node|way|relation|changeset)\/(\d+)/);
51 mapParams.object_zoom = true;
52 mapParams.object = {type: match[1], id: parseInt(match[2])};
53 } else if (params.node || params.way || params.relation || params.note) {
54 mapParams.object_zoom = true;
57 mapParams.object = {type: 'node', id: parseInt(params.node)};
58 } else if (params.way) {
59 mapParams.object = {type: 'way', id: parseInt(params.way)};
60 } else if (params.relation) {
61 mapParams.object = {type: 'relation', id: parseInt(params.relation)};
65 match = window.location.pathname.match(/\/browse\/note\/(\d+)/);
67 mapParams.note = parseInt(match[1]);
68 } else if (params.note) {
69 mapParams.note = parseInt(params.note);
72 var hash = OSM.parseHash(location.hash);
74 // Decide on a map starting position. Various ways of doing this.
76 mapParams.lon = hash.center.lng;
77 mapParams.lat = hash.center.lat;
78 mapParams.zoom = hash.zoom;
79 mapParams.object_zoom = false;
80 } else if (params.lon && params.lat) {
81 mapParams.lon = parseFloat(params.lon);
82 mapParams.lat = parseFloat(params.lat);
83 mapParams.zoom = parseInt(params.zoom || 5);
84 mapParams.object_zoom = false;
85 } else if (params.mlon && params.mlat) {
86 mapParams.lon = parseFloat(params.mlon);
87 mapParams.lat = parseFloat(params.mlat);
88 mapParams.zoom = parseInt(params.zoom || 12);
89 mapParams.object_zoom = false;
90 } else if (loc = $.cookie('_osm_location')) {
92 mapParams.lon = parseFloat(loc[0]);
93 mapParams.lat = parseFloat(loc[1]);
94 mapParams.zoom = parseInt(loc[2]);
95 } else if (OSM.home) {
96 mapParams.lon = OSM.home.lon;
97 mapParams.lat = OSM.home.lat;
99 } else if (OSM.location) {
100 mapParams.bounds = L.latLngBounds(
101 [OSM.location.minlat,
102 OSM.location.minlon],
103 [OSM.location.maxlat,
104 OSM.location.maxlon]);
106 mapParams.lon = -0.1;
107 mapParams.lat = 51.5;
108 mapParams.zoom = parseInt(params.zoom || 5);
111 mapParams.layers = hash.layers || (loc && loc[3]) || '';
113 var scale = parseFloat(params.scale);
115 mapParams.zoom = Math.log(360.0 / (scale * 512.0)) / Math.log(2.0);
121 parseHash: function(hash) {
122 if (hash.indexOf('#') === 0) {
123 hash = hash.substr(1);
125 hash = querystring.parse(hash);
126 var args = L.Hash.parseHash(hash.map || '') || {};
127 if (hash.layers) args.layers = hash.layers;
131 formatHash: function(args) {
132 var center, zoom, layers;
134 if (args instanceof L.Map) {
135 center = args.getCenter();
136 zoom = args.getZoom();
137 layers = args.getLayersCode();
139 center = L.latLng(args.lat, args.lon);
141 layers = args.layers || '';
144 center = center.wrap();
145 layers = layers.replace('M', '');
147 var precision = zoomPrecision(zoom),
148 hash = '#map=' + zoom +
149 '/' + center.lat.toFixed(precision) +
150 '/' + center.lng.toFixed(precision);
153 hash += '&layers=' + layers;