]> git.openstreetmap.org Git - rails.git/blobdiff - app/assets/javascripts/index/browse.js
Ignore clicks on the add note button when it is disabled
[rails.git] / app / assets / javascripts / index / browse.js
index dcea8e0c0b209ca1528c7765f8efa933bc0a4552..a9bdbf2b7fac290dd561b9ac1e31b8396d8763ee 100644 (file)
@@ -2,7 +2,7 @@
 //= require templates/browse/feature_list
 //= require templates/browse/feature_history
 
-$(document).ready(function () {
+function initializeBrowse(map, params) {
   var browseBounds;
   var layersById;
   var selectedLayer;
@@ -10,20 +10,20 @@ $(document).ready(function () {
   var areasHidden = false;
   var locationFilter;
 
-  var dataLayer = new L.OSM.DataLayer(null, {
-    styles: {
-      way: {
-        weight: 3,
-        color: "#000000",
-        opacity: 0.4
-      },
-      area: {
-        weight: 3,
-        color: "#ff0000"
-      },
-      node: {
-        color: "#00ff00"
-      }
+  var dataLayer = map.dataLayer;
+
+  dataLayer.setStyle({
+    way: {
+      weight: 3,
+      color: "#000000",
+      opacity: 0.4
+    },
+    area: {
+      weight: 3,
+      color: "#ff0000"
+    },
+    node: {
+      color: "#00ff00"
     }
   });
 
@@ -35,10 +35,6 @@ $(document).ready(function () {
     onSelect(e.layer);
   });
 
-  if (OSM.STATUS != 'api_offline' && OSM.STATUS != 'database_offline') {
-    map.layersControl.addOverlay(dataLayer, I18n.t("browse.start_rjs.data_layer_name"));
-  }
-
   map.on('layeradd', function (e) {
     if (e.layer === dataLayer) {
       $.ajax({ url: "/browse/start", success: function (sidebarHtml) {
@@ -53,6 +49,12 @@ $(document).ready(function () {
     }
   });
 
+  if (OSM.STATUS != 'api_offline' && OSM.STATUS != 'database_offline') {
+    if (params.layers.indexOf(dataLayer.options.code) >= 0) {
+      map.addLayer(dataLayer);
+    }
+  }
+
   function startBrowse(sidebarHtml) {
     locationFilter = new L.LocationFilter({
       enableButton: false,
@@ -66,6 +68,8 @@ $(document).ready(function () {
 
     openSidebar();
 
+    if (browseObjectList) loadObjectList();
+
     map.on("moveend", updateData);
     updateData();
 
@@ -140,6 +144,8 @@ $(document).ready(function () {
     $("#browse_content").append(div);
   }
 
+  var dataLoader;
+
   function getData() {
     var bounds = locationFilter.isEnabled() ? locationFilter.getBounds() : map.getBounds();
     var size = bounds.getSize();
@@ -151,7 +157,7 @@ $(document).ready(function () {
 
     setStatus(I18n.t('browse.start_rjs.loading'));
 
-    var url = "/api/" + OSM.API_VERSION + "/map?bbox=" + bounds.toBBOX();
+    var url = "/api/" + OSM.API_VERSION + "/map?bbox=" + bounds.toBBoxString();
 
     /*
      * Modern browsers are quite happy showing far more than 100 features in
@@ -168,7 +174,9 @@ $(document).ready(function () {
       }
     @*/
 
-    $.ajax({
+    if (dataLoader) dataLoader.abort();
+
+    dataLoader = $.ajax({
       url: url,
       success: function (xml) {
         clearStatus();
@@ -207,6 +215,8 @@ $(document).ready(function () {
         } else {
           displayFeatureWarning(features.length, maxFeatures, addFeatures);
         }
+
+        dataLoader = null;
       }
     });
   }
@@ -327,4 +337,4 @@ $(document).ready(function () {
     $("#browse_status").html("");
     $("#browse_status").hide();
   }
-});
+}