]> git.openstreetmap.org Git - rails.git/blobdiff - app/assets/javascripts/embed.js.erb
Use correct URL for problem report control
[rails.git] / app / assets / javascripts / embed.js.erb
index eec4b080e3e7192559c34072187afb6a3c44aaa6..ca5594459101720b3e95d297c40411e9a21ba1b8 100644 (file)
@@ -13,6 +13,7 @@ window.onload = function () {
 
   var map = L.map("map");
   map.attributionControl.setPrefix('');
+  map.removeControl(map.attributionControl);
 
   if (!args.layer || args.layer === "mapnik" || args.layer === "osmarender") {
     new L.OSM.Mapnik().addTo(map);
@@ -43,4 +44,31 @@ window.onload = function () {
   } else {
     map.fitWorld();
   }
+
+  map.addControl(new L.Control.OSMReportAProblem());
 };
+
+L.Control.OSMReportAProblem = L.Control.Attribution.extend({
+  options: {
+    position: 'bottomright',
+    prefix: '<a href="http://www.openstreetmap.org/fixthemap?lat={x}&lon={y}&zoom={z}">Report a problem</a>'
+  },
+
+  onAdd: function (map) {
+    var container = L.Control.Attribution.prototype.onAdd.call(this, map);
+
+    map.on('moveend', this._update, this);
+
+    return container;
+  },
+
+  _update: function () {
+    L.Control.Attribution.prototype._update.call(this);
+
+    this._container.innerHTML =
+      this._container.innerHTML
+        .replace('{x}', this._map.getCenter().lat)
+        .replace('{y}', this._map.getCenter().lng)
+        .replace('{z}', this._map.getZoom());
+  }
+});