]> git.openstreetmap.org Git - rails.git/blobdiff - app/views/browse/start.rjs
move data into a layer in the layerswitcher
[rails.git] / app / views / browse / start.rjs
index 12a5f070c97482f1b3cd445895019f3ac22bba25..8d221f29014a5ba007e49aae23f2e8e53526c90f 100644 (file)
@@ -2,7 +2,7 @@ page.replace_html :sidebar_title, 'Data'
 page.replace_html :sidebar_content, :partial => 'start'
 page << <<EOJ
     
-    var gml, sf, objList, currentFeature, featureList, mode = "auto", currentBounds;
+    var gml, sf, objList, currentFeature, featureList, mode = "auto", currentBounds, browsing;
     OpenLayers.Feature.Vector.style['default'].strokeWidth = 3;
     OpenLayers.Feature.Vector.style['default'].cursor = "pointer";
     
@@ -22,6 +22,8 @@ page << <<EOJ
         map.addControl(box);
         map.events.register("moveend", map, showData);
         map.events.triggerEvent("moveend");
+        map.dataLayer.stopBrowse = stopBrowse;
+        browsing = true;
     }
 
     function showData() {
@@ -34,19 +36,24 @@ page << <<EOJ
     }
     
     function stopBrowse() {
-        if (gml) {
-            gml.destroy();
-            gml = null; 
-        } 
-        if (sf) {   
-            sf.destroy();  
-            sf = null;
-        } 
-        if (currentFeature) {
-            currentFeature.destroy(); 
-            currentFeature = null; 
-        } 
-        map.events.unregister("moveend", map, showData);
+        if (browsing) {
+            browsing = false; 
+            map.dataLayer.stopBrowse = null;
+            if (gml) {
+                gml.destroy();
+                gml = null; 
+            } 
+            if (sf) {   
+                sf.destroy();  
+                sf = null;
+            } 
+            if (currentFeature) {
+                currentFeature.destroy(); 
+                currentFeature = null; 
+            }
+            map.dataLayer.setVisibility(false);
+            map.events.unregister("moveend", map, showData);
+        }    
     }
     
     function startDrag() {
@@ -72,7 +79,6 @@ page << <<EOJ
             currentBounds = tileBounds;
             getData(tileBounds);
             mode = "auto";
-            $("drag_box").style.display="inline";
             $("use_map").style.display="none";
         }
         return false;
@@ -82,11 +88,11 @@ page << <<EOJ
     function endDrag(bbox) {
         var bounds = bbox.getBounds();
         box.deactivate();
+        currentBounds = bounds;
         getData(bounds);
         $("drag_box").innerHTML = "Manually select a different area";
         mode = "manual";  
         $("use_map").style.display="inline";
-        $("drag_box").style.display="none";
     }
     
     function displayFeatureWarning() {
@@ -111,6 +117,7 @@ page << <<EOJ
     }    
 
     function customDataLoader(request) { 
+        if (!browsing) { return; } 
         var doc = request.responseXML;
         
         if (!doc || !doc.documentElement) {
@@ -165,6 +172,7 @@ page << <<EOJ
             gml = new OpenLayers.Layer.GML("Data",url, 
                     {format: OpenLayers.Format.OSM, formatOptions: {checkTags: true},
                      maxFeatures: 100, requestSuccess: customDataLoader,
+                     displayInLayerSwitcher: false,
                      styleMap: new OpenLayers.StyleMap({'default': style, 'select': {'strokeColor': '#0000ff', strokeWidth: 8}})
                     }
             );
@@ -183,7 +191,8 @@ page << <<EOJ
 
         currentFeature = null;
     }
-    function dataLoaded() { 
+    function dataLoaded() {
+        if (!browsing) { return; } 
         $("status").innerHTML = "Loaded " + this.features.length + " features. (<a href='"+ this.url+"'>API</a>)";
         
         objList = document.createElement("ul");
@@ -314,7 +323,7 @@ page << <<EOJ
         div.appendChild(h3);
         var nodes = doc.getElementsByTagName(this.type);
         var history = document.createElement("ul");  
-        for (var i = 0; i < nodes.length; i++) {
+        for (var i = nodes.length - 1; i >= 0; i--) {
             var user = nodes[i].getAttribute("user") || "private user";
             var timestamp = nodes[i].getAttribute("timestamp");
             var item = document.createElement("li");