]> git.openstreetmap.org Git - rails.git/commitdiff
Only add the data layer to the main map, and use the visibility changed
authorTom Hughes <tom@compton.nu>
Sun, 11 May 2008 14:41:11 +0000 (14:41 +0000)
committerTom Hughes <tom@compton.nu>
Sun, 11 May 2008 14:41:11 +0000 (14:41 +0000)
event to handle turning the data layer on and off.

app/views/site/index.rhtml
public/javascripts/map.js
public/openlayers/OpenStreetMap.js

index 895885360f03bef6100ec927f5f71f07ca5a12ec..bd114a6b36e54c640dc1221261de6ccec5f37e2a 100644 (file)
@@ -86,6 +86,10 @@ by the OpenStreetMap project and its contributors.
   function mapInit(){
     map = createMap("map");
 
+    map.dataLayer = new OpenLayers.Layer("Data", { "visibility": false });
+    map.dataLayer.events.register("visibilitychanged", map.dataLayer, toggleData);
+    map.addLayer(map.dataLayer);
+
     <% if bbox %>
     var bbox = new OpenLayers.Bounds(<%= minlon %>, <%= minlat %>, <%= maxlon %>, <%= maxlat %>);
 
@@ -118,6 +122,14 @@ by the OpenStreetMap project and its contributors.
     handleResize();
   }
 
+  function toggleData() {
+    if (map.dataLayer.visibility) {
+      <%= remote_function :url => { :controller => 'browse', :action => 'start' } %>
+    } else {
+      closeSidebar();
+    }
+  }
+
   function getPosition() {
     return getMapCenter();
   }
index c7f381d846df32e1b68863968d4ea9b3d5c566b3..9b144c560a5093f6d0852137f7e948dc079dc991 100644 (file)
@@ -8,7 +8,8 @@ OpenLayers._getScriptLocation = function () {
 }
 
 function createMap(divName, options) {
-   if (!options) { options = {} }
+   options = options || {};
+
    map = new OpenLayers.Map(divName, {
       controls: options.controls || [
          new OpenLayers.Control.ArgParser(),
@@ -40,9 +41,6 @@ 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 f472d3fc14631d543fd4215b8448b9cb71f78e0d..d6bc397d132ae517433ae494ad5956a0cc18cef1 100644 (file)
@@ -182,19 +182,3 @@ 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) {
-        var oldvis = this.visibility;
-        OpenLayers.Layer.prototype.setVisibility.apply(this, arguments);
-        if (!this.map) { return; }
-        if (vis && !oldvis) {
-            new Ajax.Request('/browse/start', {asynchronous:true, evalScripts:true}); 
-        } else {
-            if (this.stopBrowse) {
-                this.stopBrowse();
-                closeSidebar(); 
-            }    
-        }    
-    }
-});