[fusion-commits] r2661 - in trunk: text widgets/Redline widgets/Redline/classes

svn_fusion at osgeo.org svn_fusion at osgeo.org
Fri Mar 8 06:31:55 PST 2013


Author: jng
Date: 2013-03-08 06:31:54 -0800 (Fri, 08 Mar 2013)
New Revision: 2661

Modified:
   trunk/text/en
   trunk/widgets/Redline/classes/markupcommand.php
   trunk/widgets/Redline/classes/markupmanager.php
   trunk/widgets/Redline/markupmain.php
Log:
#553: Add KML/KMZ output formats for open redline layers. This uses the existing KML service APIs to do the grunt work.

Modified: trunk/text/en
===================================================================
--- trunk/text/en	2013-03-08 13:49:24 UTC (rev 2660)
+++ trunk/text/en	2013-03-08 14:31:54 UTC (rev 2661)
@@ -225,8 +225,11 @@
 REDLINEREFRESH          = Refresh List
 REDLINEEDIT             = Add/Edit Redlines
 REDLINEREMOVEFROMMAP    = Remove From Map
-REDLINEDOWNLOADSDF      = Download Data
-REDLINEUPLOADSDF        = Upload Redline
+REDLINEDOWNLOADOPTIONS  = Download Options
+REDLINEDOWNLOAD         = Download Data
+REDLINEDOWNLOADKML      = Download KML
+REDLINEDOWNLOADKMZ      = Download KMZ
+REDLINEUPLOAD           = Upload Redline
 REDLINEOTHEROPTIONS     = Other Options
 REDLINEEDITSTYLE        = Edit Style
 REDLINECREATEFAILURE    = Failed to create redline

Modified: trunk/widgets/Redline/classes/markupcommand.php
===================================================================
--- trunk/widgets/Redline/classes/markupcommand.php	2013-03-08 13:49:24 UTC (rev 2660)
+++ trunk/widgets/Redline/classes/markupcommand.php	2013-03-08 14:31:54 UTC (rev 2661)
@@ -14,6 +14,8 @@
     const Upload        = 10;
     const EditStyle     = 11;
     const DownloadDataFromLayer = 12;
+    const DownloadLayerKml = 13;
+    const DownloadLayerKmz = 14;
 }
 
 ?>
\ No newline at end of file

Modified: trunk/widgets/Redline/classes/markupmanager.php
===================================================================
--- trunk/widgets/Redline/classes/markupmanager.php	2013-03-08 13:49:24 UTC (rev 2660)
+++ trunk/widgets/Redline/classes/markupmanager.php	2013-03-08 14:31:54 UTC (rev 2661)
@@ -485,6 +485,70 @@
         $res = $featureService->UpdateFeatures($this->markupRegistryId, $cmds, false);
     }
 
+    function DownloadMarkupAsKml($kmz = false)
+    {
+        $kmlService = $this->site->CreateService(MgServiceType::KmlService);
+        $resourceService = $this->site->CreateService(MgServiceType::ResourceService);
+
+        $map = new MgMap();
+        $map->Open($resourceService, $this->args['MAPNAME']);
+        $markupLayerResId = new MgResourceIdentifier($this->args['MARKUPLAYER']);
+        $downloadName = $markupLayerResId->GetName().".".($kmz ? "kmz" : "kml");
+
+        //Find layer under _Markup with this layer def id
+        $layerGroups = $map->GetLayerGroups();
+        if (!$layerGroups->Contains("_Markup")) {
+            throw new Exception(GetLocalizedString("REDLINENOOPENLAYERS", $locale));
+        }
+        $layers = $map->GetLayers();
+        $markupLayer = null;
+        for ($i = 0; $i < $layers->GetCount(); $i++) {
+            $layer = $layers->GetItem($i);
+            $ldfId = $layer->GetLayerDefinition();
+            if (strcmp($ldfId->ToString(), $markupLayerResId->ToString()) == 0) {
+                $markupLayer = $layer;
+                break;
+            }
+        }
+        if ($markupLayer == null)
+            throw new Exception(GetLocalizedString("REDLINEOPENLAYERNOTFOUND", $locale));
+
+        //View extent crunching time
+        $geomFact = new MgGeometryFactory();
+        $csFactory = new MgCoordinateSystemFactory();
+        $mapCs = $csFactory->Create($map->GetMapSRS());
+        $metersPerUnit = $mapCs->ConvertCoordinateSystemUnitsToMeters(1.0);
+        $mapScale = $map->GetViewScale();
+        $devW = $map->GetDisplayWidth();
+        $devH = $map->GetDisplayHeight();
+        $mapDpi = $map->GetDisplayDpi();
+        $metersPerPixel = 0.0254 / $mapDpi;
+        $mcsW = $mapScale * $devW * $metersPerPixel / $metersPerUnit;
+        $mcsH = $mapScale * $devH * $metersPerPixel / $metersPerUnit;
+
+        $center = $map->GetViewCenter();
+        $coord = $center->GetCoordinate();
+        $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);
+
+        //Call the service API
+        $br = $kmlService->GetFeaturesKml($markupLayer, $bbox, $devW, $devH, $mapDpi, 0, ($kmz ? "KMZ" : "KML"));
+        $len = $br->GetLength();
+
+        $outputBuffer = '';
+        $buffer = '';
+        while ($br->Read($buffer, 50000) != 0)
+        {
+            $outputBuffer .= $buffer;
+        }
+
+        header("Content-Type: application/octet-stream");
+        header("Content-Disposition: attachment; filename=$downloadName");
+        header("Content-Length: " . strlen($outputBuffer));
+        echo $outputBuffer;
+    }
+
     function DownloadMarkup()
     {
         $resourceService = $this->site->CreateService(MgServiceType::ResourceService);

Modified: trunk/widgets/Redline/markupmain.php
===================================================================
--- trunk/widgets/Redline/markupmain.php	2013-03-08 13:49:24 UTC (rev 2660)
+++ trunk/widgets/Redline/markupmain.php	2013-03-08 14:31:54 UTC (rev 2661)
@@ -62,6 +62,16 @@
                 $markupManager->SetArgument("MARKUPLAYER", $args["OPENMARKUP"]);
                 $markupManager->DownloadMarkup();
                 break;
+            case MarkupCommand::DownloadLayerKml:
+                //The opened markup layer is the one we want to download
+                $markupManager->SetArgument("MARKUPLAYER", $args["OPENMARKUP"]);
+                $markupManager->DownloadMarkupAsKml(false);
+                break;
+            case MarkupCommand::DownloadLayerKmz:
+                //The opened markup layer is the one we want to download
+                $markupManager->SetArgument("MARKUPLAYER", $args["OPENMARKUP"]);
+                $markupManager->DownloadMarkupAsKml(true);
+                break;
             }
         }
 
@@ -83,8 +93,8 @@
         $refreshLocal = GetLocalizedString('REDLINEREFRESH', $locale );
         $addEditLocal = GetLocalizedString('REDLINEEDIT', $locale );
         $removeFromMapLocal = GetLocalizedString('REDLINEREMOVEFROMMAP', $locale );
-        $downloadLocal = GetLocalizedString('REDLINEDOWNLOADSDF', $locale );
-        $uploadLocal = GetLocalizedString('REDLINEUPLOADSDF', $locale );
+        $downloadLocal = GetLocalizedString('REDLINEDOWNLOAD', $locale );
+        $uploadLocal = GetLocalizedString('REDLINEUPLOAD', $locale );
         $editStyleLocal = GetLocalizedString('REDLINEEDITSTYLE', $locale );
         $redlineCreateFailureLocal = GetLocalizedString('REDLINECREATEFAILURE', $locale );
         $redlineLayerNameLocal = GetLocalizedString('REDLINENAME', $locale);
@@ -93,6 +103,9 @@
         $lineLocal = GetLocalizedString("REDLINELINE", $locale);
         $polyLocal = GetLocalizedString("REDLINEPOLY", $locale);
         $otherOptionsLocal = GetLocalizedString("REDLINEOTHEROPTIONS", $locale);
+        $downloadOptionsLocal = GetLocalizedString("REDLINEDOWNLOADOPTIONS", $locale);
+        $downloadKmlLocal = GetLocalizedString("REDLINEDOWNLOADKML", $locale);
+        $downloadKmzLocal = GetLocalizedString("REDLINEDOWNLOADKMZ", $locale);
     }
     catch (MgException $mge)
     {
@@ -134,6 +147,8 @@
         var CMD_UPLOAD = <?= MarkupCommand::Upload ?>;
         var CMD_EDITSTYLE = <?= MarkupCommand::EditStyle ?>;
         var CMD_DOWNLOAD_LAYER_DATA = <?= MarkupCommand::DownloadDataFromLayer ?>;
+        var CMD_DOWNLOAD_KML = <?= MarkupCommand::DownloadLayerKml ?>;
+        var CMD_DOWNLOAD_KMZ = <?= MarkupCommand::DownloadLayerKmz ?>;
 
         function GetGeometryTypes()
         {
@@ -267,6 +282,8 @@
             var closeBtn = document.getElementById("closeBtn");
             var editStyleBtn = document.getElementById("editStyleBtn");
             var downloadDataBtn = document.getElementById("downloadDataBtn");
+            var downloadKmlBtn = document.getElementById("downloadKmlBtn");
+            var downloadKmzBtn = document.getElementById("downloadKmzBtn");
 
             if (openSelect.options.length > 0 && openSelect.selectedIndex >= 0)
             {
@@ -274,6 +291,8 @@
                 closeBtn.disabled = false;
                 editStyleBtn.disabled = false;
                 downloadDataBtn.disabled = false;
+                downloadKmlBtn.disabled = false;
+                downloadKmzBtn.disabled = false;
             }
             else
             {
@@ -281,6 +300,8 @@
                 closeBtn.disabled = true;
                 editStyleBtn.disabled = true;
                 downloadDataBtn.disabled = true;
+                downloadKmlBtn.disabled = true;
+                downloadKmzBtn.disabled = true;
             }
 
             if (openSelect.options.length > 0) {
@@ -330,9 +351,9 @@
     </tr>
     <tr>
         <td>
-            <input class="Ctrl" type="button" id="newSdfBtn" onClick="SubmitCommand(CMD_NEW_SDF)" value="<?=$newSdfLocal?>" style="width:85px">
-            <input class="Ctrl" type="button" id="newShpBtn" onClick="SubmitCommand(CMD_NEW_SHP)" value="<?=$newShpLocal?>" style="width:85px">
-            <input class="Ctrl" type="button" id="newSqliteBtn" onClick="SubmitCommand(CMD_NEW_SQLITE)" value="<?=$newSqliteLocal?>" style="width:85px">
+            <input class="Ctrl" type="button" id="newSdfBtn" onClick="SubmitCommand(CMD_NEW_SDF)" value="<?=$newSdfLocal?>" style="width:95px">
+            <input class="Ctrl" type="button" id="newShpBtn" onClick="SubmitCommand(CMD_NEW_SHP)" value="<?=$newShpLocal?>" style="width:95px">
+            <input class="Ctrl" type="button" id="newSqliteBtn" onClick="SubmitCommand(CMD_NEW_SQLITE)" value="<?=$newSqliteLocal?>" style="width:95px">
         </td>
     </tr>
     <tr><td class="SubTitle"><?=$availableLayersLocal?></td></tr>
@@ -353,17 +374,17 @@
     </tr>
     <tr>
         <td>
-            <input class="Ctrl" type="button" id="openBtn" onClick="SubmitCommand(CMD_OPEN)" value="<?=$addToMapLocal?>" style="width:85px">
-            <input class="Ctrl" type="button" id="deleteBtn" onClick="SubmitCommand(CMD_DELETE)" value="<?=$deleteLocal?>" style="width:85px">
-            <input class="Ctrl" type="button" id="downloadBtn" onClick="SubmitCommand(CMD_DOWNLOAD)" value="<?=$downloadLocal?>" style="width:85px">
+            <input class="Ctrl" type="button" id="openBtn" onClick="SubmitCommand(CMD_OPEN)" value="<?=$addToMapLocal?>" style="width:95px">
+            <input class="Ctrl" type="button" id="deleteBtn" onClick="SubmitCommand(CMD_DELETE)" value="<?=$deleteLocal?>" style="width:95px">
+            <input class="Ctrl" type="button" id="downloadBtn" onClick="SubmitCommand(CMD_DOWNLOAD)" value="<?=$downloadLocal?>" style="width:95px">
             <br><br>
         </td>
     </tr>
     <tr><td class="SubTitle"><?=$otherOptionsLocal?></td></tr>
     <tr>
         <td>
-            <input class="Ctrl" type="button" id="refreshBtn" onClick="SubmitCommand(CMD_REFRESH)" value="<?=$refreshLocal?>" style="width:85px">
-            <input class="Ctrl" type="button" id="uploadBtn" onClick="SubmitCommand(CMD_UPLOAD)" value="<?=$uploadLocal?>" style="width:85px">
+            <input class="Ctrl" type="button" id="refreshBtn" onClick="SubmitCommand(CMD_REFRESH)" value="<?=$refreshLocal?>" style="width:95px">
+            <input class="Ctrl" type="button" id="uploadBtn" onClick="SubmitCommand(CMD_UPLOAD)" value="<?=$uploadLocal?>" style="width:95px">
         </td>
     </tr>
     <tr><td class="SubTitle"><?=$loadedLayersLocal?></td></tr>
@@ -387,10 +408,17 @@
             <input class="Ctrl" type="button" id="editBtn" onClick="SubmitCommand(CMD_EDIT)" value="<?=$addEditLocal?>" style="width:125px">
             <input class="Ctrl" type="button" id="closeBtn" onClick="SubmitCommand(CMD_CLOSE)" value="<?=$removeFromMapLocal?>" style="width:125px">
             <input class="Ctrl" type="button" id="editStyleBtn" onClick="SubmitCommand(CMD_EDITSTYLE)" value="<?=$editStyleLocal?>" style="width:125px">
-            <input class="Ctrl" type="button" id="downloadDataBtn" onClick="SubmitCommand(CMD_DOWNLOAD_LAYER_DATA)" value="<?=$downloadLocal?>" style="width:125px">
             <br><br>
         </td>
     </tr>
+    <tr><td class="SubTitle"><?=$downloadOptionsLocal?></td></tr>
+    <tr>
+        <td>
+            <input class="Ctrl" type="button" id="downloadDataBtn" onClick="SubmitCommand(CMD_DOWNLOAD_LAYER_DATA)" value="<?=$downloadLocal?>" style="width:95px">
+            <input class="Ctrl" type="button" id="downloadKmlBtn" onClick="SubmitCommand(CMD_DOWNLOAD_KML)" value="<?=$downloadKmlLocal?>" style="width:95px">
+            <input class="Ctrl" type="button" id="downloadKmzBtn" onClick="SubmitCommand(CMD_DOWNLOAD_KMZ)" value="<?=$downloadKmzLocal?>" style="width:95px">
+        </td>
+    </tr>
 </table>
 <input name="SESSION" type="hidden" value="<?= $args['SESSION'] ?>">
 <input name="MAPNAME" type="hidden" value="<?= $args['MAPNAME'] ?>">



More information about the fusion-commits mailing list