[fusion-commits] r2880 - in trunk: lib widgets

svn_fusion at osgeo.org svn_fusion at osgeo.org
Sat Sep 27 00:06:31 PDT 2014


Author: jng
Date: 2014-09-27 00:06:31 -0700 (Sat, 27 Sep 2014)
New Revision: 2880

Modified:
   trunk/lib/Map.js
   trunk/widgets/BasemapSwitcher.js
   trunk/widgets/OverviewMap.js
Log:
#628: Fix OverviewMap widget not showing external base layers. A new event (Fusion.Event.MAP_BASE_LAYER_CHANGED) is triggered when the map's external base layer changes. The OverviewMap widget now includes any external layers when creating the OverviewMap control, and will keep the active external base layer in sync with the main map by listening to this event.

Modified: trunk/lib/Map.js
===================================================================
--- trunk/lib/Map.js	2014-09-25 02:12:23 UTC (rev 2879)
+++ trunk/lib/Map.js	2014-09-27 07:06:31 UTC (rev 2880)
@@ -92,6 +92,10 @@
  */
 Fusion.Event.MAP_DIGITIZER_DEACTIVATED = Fusion.Event.lastEventId++;
 /**
+ * Constant: Fusion.Event.MAP_BASE_LAYER_CHANGED
+ */
+Fusion.Event.MAP_BASE_LAYER_CHANGED = Fusion.Event.lastEventId++;
+/**
  * Constant: Fusion.Constant.LAYER_POINT_TYPE
  */
 Fusion.Constant.LAYER_POINT_TYPE = 0;
@@ -309,6 +313,7 @@
         this.registerEventID(Fusion.Event.MAP_MAP_GROUP_LOADED);
         this.registerEventID(Fusion.Event.MAP_DIGITIZER_ACTIVATED);
         this.registerEventID(Fusion.Event.MAP_DIGITIZER_DEACTIVATED);
+        this.registerEventID(Fusion.Event.MAP_BASE_LAYER_CHANGED);
 
         this.registerForEvent(Fusion.Event.MAP_LOADED, OpenLayers.Function.bind(this.mapLoaded,this));
         this.registerForEvent(Fusion.Event.MAP_RELOADED, OpenLayers.Function.bind(this.mapLoaded,this));
@@ -340,6 +345,20 @@
         //create the 'Map' layer widgets defined in the MapGroup
         this.loadMapGroup(mapGroup);
     },
+    
+    /**
+     * Function: setExternalBaseLayer
+     *
+     * Sets the given external layer as the new base layer
+     *
+     * Parameter: {Fusion.Layers} baseLayer - a Fusion.Layers instance to set as the new base map
+     *
+     * Return: none
+     */
+    setExternalBaseLayer: function(baseLayer) {
+        this.oMapOL.setBaseLayer(baseLayer.oLayerOL, false);
+        this.triggerEvent(Fusion.Event.MAP_BASE_LAYER_CHANGED, baseLayer);
+    },
 
     /**
      * Function: mapLoaded

Modified: trunk/widgets/BasemapSwitcher.js
===================================================================
--- trunk/widgets/BasemapSwitcher.js	2014-09-25 02:12:23 UTC (rev 2879)
+++ trunk/widgets/BasemapSwitcher.js	2014-09-27 07:06:31 UTC (rev 2880)
@@ -368,14 +368,14 @@
     setBasemap: function(baseMap) {
         if ("None" != baseMap && this.getMap().oMapOL.baseLayer.CLASS_NAME == "OpenLayers.Layer.MapGuide") {
             var visibility = this.baseMaps["None"].oLayerOL.visibility;
-            this.getMap().oMapOL.setBaseLayer(this.baseMaps[baseMap].oLayerOL, false);
+            this.getMap().setExternalBaseLayer(this.baseMaps[baseMap], false);
             this.applyZoomOffset(baseMap);
             // Keep the MapGuide layers visibility
             this.baseMaps["None"].oLayerOL.visibility = visibility;
             this.baseMaps["None"].oLayerOL.redraw();
         }
         else {
-            this.getMap().oMapOL.setBaseLayer(this.baseMaps[baseMap].oLayerOL, false);
+            this.getMap().setExternalBaseLayer(this.baseMaps[baseMap], false);
             this.applyZoomOffset(baseMap);
         }
         this.activeBasemap = baseMap;

Modified: trunk/widgets/OverviewMap.js
===================================================================
--- trunk/widgets/OverviewMap.js	2014-09-25 02:12:23 UTC (rev 2879)
+++ trunk/widgets/OverviewMap.js	2014-09-27 07:06:31 UTC (rev 2880)
@@ -65,6 +65,7 @@
         this.oMapOptions = {};  //TODO: allow setting some mapOptions in AppDef
 
         this.getMap().registerForEvent(Fusion.Event.MAP_LOADED, OpenLayers.Function.bind(this.mapWidgetLoaded, this));
+        this.getMap().registerForEvent(Fusion.Event.MAP_BASE_LAYER_CHANGED, OpenLayers.Function.bind(this.mapBaseLayerChanged, this));
     },
 
     mapWidgetLoaded: function()
@@ -128,6 +129,21 @@
                 }
             }
             
+            // Check if we have any external layers, if so add them too.
+            var bHasOtherLayers = false;
+            var otherLayers = this.getMap().getAllMaps();
+            for (var i = 0; i < otherLayers.length; i++) {
+                if (otherLayers[i].arch != "MapGuide") {
+                    var olLayer = otherLayers[i].oLayerOL.clone();
+                    ovLayers.push(olLayer);
+                    bHasOtherLayers = true;
+                }
+            }
+            // If we found external layers, the MapGuide one is no longer a base layer but an overlay
+            if (bHasOtherLayers) {
+                layer.isBaseLayer = false;
+            }
+            
             var options = {
               div: this.domObj,
               size: this.oSize,
@@ -150,6 +166,26 @@
             //console.log('OverviewMap mapLoaded');
         }
     },
+    
+    mapBaseLayerChanged: function(evtId, newBaseLayer) {
+        //OverviewMap control not created yet. Come back later
+        if (!this.control) {
+            return;
+        }
+        var newOLLayer = newBaseLayer.oLayerOL;
+        //Update ov map's base layer to match
+        var layers = this.control.ovmap.layers;
+        var newOvLayer = null;
+        for (var i = 0; i < layers.length; i++) {
+            layers[i].isBaseLayer = false;
+            if (layers[i].name == newOLLayer.name) {
+                newOvLayer = layers[i];
+            }
+        }
+        if (newOvLayer != null) {
+            this.control.ovmap.setBaseLayer(newOvLayer);
+        }
+    },
 
     sizeChanged: function() {
         var size = $(this.domObj).getContentBoxSize();



More information about the fusion-commits mailing list