]> git.openstreetmap.org Git - rails.git/blob - app/assets/javascripts/embed.js.erb
Use correct URL for problem report control
[rails.git] / app / assets / javascripts / embed.js.erb
1 //= require leaflet
2 //= require leaflet.osm
3
4 window.onload = function () {
5   var query = (window.location.search || '?').substr(1),
6       args  = {};
7
8   var pairs = query.split('&');
9   for (var i = 0; i < pairs.length; i++) {
10     var parts = pairs[i].split('=');
11     args[parts[0]] = decodeURIComponent(parts[1] || '');
12   }
13
14   var map = L.map("map");
15   map.attributionControl.setPrefix('');
16   map.removeControl(map.attributionControl);
17
18   if (!args.layer || args.layer === "mapnik" || args.layer === "osmarender") {
19     new L.OSM.Mapnik().addTo(map);
20   } else if (args.layer === "cyclemap" || args.layer === "cycle map") {
21     new L.OSM.CycleMap().addTo(map);
22   } else if (args.layer === "transportmap") {
23     new L.OSM.TransportMap().addTo(map);
24   } else if (args.layer === "mapquest") {
25     new L.OSM.MapQuestOpen().addTo(map);
26   } else if (args.layer === "hot") {
27     new L.OSM.HOT().addTo(map);
28   }
29
30   if (args.marker) {
31     L.marker(args.marker.split(','), {icon: L.icon({
32       iconUrl: <%= asset_path('images/marker-icon.png').to_json %>,
33       iconSize: new L.Point(25, 41),
34       iconAnchor: new L.Point(12, 41),
35       shadowUrl: <%= asset_path('images/marker-shadow.png').to_json %>,
36       shadowSize: new L.Point(41, 41)
37     })}).addTo(map);
38   }
39
40   if (args.bbox) {
41     var bbox = args.bbox.split(',');
42     map.fitBounds([L.latLng(bbox[1], bbox[0]),
43                    L.latLng(bbox[3], bbox[2])]);
44   } else {
45     map.fitWorld();
46   }
47
48   map.addControl(new L.Control.OSMReportAProblem());
49 };
50
51 L.Control.OSMReportAProblem = L.Control.Attribution.extend({
52   options: {
53     position: 'bottomright',
54     prefix: '<a href="http://www.openstreetmap.org/fixthemap?lat={x}&lon={y}&zoom={z}">Report a problem</a>'
55   },
56
57   onAdd: function (map) {
58     var container = L.Control.Attribution.prototype.onAdd.call(this, map);
59
60     map.on('moveend', this._update, this);
61
62     return container;
63   },
64
65   _update: function () {
66     L.Control.Attribution.prototype._update.call(this);
67
68     this._container.innerHTML =
69       this._container.innerHTML
70         .replace('{x}', this._map.getCenter().lat)
71         .replace('{y}', this._map.getCenter().lng)
72         .replace('{z}', this._map.getZoom());
73   }
74 });