]> git.openstreetmap.org Git - rails.git/blobdiff - app/assets/javascripts/leaflet.extend.js.erb
Add about page
[rails.git] / app / assets / javascripts / leaflet.extend.js.erb
index a645ed253b7149ee04cfa58aa7c4806be62c58cb..cec25081b8b463b617c9f11638fa3e7e6ad74150 100644 (file)
@@ -33,8 +33,9 @@ L.extend(L.Map.prototype, {
         params = {};
 
     if (marker && this.hasLayer(marker)) {
-      params.mlat = marker.getLatLng().lat.toFixed(precision);
-      params.mlon = marker.getLatLng().lng.toFixed(precision);
+      var latLng = marker.getLatLng().wrap();
+      params.mlat = latLng.lat.toFixed(precision);
+      params.mlon = latLng.lng.toFixed(precision);
     }
 
     if (this._object) {
@@ -53,7 +54,7 @@ L.extend(L.Map.prototype, {
 
   getShortUrl: function(marker) {
     var zoom = this.getZoom(),
-      latLng = marker && this.hasLayer(marker) ? marker.getLatLng() : this.getCenter(),
+      latLng = marker && this.hasLayer(marker) ? marker.getLatLng().wrap() : this.getCenter().wrap(),
       str = window.location.hostname.match(/^www\.openstreetmap\.org/i) ?
         'http://osm.org/go/' : 'http://' + window.location.hostname + '/go/',
       char_array = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789_~",
@@ -121,7 +122,12 @@ L.extend(L.Map.prototype, {
           styles: {
             node: options.style,
             way: options.style,
-            area: options.style
+            area: options.style,
+            changeset: {
+              weight: 2,
+              color: '#e90',
+              fillOpacity: 0
+            }
           }
         });
 
@@ -139,16 +145,40 @@ L.extend(L.Map.prototype, {
 
         map._objectLayer.addData(xml);
 
-        if (options.zoom) map.fitBounds(map._objectLayer.getBounds());
-        if (options.callback) options.callback(map._objectLayer.getBounds());
+        var bounds = map._objectLayer.getBounds();
+
+        if (options.zoom && bounds.isValid()) map.fitBounds(bounds);
+        if (options.callback) options.callback(bounds);
 
         map._objectLayer.addTo(map);
       }
     });
+  },
+
+  removeObject: function() {
+    this._object = null;
+    if (this._objectLoader) this._objectLoader.abort();
+    if (this._objectLayer) this.removeLayer(this._objectLayer);
   }
 });
 
-L.Icon.Default.imagePath = <%= "#{asset_prefix}/images".to_json %>;
+L.Icon.Default.imagePath = "/images";
+
+L.Icon.Default.imageUrls = {
+  "/images/marker-icon.png": "<%= asset_path("images/marker-icon.png") %>",
+  "/images/marker-icon-2x.png": "<%= asset_path("images/marker-icon-2x.png") %>",
+  "/images/marker-shadow.png": "<%= asset_path("images/marker-shadow.png") %>",
+  "/images/marker-shadow-2x.png": "<%= asset_path("images/marker-shadow-2x.png") %>"
+};
+
+L.extend(L.Icon.Default.prototype, {
+  _oldGetIconUrl: L.Icon.Default.prototype._getIconUrl,
+
+  _getIconUrl:  function (name) {
+    var url = this._oldGetIconUrl(name);
+    return L.Icon.Default.imageUrls[url];
+  }
+});
 
 L.Hash.prototype.parseHash = OSM.parseHash;
 L.Hash.prototype.formatHash = OSM.formatHash;