[fusion-commits] r2745 - sandbox/adsk/2.4j/layers/MapGuide/php

svn_fusion at osgeo.org svn_fusion at osgeo.org
Tue Jul 16 23:25:16 PDT 2013


Author: liuar
Date: 2013-07-16 23:25:16 -0700 (Tue, 16 Jul 2013)
New Revision: 2745

Modified:
   sandbox/adsk/2.4j/layers/MapGuide/php/GetSelectionProperties.php
Log:
Integrate #2715 to sandbox/adsk/2.4j.

Fix GetSelectionProperties.php on empty or bad selection XML. 

Modified: sandbox/adsk/2.4j/layers/MapGuide/php/GetSelectionProperties.php
===================================================================
--- sandbox/adsk/2.4j/layers/MapGuide/php/GetSelectionProperties.php	2013-07-12 06:15:10 UTC (rev 2744)
+++ sandbox/adsk/2.4j/layers/MapGuide/php/GetSelectionProperties.php	2013-07-17 06:25:16 UTC (rev 2745)
@@ -65,121 +65,123 @@
         header('Content-type: application/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();
+        $result = NULL;
+        if ($layers != null)
+        {
+            $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();
+                /* 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 ?
-            if (isset($_SESSION['property_mappings']) && isset($_SESSION['property_mappings'][$oLayer->GetObjectId()])) {
-                $mappings = $_SESSION['property_mappings'][$oLayer->GetObjectId()];                
-				if (count($mappings) > 0) {
-                    foreach($mappings as $name => $value) {
-                        $queryOptions->AddFeatureProperty($name);
-                        //echo "$name $value <br>\n";
+                //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 ?
+                if (isset($_SESSION['property_mappings']) && isset($_SESSION['property_mappings'][$oLayer->GetObjectId()])) {
+                    $mappings = $_SESSION['property_mappings'][$oLayer->GetObjectId()];                
+                    if (count($mappings) > 0) {
+                        foreach($mappings as $name => $value) {
+                            $queryOptions->AddFeatureProperty($name);
+                            //echo "$name $value <br>\n";
+                        }
                     }
                 }
-            }
-			
-			//Add geometry property in all cases.
-			$geomName = $oLayer->GetFeatureGeometryName();
-			$queryOptions->AddFeatureProperty($geomName);
+                
+                //Add geometry property in all cases.
+                $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
+                $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);
+                $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);
+                // 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);
-        }
+                    // 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, true);
+                $featureReader->Close();
             }
+            $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();
 
-            $properties = BuildSelectionArray($featureReader, $layerName, $properties,
-                                              $bComputedProperties,
-                                              $srsLayer, $bNeedsTransform, $oLayer, true);
-            $featureReader->Close();
-        }
+                    /*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);
+                }
 
-        $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();
+                /*save selection in the session*/
+                $_SESSION['selection_array'] = $properties;
             }
-            $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);
+        } else {
+            $result->hasSelection = false;
         }
-        echo var2json($result);
-
-
     } catch(MgException $e) {
         echo "ERROR: " . $e->GetDetails() . "\n";
     }



More information about the fusion-commits mailing list