[fusion-commits] r1729 - in branches/fusion2-mg21/layers/MapGuide: . php

svn_fusion at osgeo.org svn_fusion at osgeo.org
Fri Dec 19 15:48:21 EST 2008


Author: chrisclaydon
Date: 2008-12-19 15:48:21 -0500 (Fri, 19 Dec 2008)
New Revision: 1729

Added:
   branches/fusion2-mg21/layers/MapGuide/php/GetSelectionProperties.php
   branches/fusion2-mg21/layers/MapGuide/php/SaveSelection.php
Removed:
   branches/fusion2-mg21/layers/MapGuide/php/HighlightSelection.php
   branches/fusion2-mg21/layers/MapGuide/php/SetSelection.php
Modified:
   branches/fusion2-mg21/layers/MapGuide/MapGuide.js
Log:
re #199 - Fix setSelection API to work with new selection handling.

MapGuide.js - cleaned up the code a little, and re-structured so that setSelection updates the map image, and optionally zooms to the extents of the selected features.

Renamed HighlightSelection.php to SaveSelection.php, since all it does is update the selection stored in the map resource in the MG session, and retrieve some basic info about the selection.
Renamed SetSelection.php to GetSelectionProperties.php, since it no longer sets the selection. It just retrieves properties and basic info for the selected features.

Also updated SaveSelection.php optionally to retrieve the selection extents. This is required is setSelection is called with zoomTo set to true.

Modified: branches/fusion2-mg21/layers/MapGuide/MapGuide.js
===================================================================
--- branches/fusion2-mg21/layers/MapGuide/MapGuide.js	2008-12-19 17:52:06 UTC (rev 1728)
+++ branches/fusion2-mg21/layers/MapGuide/MapGuide.js	2008-12-19 20:48:21 UTC (rev 1729)
@@ -673,34 +673,58 @@
       return layers;
     },
 
+    /**
+     * Updates the current map selection with the provided XML selection string.
+     * Optionally zooms to the new selection on the map, if zoomTo is set to true.
+     */
     setSelection: function (selText, zoomTo) {
+
+        //TODO Update this.previousSelection when the selection is set using
+        //this API to allow the selection to be extended with a shift-click.
+
+        if(selText != "" && selText != null) {
+            this.updateSelection(selText, zoomTo, false);
+        }
+        else {
+            this.clearSelection();
+        }
+    },
+
+    updateSelection: function (selText, zoomTo, extendSelection) {
+        this.updateMapSelection(selText, zoomTo);
+        this.getSelectedFeatureProperties(selText);
+    },
+
+
+    getSelectedFeatureProperties: function (selText) {
       this.mapWidget._addWorker();
       var sl = Fusion.getScriptLanguage();
-      var setSelectionScript = 'layers/' + this.arch + '/' + sl  + '/SetSelection.' + sl;
+      var getPropertiesScript = 'layers/' + this.arch + '/' + sl  + '/GetSelectionProperties.' + sl;
       var params = {
           'mapname': this.getMapName(),
           'session': this.getSessionID(),
           'selection': selText,
           'seq': Math.random()
       };
-      var options = {onSuccess: OpenLayers.Function.bind(this.processQueryResults, this, zoomTo),
-                     parameters:params, asynchronous:false};
-      Fusion.ajaxRequest(setSelectionScript, options);
+      var options = {onSuccess: OpenLayers.Function.bind(this.processSelectedFeatureProperties, this),
+                     parameters:params};
+      Fusion.ajaxRequest(getPropertiesScript, options);
     },
 
-    highlightSelection: function (selText, zoomTo) {
+    updateMapSelection: function (selText, zoomTo) {
       this.mapWidget._addWorker();
       var sl = Fusion.getScriptLanguage();
-      var highlightSelectionScript = 'layers/' + this.arch + '/' + sl  + '/HighlightSelection.' + sl;
+      var updateSelectionScript = 'layers/' + this.arch + '/' + sl  + '/SaveSelection.' + sl;
       var params = {
           'mapname': this.getMapName(),
           'session': this.getSessionID(),
           'selection': selText,
-          'seq': Math.random()
+          'seq': Math.random(),
+          'getextents' : zoomTo ? 'true' : 'false'
       };
-      var options = {onSuccess: OpenLayers.Function.bind(this.processResultsForRendering, this, zoomTo),
-                     parameters:params, asynchronous:false};
-      Fusion.ajaxRequest(highlightSelectionScript, options);
+      var options = {onSuccess: OpenLayers.Function.bind(this.renderSelection, this, zoomTo),
+                     parameters:params};
+      Fusion.ajaxRequest(updateSelectionScript, options);
     },
 
 
@@ -779,10 +803,10 @@
               onSuccess: OpenLayers.Function.bind(this.selectionCleared, this)
           };
           Fusion.ajaxRequest(s, options);
-          if (this.previousSelection != null)
-          {
-              this.previousSelection.clear();
       }
+      if (this.previousSelection != null)
+      {
+          this.previousSelection.clear();
       }
     },
 
@@ -801,7 +825,7 @@
        Call back function when select functions are called (eg queryRect)
        to handle feature attributes
     */
-    processQueryResults: function(zoomTo, r) {
+    processSelectedFeatureProperties: function(r) {
         this.mapWidget._removeWorker();
         if (r.responseText) {   //TODO: make the equivalent change to MapServer.js
             var oNode;
@@ -820,7 +844,7 @@
        Call back function when select functions are called (eg queryRect)
        to render the selection
     */
-    processResultsForRendering: function(zoomTo, r) {
+    renderSelection: function(zoomTo, r) {
         this.mapWidget._removeWorker();
         if (r.responseText) {   //TODO: make the equivalent change to MapServer.js
             var oNode;
@@ -879,9 +903,7 @@
         {
             maxFeatures = -1;
         }
-        if (options.extendSelection == true)
-        {
-            var r = new Fusion.Lib.MGRequest.MGQueryMapFeatures(this.getSessionID(),
+        var r = new Fusion.Lib.MGRequest.MGQueryMapFeatures(this.getSessionID(),
                                                                 this._sMapname,
                                                                 options.geometry,
                                                                 maxFeatures,
@@ -889,22 +911,8 @@
                                                                 options.selectionType || this.selectionType,
                                                                 options.layers,
                                                                 layerAttributeFilter);
-            var callback = OpenLayers.Function.bind(this.processAndMergeFeatureInfo, this);
-            Fusion.oBroker.dispatchRequest(r, OpenLayers.Function.bind(Fusion.xml2json, this, callback));
-        }
-        else
-        {
-            var r = new Fusion.Lib.MGRequest.MGQueryMapFeatures(this.getSessionID(),
-                                                                this._sMapname,
-                                                                options.geometry,
-                                                                maxFeatures,
-                                                                persist,
-                                                                options.selectionType || this.selectionType,
-                                                                options.layers,
-                                                                layerAttributeFilter);
-            var callback = OpenLayers.Function.bind(this.processFeatureInfo, this);
-            Fusion.oBroker.dispatchRequest(r, OpenLayers.Function.bind(Fusion.xml2json, this, callback));
-        }
+        var callback = (options.extendSelection == true) ? OpenLayers.Function.bind(this.processAndMergeFeatureInfo, this) : OpenLayers.Function.bind(this.processFeatureInfo, this);
+        Fusion.oBroker.dispatchRequest(r, OpenLayers.Function.bind(Fusion.xml2json, this, callback));
     },
 
     showLayer: function( layer, noDraw ) {
@@ -1037,47 +1045,26 @@
     },
 
 
-    processFeatureInfo: function (r)
-    {
-        eval('o='+r.responseText);
-        var newSelection = new Fusion.SimpleSelectionObject(o);
-        var selText = newSelection.getSelectionXml();
-        if(selText != "" && selText != null)
-        {
-            this.highlightSelection(selText, false);
-            this.setSelection(selText, false);
+    processAndMergeFeatureInfo: function (r) {
+        this.processSelectedFeatureInfo(r, true);
+    },
 
-            this.previousSelection = newSelection;
-    }
-        else
-        {
-            this.clearSelection();
-        }
-        this.mapWidget._removeWorker();
+    processFeatureInfo: function (r) {
+        this.processSelectedFeatureInfo(r, false);
     },
 
-    processAndMergeFeatureInfo: function (r)
-    {
-        // get the current selection
+    processSelectedFeatureInfo: function (r, mergeSelection) {
         eval('o='+r.responseText);
+
         var newSelection = new Fusion.SimpleSelectionObject(o);
-        
-        // merge the previousSelection with the currentSelection
-        newSelection.merge(this.previousSelection);
-        
-        
-        var selText = newSelection.getSelectionXml();
-        if(selText != "" && selText != null)
+        if(mergeSelection == true)
         {
-            this.highlightSelection(selText, false);
-            this.setSelection(selText, false);
-            
-            this.previousSelection = newSelection;
+            newSelection.merge(this.previousSelection);
         }
-        else
-        {
-            this.clearSelection();
-        }
+        this.previousSelection = newSelection;
+
+        var selText = newSelection.getSelectionXml();
+        this.setSelection(selText, false);
         this.mapWidget._removeWorker();
     }
 });
@@ -1111,7 +1098,7 @@
                     {
                         layer.addFeature(features[j]);
                     }
-                }    
+                }
             }
         }
         catch(e) {}
@@ -1177,7 +1164,7 @@
         }
         return xmlSelection;
     },
-    
+
     merge : function(previousSelection)
     {
         if (previousSelection != null && previousSelection.nLayers > 0)
@@ -1224,7 +1211,7 @@
             }
         }
     },
-    
+
     clear: function()
     {
         this.aLayers = [];
@@ -1266,7 +1253,7 @@
     {
         return this.nFeatures;
     },
-    
+
     removeFeatures : function (featureIndexes)
     {
         var numIndexes = featureIndexes.length;

Added: branches/fusion2-mg21/layers/MapGuide/php/GetSelectionProperties.php
===================================================================
--- branches/fusion2-mg21/layers/MapGuide/php/GetSelectionProperties.php	                        (rev 0)
+++ branches/fusion2-mg21/layers/MapGuide/php/GetSelectionProperties.php	2008-12-19 20:48:21 UTC (rev 1729)
@@ -0,0 +1,208 @@
+<?php
+/**
+ * SetSelection
+ *
+ * $Id: SetSelection.php 1664 2008-11-12 21:41:00Z madair $
+ *
+ * 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.
+ */
+
+include('Common.php');
+include('../../../common/php/Utilities.php');
+include('Utilities.php');
+
+    $selText = "";
+    GetRequestParameters();
+
+    try
+    {
+        //load the map runtime state
+        //
+        $map = new MgMap();
+        $map->Open($resourceService, $mapName);
+        // Create the selection set
+        $selection = new MgSelection($map);
+        if($selText != "") {
+            $selection->FromXml($selText);
+        }
+        
+        //now return a data struture which is the same as Query.php
+        $featureService = $siteConnection->CreateService(MgServiceType::FeatureService);
+        
+        /* Get the map SRS - we use this to convert distances */
+        $srsFactory = new MgCoordinateSystemFactory();
+        //safely get an SRS ... (in Utilities)
+        $srsDefMap = GetMapSRS($map);
+        $srsMap = $srsFactory->Create($srsDefMap);
+
+        /*holds selection array*/
+        $properties = NULL;
+        $properties->layers = array();
+
+        //process 
+        header('Content-type: text/x-json');
+        header('X-JSON: true');
+        $layers = $selection->GetLayers();
+        $nLayers = $layers->GetCount();
+        echo "/* nLayers:".$nLayers."*/";
+        for ($i=0; $i<$nLayers; $i++) {
+            $oLayer = $layers->GetItem($i);
+            $featureResId = new MgResourceIdentifier($oLayer->GetFeatureSourceId());
+            /* the class that is used for this layer will be used to select  features */
+            $class = $oLayer->GetFeatureClassName();
+
+            /* select the features */
+            $queryOptions = new MgFeatureQueryOptions();
+            
+            //TODO : seems that property mapping breaks the selection ????
+            //could it be that $selection->AddFeatures($layerObj, $featureReader, 0) is
+            //the one causing a problem when the properies are limited ?
+            $mappings = $_SESSION['property_mappings'][$oLayer->GetObjectId()];
+            if (0 && count($mappings) > 0) {
+                foreach($mappings as $name => $value) {
+                    $queryOptions->AddFeatureProperty($name);
+                    //echo "$name $value <br>\n";
+                }
+                $geomName = $oLayer->GetFeatureGeometryName();
+                $queryOptions->AddFeatureProperty($geomName);
+            }
+            
+            $filter = $selection->GenerateFilter($oLayer, $class);
+            $queryOptions->SetFilter($filter);
+            $featureReader = $featureService->SelectFeatures($featureResId, $class, $queryOptions);
+            //$featureReader = $selection->GetSelectedFeatures($oLayer, $class, true );//this doesn't seem to work but would replace much of the above code
+
+            $layerName = $oLayer->GetName();
+            array_push($properties->layers, $layerName);
+
+	    // TODO: Check if computed properties are needed?
+            $bComputedProperties = false;
+            $bNeedsTransform = false;
+            $srsLayer = NULL;
+            if ($bComputedProperties)
+            {
+		$spatialContext = $featureService->GetSpatialContexts($featureResId, true);
+		$srsLayerWkt = false;
+		if($spatialContext != null && $spatialContext->ReadNext() != null) {
+		    $srsLayerWkt = $spatialContext->GetCoordinateSystemWkt();
+		    /* skip this layer if the srs is empty */
+		}
+		if ($srsLayerWkt == null) {
+		    $srsLayerWkt = $srsDefMap;
+		}
+		/* create a coordinate system from the layer's SRS wkt */
+		$srsLayer = $srsFactory->Create($srsLayerWkt);
+
+		// exclude layer if:
+		//  the map is non-arbitrary and the layer is arbitrary or vice-versa
+		//     or
+		//  layer and map are both arbitrary but have different units
+		//
+		$bLayerSrsIsArbitrary = ($srsLayer->GetType() == MgCoordinateSystemType::Arbitrary);
+		$bMapSrsIsArbitrary = ($srsMap->GetType() == MgCoordinateSystemType::Arbitrary);
+		if (($bLayerSrsIsArbitrary != $bMapSrsIsArbitrary) ||
+		    ($bLayerSrsIsArbitrary && ($srsLayer->GetUnits() != $srsMap->GetUnits()))) {
+		    $bComputedProperties = false;
+		} else {
+		    $srsTarget = null;
+		    $srsXform = null;
+		    $bNeedsTransform = ($srsLayer->GetUnitScale() != 1.0);
+		}
+            }
+
+            $properties = BuildSelectionArray($featureReader, $layerName, $properties,
+                                              $bComputedProperties,
+                                              $srsLayer, $bNeedsTransform, $oLayer);
+            $featureReader->Close();
+        }
+        
+        $result = NULL;
+        $result->hasSelection = false;
+        if ($layers && $layers->GetCount() >= 0)
+        {
+            $result->hasSelection = true;
+            $oExtents = $selection->GetExtents($featureService);
+            if ($oExtents)
+            {
+                $oMin = $oExtents->GetLowerLeftCoordinate();
+                $oMax = $oExtents->GetUpperRightCoordinate();
+                $result->extents = NULL;
+                $result->extents->minx = $oMin->GetX();
+                $result->extents->miny = $oMin->GetY();
+                $result->extents->maxx = $oMax->GetX();
+                $result->extents->maxy = $oMax->GetY();
+
+                /*keep the full extents of the selection when saving the selection in the session*/
+                $properties->extents = NULL;
+                $properties->extents->minx = $oMin->GetX();
+                $properties->extents->miny = $oMin->GetY();
+                $properties->extents->maxx = $oMax->GetX();
+                $properties->extents->maxy = $oMax->GetY();
+            }
+            $result->layers = array();
+            for ($i=0; $i<$layers->GetCount(); $i++) {
+              $layer = $layers->GetItem($i);
+              $layerName = $layer->GetName();
+              array_push($result->layers, $layerName);
+              $layerClassName = $layer->GetFeatureClassName();
+              $result->$layerName->featureCount = $selection->GetSelectedFeaturesCount($layer, $layerClassName);
+            }
+
+            /*save selection in the session*/
+            $_SESSION['selection_array'] = $properties;
+        }
+        echo var2json($result);
+
+
+    } catch(MgException $e) {
+        echo "/* SetSelection Exception: " . $e->GetDetails()."*/";
+    }
+
+function GetParameters($params)
+{
+    global $selText;
+
+    $selText = UnescapeMagicQuotes($params['selection']);
+}
+
+
+function UnescapeMagicQuotes($str)
+{
+    if(ini_get("magic_quotes_sybase") == "1")
+        return str_replace("''", "'", $str);
+    else if(get_magic_quotes_gpc() == "1")
+    {
+        //Unescape double quotes
+        $str = str_replace('\\"', '"', $str);
+
+        //remove additional backslash
+        return str_replace("\\", "", $str);
+    }
+    return $str;
+}
+
+function GetRequestParameters()
+{
+    if($_SERVER['REQUEST_METHOD'] == "POST")
+        GetParameters($_POST);
+    else
+        GetParameters($_GET);
+}
+?>


Property changes on: branches/fusion2-mg21/layers/MapGuide/php/GetSelectionProperties.php
___________________________________________________________________
Name: svn:eol-style
   + native

Deleted: branches/fusion2-mg21/layers/MapGuide/php/HighlightSelection.php
===================================================================
--- branches/fusion2-mg21/layers/MapGuide/php/HighlightSelection.php	2008-12-19 17:52:06 UTC (rev 1728)
+++ branches/fusion2-mg21/layers/MapGuide/php/HighlightSelection.php	2008-12-19 20:48:21 UTC (rev 1729)
@@ -1,110 +0,0 @@
-<?php
-/**
- * SetSelection
- *
- * $Id: SetSelection.php 1664 2008-11-12 21:41:00Z madair $
- *
- * 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.
- */
-
-include('Common.php');
-include('../../../common/php/Utilities.php');
-include('Utilities.php');
-
-    $selText = "";
-    GetRequestParameters();
-
-    try
-    {
-        //load the map runtime state
-        //
-        $map = new MgMap();
-        $map->Open($resourceService, $mapName);
-        // Create the selection set and save it
-        $selection = new MgSelection($map);
-        if($selText != "") {
-            $selection->FromXml($selText);
-        }
-        $selection->Save($resourceService, $mapName);
-        
-        //now return a data struture which is the same as Query.php
-        
-        //process 
-        header('Content-type: text/x-json');
-        header('X-JSON: true');
-        $layers = $selection->GetLayers();
-        
-        $result = NULL;
-        $result->hasSelection = false;
-        if ($layers && $layers->GetCount() >= 0)
-        {
-            $result->hasSelection = true;
-            $result->extents = NULL;
-            
-            $result->layers = array();
-            for ($i=0; $i<$layers->GetCount(); $i++) {
-              $layer = $layers->GetItem($i);
-              $layerName = $layer->GetName();
-              array_push($result->layers, $layerName);
-              $layerClassName = $layer->GetFeatureClassName();
-              $filter = $selection->GenerateFilter($layer, $layerClassName);
-              $a = explode('OR', $filter);
-              $result->$layerName->featureCount = count($a);
-            }
-
-        }
-        echo var2json($result);
-
-
-    } catch(MgException $e) {
-        echo "/* SetSelection Exception: " . $e->GetDetails()."*/";
-    }
-
-function GetParameters($params)
-{
-    global $selText;
-
-    $selText = UnescapeMagicQuotes($params['selection']);
-}
-
-
-function UnescapeMagicQuotes($str)
-{
-    if(ini_get("magic_quotes_sybase") == "1")
-        return str_replace("''", "'", $str);
-    else if(get_magic_quotes_gpc() == "1")
-    {
-        //Unescape double quotes
-        $str = str_replace('\\"', '"', $str);
-
-        //remove additional backslash
-        return str_replace("\\", "", $str);
-    }
-    return $str;
-}
-
-function GetRequestParameters()
-{
-    if($_SERVER['REQUEST_METHOD'] == "POST")
-        GetParameters($_POST);
-    else
-        GetParameters($_GET);
-}
-?>

Added: branches/fusion2-mg21/layers/MapGuide/php/SaveSelection.php
===================================================================
--- branches/fusion2-mg21/layers/MapGuide/php/SaveSelection.php	                        (rev 0)
+++ branches/fusion2-mg21/layers/MapGuide/php/SaveSelection.php	2008-12-19 20:48:21 UTC (rev 1729)
@@ -0,0 +1,126 @@
+<?php
+/**
+ * SetSelection
+ *
+ * $Id: SetSelection.php 1664 2008-11-12 21:41:00Z madair $
+ *
+ * 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.
+ */
+
+include('Common.php');
+include('../../../common/php/Utilities.php');
+include('Utilities.php');
+
+    $selText = "";
+    $getExtents = false;
+
+    GetRequestParameters();
+
+    try
+    {
+        //load the map runtime state
+        //
+        $map = new MgMap();
+        $map->Open($resourceService, $mapName);
+        // Create the selection set and save it
+        $selection = new MgSelection($map);
+        if($selText != "") {
+            $selection->FromXml($selText);
+        }
+        $selection->Save($resourceService, $mapName);
+
+        //now return a data struture which is the same as Query.php
+
+        //process
+        header('Content-type: text/x-json');
+        header('X-JSON: true');
+        $layers = $selection->GetLayers();
+
+        $result = NULL;
+        $result->hasSelection = false;
+        if ($layers && $layers->GetCount() >= 0)
+        {
+            $result->hasSelection = true;
+            $result->extents = NULL;
+            if($getExtents)
+            {
+                $featureService = $siteConnection->CreateService(MgServiceType::FeatureService);
+                $oExtents = $selection->GetExtents($featureService);
+                if ($oExtents)
+                {
+                    $oMin = $oExtents->GetLowerLeftCoordinate();
+                    $oMax = $oExtents->GetUpperRightCoordinate();
+                    $result->extents->minx = $oMin->GetX();
+                    $result->extents->miny = $oMin->GetY();
+                    $result->extents->maxx = $oMax->GetX();
+                    $result->extents->maxy = $oMax->GetY();
+                }
+            }
+            $result->layers = array();
+            for ($i=0; $i<$layers->GetCount(); $i++)
+            {
+              $layer = $layers->GetItem($i);
+              $layerName = $layer->GetName();
+              array_push($result->layers, $layerName);
+              $layerClassName = $layer->GetFeatureClassName();
+              $result->$layerName->featureCount = $selection->GetSelectedFeaturesCount($layer, $layerClassName);
+            }
+        }
+
+        echo var2json($result);
+
+
+    } catch(MgException $e) {
+        echo "/* SetSelection Exception: " . $e->GetDetails()."*/";
+    }
+
+function GetParameters($params)
+{
+    global $selText;
+    global $getExtents;
+
+    $selText = UnescapeMagicQuotes($params['selection']);
+    $getExtents = ($params['getextents'] == "true") ? true : false;
+}
+
+
+function UnescapeMagicQuotes($str)
+{
+    if(ini_get("magic_quotes_sybase") == "1")
+        return str_replace("''", "'", $str);
+    else if(get_magic_quotes_gpc() == "1")
+    {
+        //Unescape double quotes
+        $str = str_replace('\\"', '"', $str);
+
+        //remove additional backslash
+        return str_replace("\\", "", $str);
+    }
+    return $str;
+}
+
+function GetRequestParameters()
+{
+    if($_SERVER['REQUEST_METHOD'] == "POST")
+        GetParameters($_POST);
+    else
+        GetParameters($_GET);
+}
+?>


Property changes on: branches/fusion2-mg21/layers/MapGuide/php/SaveSelection.php
___________________________________________________________________
Name: svn:eol-style
   + native

Deleted: branches/fusion2-mg21/layers/MapGuide/php/SetSelection.php
===================================================================
--- branches/fusion2-mg21/layers/MapGuide/php/SetSelection.php	2008-12-19 17:52:06 UTC (rev 1728)
+++ branches/fusion2-mg21/layers/MapGuide/php/SetSelection.php	2008-12-19 20:48:21 UTC (rev 1729)
@@ -1,208 +0,0 @@
-<?php
-/**
- * SetSelection
- *
- * $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.
- */
-
-include('Common.php');
-include('../../../common/php/Utilities.php');
-include('Utilities.php');
-
-    $selText = "";
-    GetRequestParameters();
-
-    try
-    {
-        //load the map runtime state
-        //
-        $map = new MgMap();
-        $map->Open($resourceService, $mapName);
-        // Create the selection set
-        $selection = new MgSelection($map);
-        if($selText != "") {
-            $selection->FromXml($selText);
-        }
-        
-        //now return a data struture which is the same as Query.php
-        $featureService = $siteConnection->CreateService(MgServiceType::FeatureService);
-        
-        /* Get the map SRS - we use this to convert distances */
-        $srsFactory = new MgCoordinateSystemFactory();
-        //safely get an SRS ... (in Utilities)
-        $srsDefMap = GetMapSRS($map);
-        $srsMap = $srsFactory->Create($srsDefMap);
-
-        /*holds selection array*/
-        $properties = NULL;
-        $properties->layers = array();
-
-        //process 
-        header('Content-type: text/x-json');
-        header('X-JSON: true');
-        $layers = $selection->GetLayers();
-        $nLayers = $layers->GetCount();
-        echo "/* nLayers:".$nLayers."*/";
-        for ($i=0; $i<$nLayers; $i++) {
-            $oLayer = $layers->GetItem($i);
-            $featureResId = new MgResourceIdentifier($oLayer->GetFeatureSourceId());
-            /* the class that is used for this layer will be used to select  features */
-            $class = $oLayer->GetFeatureClassName();
-
-            /* select the features */
-            $queryOptions = new MgFeatureQueryOptions();
-            
-            //TODO : seems that property mapping breaks the selection ????
-            //could it be that $selection->AddFeatures($layerObj, $featureReader, 0) is
-            //the one causing a problem when the properies are limited ?
-            $mappings = $_SESSION['property_mappings'][$oLayer->GetObjectId()];
-            if (0 && count($mappings) > 0) {
-                foreach($mappings as $name => $value) {
-                    $queryOptions->AddFeatureProperty($name);
-                    //echo "$name $value <br>\n";
-                }
-                $geomName = $oLayer->GetFeatureGeometryName();
-                $queryOptions->AddFeatureProperty($geomName);
-            }
-            
-            $filter = $selection->GenerateFilter($oLayer, $class);
-            $queryOptions->SetFilter($filter);
-            $featureReader = $featureService->SelectFeatures($featureResId, $class, $queryOptions);
-            //$featureReader = $selection->GetSelectedFeatures($oLayer, $class, true );//this doesn't seem to work but would replace much of the above code
-
-            $layerName = $oLayer->GetName();
-            array_push($properties->layers, $layerName);
-
-	    // TODO: Check if computed properties are needed?
-            $bComputedProperties = false;
-            $bNeedsTransform = false;
-            $srsLayer = NULL;
-            if ($bComputedProperties)
-            {
-		$spatialContext = $featureService->GetSpatialContexts($featureResId, true);
-		$srsLayerWkt = false;
-		if($spatialContext != null && $spatialContext->ReadNext() != null) {
-		    $srsLayerWkt = $spatialContext->GetCoordinateSystemWkt();
-		    /* skip this layer if the srs is empty */
-		}
-		if ($srsLayerWkt == null) {
-		    $srsLayerWkt = $srsDefMap;
-		}
-		/* create a coordinate system from the layer's SRS wkt */
-		$srsLayer = $srsFactory->Create($srsLayerWkt);
-
-		// exclude layer if:
-		//  the map is non-arbitrary and the layer is arbitrary or vice-versa
-		//     or
-		//  layer and map are both arbitrary but have different units
-		//
-		$bLayerSrsIsArbitrary = ($srsLayer->GetType() == MgCoordinateSystemType::Arbitrary);
-		$bMapSrsIsArbitrary = ($srsMap->GetType() == MgCoordinateSystemType::Arbitrary);
-		if (($bLayerSrsIsArbitrary != $bMapSrsIsArbitrary) ||
-		    ($bLayerSrsIsArbitrary && ($srsLayer->GetUnits() != $srsMap->GetUnits()))) {
-		    $bComputedProperties = false;
-		} else {
-		    $srsTarget = null;
-		    $srsXform = null;
-		    $bNeedsTransform = ($srsLayer->GetUnitScale() != 1.0);
-		}
-            }
-
-            $properties = BuildSelectionArray($featureReader, $layerName, $properties,
-                                              $bComputedProperties,
-                                              $srsLayer, $bNeedsTransform, $oLayer);
-            $featureReader->Close();
-        }
-        
-        $result = NULL;
-        $result->hasSelection = false;
-        if ($layers && $layers->GetCount() >= 0)
-        {
-            $result->hasSelection = true;
-            $oExtents = $selection->GetExtents($featureService);
-            if ($oExtents)
-            {
-                $oMin = $oExtents->GetLowerLeftCoordinate();
-                $oMax = $oExtents->GetUpperRightCoordinate();
-                $result->extents = NULL;
-                $result->extents->minx = $oMin->GetX();
-                $result->extents->miny = $oMin->GetY();
-                $result->extents->maxx = $oMax->GetX();
-                $result->extents->maxy = $oMax->GetY();
-
-                /*keep the full extents of the selection when saving the selection in the session*/
-                $properties->extents = NULL;
-                $properties->extents->minx = $oMin->GetX();
-                $properties->extents->miny = $oMin->GetY();
-                $properties->extents->maxx = $oMax->GetX();
-                $properties->extents->maxy = $oMax->GetY();
-            }
-            $result->layers = array();
-            for ($i=0; $i<$layers->GetCount(); $i++) {
-              $layer = $layers->GetItem($i);
-              $layerName = $layer->GetName();
-              array_push($result->layers, $layerName);
-              $layerClassName = $layer->GetFeatureClassName();
-              $result->$layerName->featureCount = $selection->GetSelectedFeaturesCount($layer, $layerClassName);
-            }
-
-            /*save selection in the session*/
-            $_SESSION['selection_array'] = $properties;
-        }
-        echo var2json($result);
-
-
-    } catch(MgException $e) {
-        echo "/* SetSelection Exception: " . $e->GetDetails()."*/";
-    }
-
-function GetParameters($params)
-{
-    global $selText;
-
-    $selText = UnescapeMagicQuotes($params['selection']);
-}
-
-
-function UnescapeMagicQuotes($str)
-{
-    if(ini_get("magic_quotes_sybase") == "1")
-        return str_replace("''", "'", $str);
-    else if(get_magic_quotes_gpc() == "1")
-    {
-        //Unescape double quotes
-        $str = str_replace('\\"', '"', $str);
-
-        //remove additional backslash
-        return str_replace("\\", "", $str);
-    }
-    return $str;
-}
-
-function GetRequestParameters()
-{
-    if($_SERVER['REQUEST_METHOD'] == "POST")
-        GetParameters($_POST);
-    else
-        GetParameters($_GET);
-}
-?>



More information about the fusion-commits mailing list