[fusion-commits] r2879 - in sandbox/adsk/2.6l: layers/MapGuide widgets/Redline/classes

svn_fusion at osgeo.org svn_fusion at osgeo.org
Wed Sep 24 19:12:23 PDT 2014


Author: liuar
Date: 2014-09-24 19:12:23 -0700 (Wed, 24 Sep 2014)
New Revision: 2879

Modified:
   sandbox/adsk/2.6l/layers/MapGuide/MapGuide.js
   sandbox/adsk/2.6l/widgets/Redline/classes/markupmanager.php
Log:
Merged revision(s) 2877 from trunk:
#626: Fix KML/KMZ downloads being useless when map CS is not LL84. This fixes the following issues:
 - The bounding box that's passed to MgKmlService::GetFeaturesKml must be in LL84. So if we encounter a non-LL84 bounding box, it must be transformed to LL84 before invoking GetFeaturesKml. The API documentation failed to state this fact and should be updated as well.
 - When creating a SHP feature source, nothing is exported due to a possible bug in CreateFeatureSource() that results in a blank .prj file in the created feature source. This naturally interferes with our need to transform data to LL84 for KML export. We already worked around this for native export (by creating the required .prj file using the map's coordinate system WKT), so we apply the same workaround here.
 - Several deprecated MgMap constructor usages are still being used.



Modified: sandbox/adsk/2.6l/layers/MapGuide/MapGuide.js
===================================================================
--- sandbox/adsk/2.6l/layers/MapGuide/MapGuide.js	2014-09-24 06:11:25 UTC (rev 2878)
+++ sandbox/adsk/2.6l/layers/MapGuide/MapGuide.js	2014-09-25 02:12:23 UTC (rev 2879)
@@ -373,7 +373,7 @@
                     displayInLegend: (lyr.DisplayInLegend[0] == "true"),
                     expandInLegend: (lyr.ExpandInLegend[0] == "true")
                 };
-                if (lyr.Type[0] != 2 && !lm.hasDynamicLayers)
+                if (lyr.Type[0] != "2" && !lm.hasDynamicLayers)
                     lm.hasDynamicLayers = true;
                 lm.layers.push(cl);
                 
@@ -1751,6 +1751,7 @@
             
             for (var i = 0; i < selLayers.length; i++) {
                 var selLayer = selLayers[i];
+                var selFeatures = selLayer.Feature || [];
                 var layerName = selLayer["@name"];
                 if (!result[layerName]) {
                     if (selLayer.LayerMetadata) {
@@ -1768,7 +1769,7 @@
                     result[layerName] = {
                         metadata: [],  //NOTE: Probably a defect, but regular code path is putting blank string arrays here too
                         metadatanames: ["dimension", "bbox", "center", "area", "length"],
-                        numelements: selLayer.Feature.length,
+                        numelements: selFeatures.length,
                         propertynames: pnames,
                         propertytypes: ptypes,
                         propertyvalues: pvals,
@@ -1777,8 +1778,8 @@
                     layerNames.push(layerName);
                 }
                 
-                for (var j = 0; j < selLayer.Feature.length; j++) {
-                    var feat = selLayer.Feature[j];
+                for (var j = 0; j < selFeatures.length; j++) {
+                    var feat = selFeatures[j];
                     var featVals = [];
                     if (feat.Property) {
                         for (var k = 0; k < feat.Property.length; k++) {

Modified: sandbox/adsk/2.6l/widgets/Redline/classes/markupmanager.php
===================================================================
--- sandbox/adsk/2.6l/widgets/Redline/classes/markupmanager.php	2014-09-24 06:11:25 UTC (rev 2878)
+++ sandbox/adsk/2.6l/widgets/Redline/classes/markupmanager.php	2014-09-25 02:12:23 UTC (rev 2879)
@@ -344,8 +344,8 @@
     {
         $resourceService = $this->site->CreateService(MgServiceType::ResourceService);
 
-        $map = new MgMap();
-        $map->Open($resourceService, $this->args['MAPNAME']);
+        $map = new MgMap($this->site);
+        $map->Open($this->args['MAPNAME']);
 
         // Create the Layer Groups
 
@@ -375,23 +375,21 @@
         $markupLayer->SetGroup($markupGroup);
         $map->GetLayers()->Insert(0, $markupLayer);
 
-        $map->Save($resourceService);
+        $map->Save();
     }
 
     function CloseMarkup()
     {
-        $resourceService = $this->site->CreateService(MgServiceType::ResourceService);
+        $map = new MgMap($this->site);
+        $map->Open($this->args['MAPNAME']);
 
-        $map = new MgMap();
-        $map->Open($resourceService, $this->args['MAPNAME']);
-
         // Add the Markup Layer
 
         $markupLayerResId = new MgResourceIdentifier($this->args['OPENMARKUP']);
         $index = $map->GetLayers()->IndexOf('_' . $markupLayerResId->GetName());
         $map->GetLayers()->RemoveAt($index);
 
-        $map->Save($resourceService);
+        $map->Save();
     }
 
     function UniqueMarkupName(&$markupName)
@@ -695,8 +693,8 @@
         $resourceService = $this->site->CreateService(MgServiceType::ResourceService);
         $featureService = $this->site->CreateService(MgServiceType::FeatureService);
 
-        $map = new MgMap();
-        $map->Open($resourceService, $this->args['MAPNAME']);
+        $map = new MgMap($this->site);
+        $map->Open($this->args['MAPNAME']);
 
         $featureSourceId = "";
         $bUpdate = array_key_exists("EDITMARKUPLAYER", $this->args) && array_key_exists("MARKUPLAYERNAME", $this->args) && array_key_exists("EDITFEATURESOURCE", $this->args);
@@ -715,6 +713,44 @@
             }
             $fsParams = new MgFileFeatureSourceParams($this->args["MARKUPFDOPROVIDER"], 'Default', $map->GetMapSRS(), $markupSchema);
             $featureService->CreateFeatureSource($markupFsId, $fsParams);
+            //HACK: There must be some defect in MgFeatureService::CreateFeatureSource() for SHP
+            //files or the FDO provider, because even if we plug in a coord sys WKT when we create
+            //it, we get a blank prj file.
+            //
+            //As a workaround, create the required prj file using the map's SRS if we encounter an empty prj file
+            //
+            //That's what we were already doing when we called MgFeatureService::CreateFeatureSource(), but it
+            //or the provider didn't like it.
+            if ($fsParams->GetProviderName() == "OSGeo.SHP")
+            {
+                $dataList = $resourceService->EnumerateResourceData($markupFsId);
+                $doc = new DOMDocument();
+                $doc->loadXML($dataList->ToString());
+                $dataItems = $doc->getElementsByTagName("Name");
+                //Copy out all data files to a temp location
+                for ($i = 0; $i < $dataItems->length; $i++) {
+                    $dataName = $dataItems->item($i)->nodeValue;
+                    $dataNorm = strtolower($dataName);
+                    if ( substr( $dataNorm, strlen( $dataNorm ) - strlen( "prj" ) ) == "prj" ) {
+                        $byteReader = $resourceService->GetResourceData($markupFsId, $dataName);
+                        //Sink to temp file
+                        $tmpSink = new MgByteSink($byteReader);
+                        $fileName = tempnam(sys_get_temp_dir(), $dataName);
+                        $tmpSink->ToFile($fileName);
+                        $content = file_get_contents($fileName);
+                        if (strlen($content) == 0) {
+                            $content = $map->GetMapSRS();
+                            file_put_contents($fileName, $content);
+                            //Put new prj file back into SHP Feature Source
+                            $prjBs = new MgByteSource($fileName);
+                            $prjBr = $prjBs->GetReader();
+                            $resourceService->SetResourceData($markupFsId, $dataName, MgResourceDataType::File, $prjBr);
+                        }
+                        @unlink($fileName);
+                        break;
+                    }
+                }
+            }
             $featureSourceId = $markupFsId->ToString();
         }
         else
@@ -798,8 +834,8 @@
         $kmlService = $this->site->CreateService(MgServiceType::KmlService);
         $resourceService = $this->site->CreateService(MgServiceType::ResourceService);
 
-        $map = new MgMap();
-        $map->Open($resourceService, $this->args['MAPNAME']);
+        $map = new MgMap($this->site);
+        $map->Open($this->args['MAPNAME']);
         $markupLayerResId = new MgResourceIdentifier($this->args['MARKUPLAYER']);
         $downloadName = $markupLayerResId->GetName().".".($kmz ? "kmz" : "kml");
 
@@ -825,10 +861,13 @@
         $geomFact = new MgGeometryFactory();
         $csFactory = new MgCoordinateSystemFactory();
         $metersPerUnit = 1.0;
+        $transform = null;
         if ($map->GetMapSRS() != null)
         {
             $mapCs = $csFactory->Create($map->GetMapSRS());
             $metersPerUnit = $mapCs->ConvertCoordinateSystemUnitsToMeters(1.0);
+            $llCs = $csFactory->CreateFromCode("LL84");
+            $transform = $csFactory->GetTransform($mapCs, $llCs);
         }
         $mapScale = $map->GetViewScale();
         $devW = $map->GetDisplayWidth();
@@ -843,6 +882,12 @@
         $coord0 = $geomFact->CreateCoordinateXY($coord->GetX() - 0.5 * $mcsW, $coord->GetY() - 0.5 * $mcsH);
         $coord1 = $geomFact->CreateCoordinateXY($coord->GetX() + 0.5 * $mcsW, $coord->GetY() + 0.5 * $mcsH);
         $bbox = new MgEnvelope($coord0, $coord1);
+        
+        //The bbox has to be in LL84
+        if ($transform != NULL)
+        {
+            $bbox = $bbox->Transform($transform);
+        }
 
         //Call the service API
         $br = $kmlService->GetFeaturesKml($markupLayer, $bbox, $devW, $devH, $mapDpi, 0, ($kmz ? "KMZ" : "KML"));
@@ -906,8 +951,8 @@
                 if ( substr( $dataNorm, strlen( $dataNorm ) - strlen( "prj" ) ) == "prj" ) {
                     $content = file_get_contents($filePath);
                     if (strlen($content) == 0) {
-                        $map = new MgMap();
-                        $map->Open($resourceService, $this->args['MAPNAME']);
+                        $map = new MgMap($this->site);
+                        $map->Open($this->args['MAPNAME']);
                         $content = $map->GetMapSRS();
                         file_put_contents($filePath, $content);
                     }
@@ -1028,6 +1073,9 @@
         if (strcmp($fdoProvider, "OSGeo.SDF") == 0) { //Need to set ReadOnly = false for SDF
             $extraXml = "<Parameter><Name>ReadOnly</Name><Value>FALSE</Value></Parameter>";
         }
+        else if (strcmp($fdoProvider, "OSGeo.SQLite") == 0) { //Need to set UseFdoMetadata = true for SQLite
+            $extraXml = "<Parameter><Name>UseFdoMetadata</Name><Value>TRUE</Value></Parameter>";
+        }
         $fsXml = sprintf(file_get_contents("templates/markupfeaturesource.xml"), $fdoProvider, $fileParam, $dataName, $extraXml);
         $bs2 = new MgByteSource($fsXml, strlen($fsXml));
         $resourceService->SetResource($markupFsId, $bs2->GetReader(), null);
@@ -1135,11 +1183,9 @@
     {
         $openMarkup = array();
 
-        $resourceService = $this->site->CreateService(MgServiceType::ResourceService);
+        $map = new MgMap($this->site);
+        $map->Open($this->args['MAPNAME']);
 
-        $map = new MgMap();
-        $map->Open($resourceService, $this->args['MAPNAME']);
-
         $layerGroups = $map->GetLayerGroups();
         if ($layerGroups->Contains('_Markup'))
         {



More information about the fusion-commits mailing list