]> git.openstreetmap.org Git - rails.git/blobdiff - app/assets/javascripts/index/browse.js
Remove hard coded assumption that layer zero is mapnik
[rails.git] / app / assets / javascripts / index / browse.js
index 0016c7b5d1c0ad35af2983886649cce0f8815fd7..6371f559b1b9807843622232e2a3823da28267de 100644 (file)
@@ -42,10 +42,11 @@ $(document).ready(function () {
 
     var locationFilter = new L.LocationFilter({
       enableButton: false,
 
     var locationFilter = new L.LocationFilter({
       enableButton: false,
-      adjustButton: false,
-      onChange: getData
+      adjustButton: false
     }).addTo(map);
 
     }).addTo(map);
 
+    locationFilter.on("change", getData);
+
     $("#sidebar_title").html(I18n.t('browse.start_rjs.data_frame_title'));
     $("#sidebar_content").html(sidebarHtml);
 
     $("#sidebar_title").html(I18n.t('browse.start_rjs.data_frame_title'));
     $("#sidebar_content").html(sidebarHtml);
 
@@ -77,10 +78,12 @@ $(document).ready(function () {
       map.removeLayer(dataLayer);
       map.removeLayer(locationFilter);
       map.off("moveend", updateData);
       map.removeLayer(dataLayer);
       map.removeLayer(locationFilter);
       map.off("moveend", updateData);
+      locationFilter.off("change", getData);
     });
 
     function enableFilter() {
       $("#browse_filter_toggle").html(I18n.t('browse.start_rjs.view_data'));
     });
 
     function enableFilter() {
       $("#browse_filter_toggle").html(I18n.t('browse.start_rjs.view_data'));
+      locationFilter.setBounds(map.getBounds().pad(-0.2));
       locationFilter.enable();
       getData();
     }
       locationFilter.enable();
       getData();
     }
@@ -159,28 +162,36 @@ $(document).ready(function () {
           dataLayer.clearLayers();
           selectedLayer = null;
 
           dataLayer.clearLayers();
           selectedLayer = null;
 
-          dataLayer.addData(xml);
+          var features = dataLayer.buildFeatures(xml);
+
+          function addFeatures() {
+            dataLayer.addData(features);
 
 
-          layersById = {};
-          var features = [];
+            layersById = {};
 
 
-          dataLayer.eachLayer(function (layer) {
-            var feature = layer.feature;
-            layersById[feature.id] = layer;
-            features.push({
-              typeName: featureTypeName(feature),
-              url: "/browse/" + feature.type + "/" + feature.id,
-              name: featureName(feature),
-              id: feature.id
+            dataLayer.eachLayer(function (layer) {
+              var feature = layer.feature;
+              layersById[feature.id] = layer;
+              $.extend(feature, {
+                typeName: featureTypeName(feature),
+                url: "/browse/" + feature.type + "/" + feature.id,
+                name: featureName(feature)
+              });
             });
             });
-          });
 
 
-          browseObjectList = $(JST["templates/browse/feature_list"]({
-            features: features,
-            url: url
-          }))[0];
+            browseObjectList = $(JST["templates/browse/feature_list"]({
+              features: features,
+              url: url
+            }))[0];
 
 
-          loadObjectList();
+            loadObjectList();
+          }
+
+          if (features.length < maxFeatures) {
+            addFeatures();
+          } else {
+            displayFeatureWarning(features.length, maxFeatures, addFeatures);
+          }
         }
       });
     }
         }
       });
     }