2 <% if defined?(PIWIK_LOCATION) and defined?(PIWIK_SITE) %>
3 PIWIK_LOCATION: <%= PIWIK_LOCATION.to_json %>,
4 PIWIK_SITE: <%= PIWIK_SITE.to_json %>,
7 MAX_REQUEST_AREA: <%= MAX_REQUEST_AREA.to_json %>,
8 SERVER_URL: <%= SERVER_URL.to_json %>,
9 API_VERSION: <%= API_VERSION.to_json %>,
10 STATUS: <%= STATUS.to_json %>,
11 MAX_NOTE_REQUEST_AREA: <%= MAX_NOTE_REQUEST_AREA.to_json %>,
13 apiUrl: function (object) {
14 var url = "/api/" + OSM.API_VERSION + "/" + object.type + "/" + object.id;
16 if (object.type != "node") {
18 } else if (object.version) {
19 url += "/" + object.version;
25 mapParams: function (search) {
26 var params = {}, mapParams = {}, bounds, loc;
28 search = (search || window.location.search).replace('?', '').split(/&|;/);
30 for (var i = 0; i < search.length; ++i) {
32 j = pair.indexOf('='),
33 key = pair.slice(0, j),
34 val = pair.slice(++j);
35 params[key] = decodeURIComponent(val);
38 if (params.mlon && params.mlat) {
39 mapParams.marker = true;
40 mapParams.mlon = parseFloat(params.mlon);
41 mapParams.mlat = parseFloat(params.mlat);
44 if (params.node || params.way || params.relation) {
45 mapParams.object_zoom = true;
48 mapParams.object = {type: 'node', id: parseInt(params.node)};
49 } else if (params.way) {
50 mapParams.object = {type: 'way', id: parseInt(params.way)};
51 } else if (params.relation) {
52 mapParams.object = {type: 'relation', id: parseInt(params.relation)};
57 params.bbox = params.bbox.split(',');
58 bounds = L.latLngBounds(
59 [parseFloat(params.bbox[1]),
60 parseFloat(params.bbox[0])],
61 [parseFloat(params.bbox[3]),
62 parseFloat(params.bbox[2])]);
63 } else if (params.minlon && params.minlat && params.maxlon && params.maxlat) {
64 bounds = L.latLngBounds(
65 [parseFloat(params.minlat),
66 parseFloat(params.minlon)],
67 [parseFloat(params.maxlat),
68 parseFloat(params.maxlon)]);
71 if (params.box === 'yes') {
72 mapParams.box = bounds;
75 var hash = OSM.parseHash(location.hash);
77 // Decide on a map starting position. Various ways of doing this.
79 mapParams.lon = hash.center.lng;
80 mapParams.lat = hash.center.lat;
81 mapParams.zoom = hash.zoom;
82 mapParams.object_zoom = false;
84 mapParams.bounds = bounds;
85 mapParams.object_zoom = false;
86 } else if (params.lon && params.lat) {
87 mapParams.lon = parseFloat(params.lon);
88 mapParams.lat = parseFloat(params.lat);
89 mapParams.zoom = parseInt(params.zoom || 5);
90 mapParams.object_zoom = false;
91 } else if (params.mlon && params.mlat) {
92 mapParams.lon = parseFloat(params.mlon);
93 mapParams.lat = parseFloat(params.mlat);
94 mapParams.zoom = parseInt(params.zoom || 12);
95 mapParams.object_zoom = false;
96 } else if (loc = $.cookie('_osm_location')) {
98 mapParams.lon = parseFloat(loc[0]);
99 mapParams.lat = parseFloat(loc[1]);
100 mapParams.zoom = parseInt(loc[2]);
101 } else if (OSM.home) {
102 mapParams.lon = OSM.home.lon;
103 mapParams.lat = OSM.home.lat;
105 } else if (OSM.location) {
106 mapParams.bounds = L.latLngBounds(
107 [OSM.location.minlat,
108 OSM.location.minlon],
109 [OSM.location.maxlat,
110 OSM.location.maxlon]);
112 mapParams.lon = -0.1;
113 mapParams.lat = 51.5;
114 mapParams.zoom = parseInt(params.zoom || 5);
117 mapParams.layers = hash.layers || (loc && loc[3]) || '';
120 mapParams.note = parseInt(params.note);
123 var scale = parseFloat(params.scale);
125 mapParams.zoom = Math.log(360.0 / (scale * 512.0)) / Math.log(2.0);
131 parseHash: function(hash) {
132 if (hash.indexOf('#') === 0) {
133 hash = hash.substr(1);
135 hash = querystring.parse(hash);
136 var args = L.Hash.parseHash(hash.map || '') || {};
137 if (hash.layers) args.layers = hash.layers;
141 formatHash: function(args) {
142 if (args instanceof L.Map) {
144 lat: args.getCenter().lat,
145 lon: args.getCenter().lng,
146 zoom: args.getZoom(),
147 layers: args.getLayersCode()
151 var precision = zoomPrecision(args.zoom),
152 hash = '#map=' + args.zoom +
153 '/' + args.lat.toFixed(precision) +
154 '/' + args.lon.toFixed(precision);
157 args.layers = args.layers.replace('M', '');
161 hash += '&layers=' + args.layers;