]> git.openstreetmap.org Git - rails.git/blobdiff - app/assets/javascripts/browse.js
Clean up some of the map JS, reduce scope of globals
[rails.git] / app / assets / javascripts / browse.js
index cde7c1276a76ad334bac9bc4414b6e3ec88854fd..0b60778d63493666ab4a63b8e7f493b06e735d91 100644 (file)
@@ -21,10 +21,16 @@ $(document).ready(function () {
     return false;
   }
 
-  var map = createMap("small_map", {
-    layerControl: false,
-    panZoomControl: false,
-    attributionControl: false
+  var map = L.map("small_map", {
+    attributionControl: false,
+    zoomControl: false
+  }).addLayer(new L.OSM.Mapnik());
+
+  L.control.zoom({position: 'topright'})
+    .addTo(map);
+
+  $("#small_map").on("resized", function () {
+    map.invalidateSize();
   });
 
   var params = $("#small_map").data();
@@ -33,7 +39,12 @@ $(document).ready(function () {
                               [params.maxlat, params.maxlon]);
 
     map.fitBounds(bbox);
-    addBoxToMap(bbox);
+
+    L.rectangle(bbox, {
+      weight: 2,
+      color: '#e90',
+      fillOpacity: 0
+    }).addTo(map);
 
     $("#loading").hide();
     $("#browse_map .geolink").show();
@@ -60,7 +71,7 @@ $(document).ready(function () {
       return remoteEditHandler(bbox);
     });
 
-    updatelinks(params.lon, params.lat, 16, null, 
+    updatelinks(params.lon, params.lat, 16, null,
                 bbox.getWest(), bbox.getSouth(),
                 bbox.getEast(), bbox.getNorth(),
                 object);
@@ -74,33 +85,36 @@ $(document).ready(function () {
       object.version = params.version - 1;
     }
 
-    addObjectToMap(object, true, function(extent) {
-      $("#loading").hide();
-      $("#browse_map .geolink").show();
-
-      if (extent) {
-        $("a.bbox[data-editor=remote]").click(function () {
-          return remoteEditHandler(extent);
-        });
-
-        $("a.object[data-editor=remote]").click(function () {
-          return remoteEditHandler(extent, params.type + params.id);
-        });
-
-        $("#object_larger_map").show();
-        $("#object_edit").show();
-
-        var centre = extent.getCenter();
-        updatelinks(centre.lng,
-                    centre.lat,
-                    16, null,
-                    extent.getWest(),
-                    extent.getSouth(),
-                    extent.getEast(),
-                    extent.getNorth(),
-                    object);
-      } else {
-        $("#small_map").hide();
+    addObjectToMap(object, map, {
+      zoom: true, 
+      callback: function(extent) {
+        $("#loading").hide();
+        $("#browse_map .geolink").show();
+
+        if (extent) {
+          $("a.bbox[data-editor=remote]").click(function () {
+            return remoteEditHandler(extent);
+          });
+
+          $("a.object[data-editor=remote]").click(function () {
+            return remoteEditHandler(extent, params.type + params.id);
+          });
+
+          $("#object_larger_map").show();
+          $("#object_edit").show();
+
+          var centre = extent.getCenter();
+          updatelinks(centre.lng,
+                      centre.lat,
+                      16, null,
+                      extent.getWest(),
+                      extent.getSouth(),
+                      extent.getEast(),
+                      extent.getNorth(),
+                      object);
+        } else {
+          $("#small_map").hide();
+        }
       }
     });
   }