[fusion-commits] r1543 - in trunk: MapGuide MapGuide/php MapServer MapServer/php widgets

svn_fusion at osgeo.org svn_fusion at osgeo.org
Tue Sep 23 12:52:15 EDT 2008


Author: Assefa
Date: 2008-09-23 12:52:15 -0400 (Tue, 23 Sep 2008)
New Revision: 1543

Added:
   trunk/MapGuide/php/LoadScaleRanges.php
   trunk/MapServer/php/LoadScaleRanges.php
Modified:
   trunk/MapGuide/MapGuide.js
   trunk/MapGuide/php/LoadMap.php
   trunk/MapServer/MapServer.js
   trunk/MapServer/php/LoadMap.php
   trunk/widgets/Legend.js
Log:
move scale ranges from load map into new function (#129)

Modified: trunk/MapGuide/MapGuide.js
===================================================================
--- trunk/MapGuide/MapGuide.js	2008-09-22 19:57:16 UTC (rev 1542)
+++ trunk/MapGuide/MapGuide.js	2008-09-23 16:52:15 UTC (rev 1543)
@@ -331,6 +331,7 @@
             }
         }
         this.mapWidget._removeWorker();
+
     },
     
 //TBD: this function not yet converted for OL    
@@ -365,7 +366,54 @@
         OpenLayers.i18n('mapLoadError', {'error':r.transport.responseText})));
       this.mapWidget._removeWorker();
     },
+  
+    /**
+     * Function: loadScaleRanges
+     * 
+     * This function should be called after the map has loaded. It
+     * loads the scsle ranges for each layer. I tis for now only
+     * used by the legend widget.
+     */
+        
+    loadScaleRanges: function(userFunc) {
+        var sl = Fusion.getScriptLanguage();
+        var loadmapScript = this.arch + '/' + sl  + '/LoadScaleRanges.' + sl;
+        
+        var sessionid = this.getSessionID();
+        
+        var params = {'mapname': this._sMapname, "session": sessionid};
+        var options = {onSuccess: OpenLayers.Function.bind(this.scaleRangesLoaded,this, userFunc), 
+                       parameters:params};
+        Fusion.ajaxRequest(loadmapScript, options);
+    },
 
+    scaleRangesLoaded: function(userFunc, r) 
+    {
+        if (r.status == 200) 
+        {
+            var o;
+            eval('o='+r.responseText);
+            if (o.layers && o.layers.length > 0)
+            {
+                for (var i=0; i<o.layers.length; i++)
+                {
+                    var oLayer = this.getLayerById(o.layers[i].uniqueId);
+                    if (oLayer)
+                    {
+                        oLayer.scaleRanges = [];
+                        for (var j=0; j<o.layers[i].scaleRanges.length; j++) 
+                        {
+                            var scaleRange = new Fusion.Maps.MapGuide.ScaleRange(o.layers[i].scaleRanges[j], 
+                                                                                 oLayer.layerType);
+                            oLayer.scaleRanges.push(scaleRange);
+                        }
+                    }
+                }
+            }
+
+            userFunc();
+        }
+    },
 //TBD: this function not yet converted for OL    
     mapReloaded: function(r) {
         if (r.status == 200) {
@@ -560,6 +608,25 @@
     },
 
     /**
+     * Function: getLayerById
+     * 
+     * Returns the MapGuide layer object as identified by the layer unique id
+     */
+    getLayerById : function(id)
+    {
+        var oLayer = null;
+        for (var i=0; i<this.aLayers.length; i++)
+        {
+            if (this.aLayers[i].uniqueId == id)
+            {
+                oLayer = this.aLayers[i];
+                break;
+            }
+        }
+        return oLayer;
+    },           
+
+    /**
      * Function: isMapLoaded
      * 
      * Returns true if the Map has been laoded succesfully form the server

Modified: trunk/MapGuide/php/LoadMap.php
===================================================================
--- trunk/MapGuide/php/LoadMap.php	2008-09-22 19:57:16 UTC (rev 1542)
+++ trunk/MapGuide/php/LoadMap.php	2008-09-23 16:52:15 UTC (rev 1543)
@@ -138,7 +138,8 @@
         $layerObj->expandInLegend = BooleanToString($layer->GetExpandInLegend());
 
         $oScaleRanges = buildScaleRanges($layer);
-        $layerObj->scaleRanges = $oScaleRanges;
+        $_SESSION['scale_ranges'][$layer->GetObjectId()] = $oScaleRanges;
+        //$layerObj->scaleRanges = $oScaleRanges;
         /*get the min/max scale for the layer*/
         $nCount = count($oScaleRanges);
         $layerObj->minScale = $oScaleRanges[0]->minScale;

Added: trunk/MapGuide/php/LoadScaleRanges.php
===================================================================
--- trunk/MapGuide/php/LoadScaleRanges.php	                        (rev 0)
+++ trunk/MapGuide/php/LoadScaleRanges.php	2008-09-23 16:52:15 UTC (rev 1543)
@@ -0,0 +1,66 @@
+<?php
+/**
+ *
+ * $Id: $
+ *
+ * Copyright (c) 2007, DM Solutions Group Inc.
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included
+ * in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ */
+
+/*****************************************************************************
+ * Utility function to load scale ranges for the layers. Initially
+ * scale ranges were returned as part of in LoadMap.php. This allows
+ * to reduce the size of information that is returned by LoadMap, by putting
+ * elements that are unnessary to the map draw her.  
+ *****************************************************************************/
+
+
+include ("Common.php");
+include('../../common/php/Utilities.php');
+include('Utilities.php');
+
+
+$map = new MgMap();
+$map->Open($resourceService, $mapName);
+$layers=$map->GetLayers();
+
+$scaleObj = NULL;
+$scaleObj->layers = array();
+
+for($i=0;$i<$layers->GetCount();$i++) 
+{    
+    $layer=$layers->GetItem($i);
+    if (isset($_SESSION['scale_ranges']) && 
+        isset($_SESSION['scale_ranges'][$layer->GetObjectId()]))
+    {
+        $scaleranges = $_SESSION['scale_ranges'][$layer->GetObjectId()];
+        $layerObj = NULL;
+        $layerObj->uniqueId = $layer->GetObjectId();
+        $layerObj->scaleRanges = $scaleranges;
+        array_push($scaleObj->layers, $layerObj);
+    }
+ }
+
+header('Content-type: text/x-json');
+header('X-JSON: true');
+
+echo var2json($scaleObj);
+exit;
+
+?>

Modified: trunk/MapServer/MapServer.js
===================================================================
--- trunk/MapServer/MapServer.js	2008-09-22 19:57:16 UTC (rev 1542)
+++ trunk/MapServer/MapServer.js	2008-09-23 16:52:15 UTC (rev 1543)
@@ -239,8 +239,8 @@
               if (this.aLayers[i].visible) {
                   this.aVisibleLayers.push(this.aLayers[i].layerName);
               }
-      				minScale = Math.min(minScale, this.aLayers[i].minScale);
-      				maxScale = Math.max(maxScale, this.aLayers[i].maxScale);
+              minScale = Math.min(minScale, this.aLayers[i].minScale);
+              maxScale = Math.max(maxScale, this.aLayers[i].maxScale);
             }
             //a scale value of 0 is undefined
             if (minScale <= 0) {
@@ -335,6 +335,54 @@
         Fusion.ajaxRequest(loadmapScript, options);
     },
 
+    /**
+     * Function: loadScaleRanges
+     * 
+     * This function should be called after the map has loaded. It
+     * loads the scsle ranges for each layer. I tis for now only
+     * used by the legend widget.
+     */
+        
+    loadScaleRanges: function(userFunc) {
+        var sl = Fusion.getScriptLanguage();
+        var loadmapScript = this.arch + '/' + sl  + '/LoadScaleRanges.' + sl;
+        
+        var sessionid = this.getSessionID();
+        
+        var params = {'mapname': this._sMapname, "session": this.getSessionID()};
+        var options = {onSuccess: OpenLayers.Function.bind(this.scaleRangesLoaded,this, userFunc), 
+                       parameters:params};
+        Fusion.ajaxRequest(loadmapScript, options);
+    },
+
+    scaleRangesLoaded: function(userFunc, r) 
+    {
+        if (r.status == 200) 
+        {
+            var o;
+            eval('o='+r.responseText);
+            if (o.layers && o.layers.length > 0)
+            {
+                for (var i=0; i<o.layers.length; i++)
+                {
+                    var oLayer = this.getLayerById(o.layers[i].uniqueId);
+                    if (oLayer)
+                    {
+                        oLayer.scaleRanges = [];
+                        for (var j=0; j<o.layers[i].scaleRanges.length; j++) 
+                        {
+                            var scaleRange = new Fusion.Maps.MapServer.ScaleRange(o.layers[i].scaleRanges[j], 
+                                                                                 oLayer.layerType);
+                            oLayer.scaleRanges.push(scaleRange);
+                        }
+                    }
+                }
+            }
+
+            userFunc();
+        }
+    },
+
     mapReloaded: function(r) {  
         if (r.status == 200) {
             var o;
@@ -423,6 +471,7 @@
         }
     },
 
+    
     /**
      * Function: isMapLoaded
      *
@@ -733,6 +782,20 @@
       return null;
   },
 
+    getLayerById : function(id)
+    {
+        var oLayer = null;
+        for (var i=0; i<this.aLayers.length; i++)
+        {
+            if (this.aLayers[i].uniqueId == id)
+            {
+                oLayer = this.aLayers[i];
+                break;
+            }
+        }
+        return oLayer;
+    },           
+
   getMetadata: function(key) {
       if (typeof this.metadata[key] != 'undefined') {
           return this.metadata[key];
@@ -826,14 +889,18 @@
         this.metadata = o.metadata;
         this.extent = o.extent;
         this.scaleRanges = [];
-    		this.minScale = 1.0e10;
-    		this.maxScale = 0;
+        this.minScale = o.minScale;
+        this.maxScale = o.maxScale;
+        
+        /*
         for (var i=0; i<o.scaleRanges.length; i++) {
             var scaleRange = new Fusion.Maps.MapServer.ScaleRange(o.scaleRanges[i], this.supportsType(4));
             this.scaleRanges.push(scaleRange);
       			this.minScale = Math.min(this.minScale, scaleRange.minScale);
       			this.maxScale = Math.max(this.maxScale, scaleRange.maxScale);
+        
         }
+        */
     },
 
     clear: function() {

Modified: trunk/MapServer/php/LoadMap.php
===================================================================
--- trunk/MapServer/php/LoadMap.php	2008-09-22 19:57:16 UTC (rev 1542)
+++ trunk/MapServer/php/LoadMap.php	2008-09-23 16:52:15 UTC (rev 1543)
@@ -272,8 +272,18 @@
                  }
              }
          }
-         $layerObj->scaleRanges = $aScaleRanges;
-         array_push($mapObj->layers, $layerObj);
+         //$layerObj->scaleRanges = $aScaleRanges;
+         $_SESSION['scale_ranges'][$i] = $aScaleRanges;
+         /*get the min/max scale for the layer*/
+        $nCount = count($aScaleRanges);
+        $layerObj->minScale = $oScaleRanges[0]->minScale;
+        $layerObj->maxScale = $oScaleRanges[0]->maxScale;
+        for ($j=1; $j<$nCount; $j++)
+        {
+            $layerObj->minScale = min($layerObj->minScale, $oScaleRanges[$j]->minScale);
+            $layerObj->maxScale = max($layerObj->maxScale, $oScaleRanges[$j]->maxScale);
+        }
+        array_push($mapObj->layers, $layerObj);
     }
     $mapObj->groups = array();
     $aGroups = $oMap->getAllGroupNames();

Added: trunk/MapServer/php/LoadScaleRanges.php
===================================================================
--- trunk/MapServer/php/LoadScaleRanges.php	                        (rev 0)
+++ trunk/MapServer/php/LoadScaleRanges.php	2008-09-23 16:52:15 UTC (rev 1543)
@@ -0,0 +1,66 @@
+<?php
+/**
+ * SetLayers
+ *
+ * $Id: $
+ *
+ * Copyright (c) 2007, DM Solutions Group Inc.
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included
+ * in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ */
+
+/*****************************************************************************
+ * Utility function to load scale ranges for the layers. Initially
+ * scale ranges were returned as part of in LoadMap.php. This allows
+ * to reduce the size of information that is returned by LoadMap, by putting
+ * elements that are unnessary to the map draw her.  
+ *****************************************************************************/
+
+/* set up the session */
+include ("Common.php");
+include('../../common/php/Utilities.php');
+include ("Utilities.php");
+
+
+if (isset($_SESSION['maps']) && isset($_SESSION['maps'][$mapName])) {
+    $oMap = ms_newMapObj($_SESSION['maps'][$mapName]);
+}
+
+$scaleObj = NULL;
+$scaleObj->layers = array();
+
+for($i=0;$i<$oMap->numlayers;$i++) 
+{    
+    if (isset($_SESSION['scale_ranges']) && 
+        isset($_SESSION['scale_ranges'][$i]))
+    {
+        $scaleranges = $_SESSION['scale_ranges'][$i];
+        $layerObj = NULL;
+        $layerObj->uniqueId = $i;
+        $layerObj->scaleRanges = $scaleranges;
+        array_push($scaleObj->layers, $layerObj);
+    }
+ }
+
+
+header('Content-type: text/x-json');
+header('X-JSON: true');
+
+echo var2json($scaleObj);
+exit;
+

Modified: trunk/widgets/Legend.js
===================================================================
--- trunk/widgets/Legend.js	2008-09-22 19:57:16 UTC (rev 1542)
+++ trunk/widgets/Legend.js	2008-09-23 16:52:15 UTC (rev 1543)
@@ -242,7 +242,7 @@
         this.oTree = new Jx.Tree(this.oLegend.domObj);
        
         this.hideInvisibleLayers = (json.HideInvisibleLayers && json.HideInvisibleLayers[0]) == 'true' ? true : false;
-        
+        //console.log('hideInvisibleLayers ' +  this.hideInvisibleLayers);
         this.refreshItem = new Jx.Menu.Item({
             label: OpenLayers.i18n('refresh'),
             onClick: OpenLayers.Function.bind(this.update, this)
@@ -338,6 +338,10 @@
       this.targetFolder = folder;
     },
     
+    scaleRangesLoaded: function() {
+        this.layerRoot = this.getMap().layerRoot;
+        this.renderLegend();
+    },
     mapLoading: function() {
         this.getMap().deregisterForEvent(Fusion.Event.MAP_EXTENTS_CHANGED, this.extentsChangedWatcher);
         this.clear();
@@ -345,12 +349,11 @@
    
     mapLoaded: function() {
         this.getMap().registerForEvent(Fusion.Event.MAP_EXTENTS_CHANGED, this.extentsChangedWatcher);
-        this.layerRoot = this.getMap().layerRoot;
-        this.renderLegend();
+        this.getMap().loadScaleRanges(OpenLayers.Function.bind(this.scaleRangesLoaded, this));
     },
     
     mapReloaded: function() {
-        this.renderLegend();
+        this.getMap().loadScaleRanges(OpenLayers.Function.bind(this.scaleRangesLoaded, this));
     },
     /**
      * the map state has become invalid in some way (layer added, removed,
@@ -482,6 +485,7 @@
     
     selectionChanged: function(o) {
         if (this.currentNode) {
+          console.log(this.currentNode);
             $(this.currentNode.domObj.childNodes[3]).addClass('jxTreeSelectedNode');
         }
         this.currentNode = o;
@@ -666,6 +670,7 @@
         }
     },
     stateChanged: function(obj) {
+    console.log(obj);
         if (obj.legend && obj.legend.treeItem.checkBox) {
             if (obj.legend.treeItem.checkBox.checked) {
                 obj.show();



More information about the fusion-commits mailing list