[fusion-commits] r2877 - trunk/widgets/Redline/classes

svn_fusion at osgeo.org svn_fusion at osgeo.org
Tue Sep 23 23:08:12 PDT 2014


Author: jng
Date: 2014-09-23 23:08:12 -0700 (Tue, 23 Sep 2014)
New Revision: 2877

Modified:
   trunk/widgets/Redline/classes/markupmanager.php
Log:
#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: trunk/widgets/Redline/classes/markupmanager.php
===================================================================
--- trunk/widgets/Redline/classes/markupmanager.php	2014-09-14 12:10:30 UTC (rev 2876)
+++ trunk/widgets/Redline/classes/markupmanager.php	2014-09-24 06:08:12 UTC (rev 2877)
@@ -713,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
@@ -796,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");
 
@@ -823,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();
@@ -841,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"));
@@ -904,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);
                     }



More information about the fusion-commits mailing list