[fusion-commits] r2479 - in trunk: layers/MapGuide widgets

svn_fusion at osgeo.org svn_fusion at osgeo.org
Fri Dec 2 05:13:05 EST 2011


Author: jng
Date: 2011-12-02 02:13:04 -0800 (Fri, 02 Dec 2011)
New Revision: 2479

Modified:
   trunk/layers/MapGuide/MapGuide.js
   trunk/widgets/BasemapSwitcher.js
Log:
#486: Fix layer mismatch with Bing layers. The problem is due to the scale list being used not the same as the bing layer scale list as a result, tile layer requests were being offset by 1. The solution is to check if the given OpenLayers.Layer.MapGuide objects being created has a google compatible scale list. If they do, appropriate offsets are applied to these objects based on the currently selected commercial layer from the BasemapSwitcher widget. When the commercial layer switches, these offsets are updated.

Modified: trunk/layers/MapGuide/MapGuide.js
===================================================================
--- trunk/layers/MapGuide/MapGuide.js	2011-12-02 06:18:49 UTC (rev 2478)
+++ trunk/layers/MapGuide/MapGuide.js	2011-12-02 10:13:04 UTC (rev 2479)
@@ -41,6 +41,15 @@
     selectionType: 'INTERSECTS',
     bSelectionOn: false,
     oSelection: null,
+    nCmsScaleTolerance: 2.0,  //When checking the scale list of a tiled map to determine if it is compatible with commercial layers, this value determines how much leeway a given scale can have to be considered equal
+    bUsesCommercialLayerScaleList: false,
+    //This is the CMS scale list as defined by MG Studio and interpreted by OpenLayers
+    aCmsScales: [
+        1128.49722, 2256.99444, 4513.98888, 9027.977761000002, 18055.95552,
+        36111.91104, 72223.82208999999, 144447.6442, 288895.2884, 577790.5767000001, 
+        1155581.153, 2311162.307, 4622324.614, 9244649.227, 18489298.45, 
+        36978596.91, 73957193.82, 147914387.6, 295828775.3, 591657550.5
+    ],
     selectionAsOverlay: true,
     useAsyncOverlay: false,
     defaultFormat: 'PNG',
@@ -717,8 +726,49 @@
       }
       
       var oNewLayerOL = new OpenLayers.Layer.MapGuide( layerName, url, params, layerOptions );
+      if (!bSingleTile) {
+        if (oNewLayerOL.scales.length == this.aCmsScales.length) { 
+            //NOTE: This is not a property of OpenLayers.Layer.MapGuide, it is something we've bolted on
+            oNewLayerOL.bUsesCommercialLayerScaleList = false;
+            for (var i = 0; i < this.aCmsScales.length; i++) {
+                if (!this.scalesAreApproximate(oNewLayerOL.scales[i], this.aCmsScales[i]))
+                {
+                    return oNewLayerOL; //Doesn't match. Nothing more to do here
+                }
+            }
+            oNewLayerOL.bUsesCommercialLayerScaleList = true;
+            this.bUsesCommercialLayerScaleList = true;
+        }
+      }
       return oNewLayerOL;
     },
+    
+    scalesAreApproximate: function(scale1, scale2) {
+        return Math.abs(scale1 - scale2) < this.nCmsScaleTolerance;
+    },
+    
+    applyZoomOffset: function(offset) {
+        //console.log("Applying zoom offset of: " + offset);
+        //We need to redraw to prevent potential mismatch after switching of commerical layers
+        //TODO: This is called for each commerical layer in the basemap switcher widget, do
+        //redraw() calls at this point result in redundant requests?
+        if (this.oLayerOL && this.oLayerOL.bUsesCommercialLayerScaleList === true) {
+            this.oLayerOL.zoomOffset = offset;
+            this.oLayerOL.redraw();
+        }
+        if (this.oLayerOL2 && this.oLayerOL2.bUsesCommercialLayerScaleList === true) {
+            this.oLayerOL2.zoomOffset = offset;
+            this.oLayerOL2.redraw();
+        }
+        if (this.oLayersOLTile) {
+            for (var i = 0; i < this.oLayersOLTile.length; i++) {
+                if (this.oLayersOLTile[i].bUsesCommercialLayerScaleList === true) {
+                    this.oLayersOLTile[i].zoomOffset = offset;
+                    this.oLayersOLTile[i].redraw();
+                }
+            }
+        }
+    },
 
     /**
      * Function: getLayerByName

Modified: trunk/widgets/BasemapSwitcher.js
===================================================================
--- trunk/widgets/BasemapSwitcher.js	2011-12-02 06:18:49 UTC (rev 2478)
+++ trunk/widgets/BasemapSwitcher.js	2011-12-02 10:13:04 UTC (rev 2479)
@@ -29,10 +29,30 @@
 
     defaultBasemap: null,
 
+    activeBasemap: null,
+
     menuItems: {},
+    
+    zoomOffsets: {
+        'G_NORMAL_MAP': 0,
+        'G_SATELLITE_MAP': 0,
+        'G_HYBRID_MAP': 0,
+        'G_PHYSICAL_MAP': 0,
+        'YAHOO_MAP_REG': 0,
+        'YAHOO_MAP_SAT': 0,
+        'YAHOO_MAP_HYB': 0,
+        'Road': -1,
+        'Aerial': -1,
+        'Hybrid': -1,
+        'Mapnik': 0,
+        'Osmarender': 0,
+        'CycleMap': 0,
+        'None': 0
+    },
 
     initializeWidget: function(widgetTag) {
         this.getMap().registerForEvent(Fusion.Event.MAP_MAP_GROUP_LOADED, OpenLayers.Function.bind(this.setDefaultBasemap, this));
+        this.getMap().registerForEvent(Fusion.Event.MAP_LOADED, OpenLayers.Function.bind(this.checkZoomOffsets, this));
     },
 
     refreshSettings: function() {
@@ -289,19 +309,39 @@
         Fusion.Widget.prototype.setUiObject.apply(this, [uiObj]);
         this.setDefaultBasemap();
     },
+    
+    checkZoomOffsets: function() {
+        if (this.activeBasemap != null) {
+            this.applyZoomOffset(this.activeBasemap);
+        }
+    },
+    
+    applyZoomOffset: function(baseMap) {
+        var offset = 0;
+        if (this.zoomOffsets[baseMap])
+            offset = this.zoomOffsets[baseMap];
+        for (var i = 0; i < this.getMap().aMaps.length; i++) {
+            var layer = this.getMap().aMaps[i];
+            if (layer.arch == "MapGuide" && layer.bUsesCommercialLayerScaleList) {
+                layer.applyZoomOffset(offset);
+            }
+        }
+    },
 
     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.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.applyZoomOffset(baseMap);
         }
-
+        this.activeBasemap = baseMap;
     },
 
     setDefaultBasemap: function() {



More information about the fusion-commits mailing list