]> git.openstreetmap.org Git - rails.git/commitdiff
move data into a layer in the layerswitcher
authorChristopher Schmidt <crschmidt@crschmidt.net>
Wed, 23 Apr 2008 13:59:41 +0000 (13:59 +0000)
committerChristopher Schmidt <crschmidt@crschmidt.net>
Wed, 23 Apr 2008 13:59:41 +0000 (13:59 +0000)
app/views/browse/_start.rhtml
app/views/browse/start.rjs
app/views/site/index.rhtml
public/javascripts/map.js
public/openlayers/OpenStreetMap.js

index 8b894fcb8c004a37c44c412b552f99abbc5176e6..a6030a5a4b5914a34b766aab8ff7f4fe6dbed580 100644 (file)
@@ -1,4 +1,4 @@
-<div style="padding:0px 10px; width:100%">
+<div style="padding:0px 10px">
     <div style="text-align: center">
     <p style="margin-top: 10px">
       <a id="use_map" display="hidden" href="#">View Data For Current Map View</a>
index 84a03ce1c0a2a42e8a4d6a8b043d543ed7e41e98..8d221f29014a5ba007e49aae23f2e8e53526c90f 100644 (file)
@@ -22,6 +22,7 @@ page << <<EOJ
         map.addControl(box);
         map.events.register("moveend", map, showData);
         map.events.triggerEvent("moveend");
+        map.dataLayer.stopBrowse = stopBrowse;
         browsing = true;
     }
 
@@ -35,20 +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);
-        browsing = false; 
+        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() {
@@ -83,6 +88,7 @@ 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";  
@@ -166,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}})
                     }
             );
index fa31d848ba2f3ab39806270f5e63a1360c366cb5..94b24debf54d41162759c182f069ab03e29d8108 100644 (file)
@@ -9,7 +9,6 @@
 <%= render :partial => 'search' %>
 
 <div id="map">
-<div id="datalink"><%= link_to_remote 'See Data', {:url => {:controller => 'browse', :action => 'start'}}, {:href => url_for( {:controller => 'browse', :action => 'index'}), :id => 'browseanchor', :title => 'browse data'} %></div>
 <div id="permalink"><a href="/" id="permalinkanchor">Permalink</a></div>
 </div> 
 
index bc2e9086326dbbbe1b24b6bdbc9da474c1ef9b7b..ccfa3b2559a0fa40d9c7fbb0f058642a6a87e9c0 100644 (file)
@@ -40,6 +40,9 @@ function createMap(divName, options) {
       wrapDateLine: true
    });
    map.addLayer(maplint);
+   var data = new OpenLayers.Layer.Data("Data", {'visibility': false});
+   map.addLayer(data); 
+   map.dataLayer = data;
 
    var numZoomLevels = Math.max(mapnik.numZoomLevels, osmarender.numZoomLevels);
    markers = new OpenLayers.Layer.Markers("Markers", {
index d6bc397d132ae517433ae494ad5956a0cc18cef1..244930866ab07a46c834304eb3b3c40b2050ec30 100644 (file)
@@ -182,3 +182,18 @@ OpenLayers.Layer.OSM.Maplint = OpenLayers.Class(OpenLayers.Layer.OSM, {
 
     CLASS_NAME: "OpenLayers.Layer.OSM.Maplint"
 });
+
+OpenLayers.Layer.Data = OpenLayers.Class(OpenLayers.Layer, { 
+    setVisibility: function(vis) {
+        OpenLayers.Layer.prototype.setVisibility.apply(this, arguments);
+        if (!this.map) { return; }
+        if (vis) {
+            new Ajax.Request('/browse/start', {asynchronous:true, evalScripts:true}); 
+        } else {
+            if (this.stopBrowse) {
+                this.stopBrowse();
+                closeSidebar(); 
+            }    
+        }    
+    }
+});