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

svn_fusion at osgeo.org svn_fusion at osgeo.org
Fri Mar 8 01:32:42 PST 2013


Author: jng
Date: 2013-03-08 01:32:42 -0800 (Fri, 08 Mar 2013)
New Revision: 2654

Modified:
   trunk/text/en
   trunk/widgets/Redline/classes/markupeditor.php
   trunk/widgets/Redline/classes/markupmanager.php
   trunk/widgets/Redline/editmarkup.php
   trunk/widgets/Redline/templates/markuplayerdefinition.xml
Log:
#551: Add support for SQLite as a usable redline data store. The UI is still hard-coded to create SDF redlines. We'll fix that in a future submission

Modified: trunk/text/en
===================================================================
--- trunk/text/en	2013-03-08 01:39:50 UTC (rev 2653)
+++ trunk/text/en	2013-03-08 09:32:42 UTC (rev 2654)
@@ -150,7 +150,7 @@
 FEATUREINFOERROR        = Error
 FEATUREINFOFETCHINFO    = fetching feature info ...
 FEATUREINFOFEATURESEL   = features selected
-FEATUREINFOAREA         = Area: 
+FEATUREINFOAREA         = Area:
 FEATUREINFOAREAUNDEFINE = areaIdx undefined
 FEATUREINFONOINFO       = no layer info
 FEATUREINFONOFEATUREIN  = no features in selected layer.
@@ -226,6 +226,8 @@
 REDLINEUPLOADSDF        = Upload
 REDLINEEDITSTYLE        = Edit Style
 REDLINECREATEFAILURE    = Failed to create redline
+REDLINEUPLOADUNKNOWNPROVIDER  = Could not determine FDO provider from uploaded file
+REDLINEUPLOADNOGEOMETRY = Could not find geometry property in uploaded file
 
 # Edit Redline Style UI
 REDLINEEDITLAYERSTYLE   = Edit Redline Style
@@ -411,7 +413,7 @@
 # Main Frame
 NEEDLOGIN               = You must enter a valid login ID and password to access this site
 ALREADYINMEASURE        = Only one measure command is allowed in a web layout
-ACCESSDENIED            = Access Denied   
+ACCESSDENIED            = Access Denied
 LATLONCURPOS            = Lat: {0}, Lon: {1}
 MAPUNITSCURPOS          = X: {0}, Y: {1}
 FEATURESSELECTED        = {0} features selected

Modified: trunk/widgets/Redline/classes/markupeditor.php
===================================================================
--- trunk/widgets/Redline/classes/markupeditor.php	2013-03-08 01:39:50 UTC (rev 2653)
+++ trunk/widgets/Redline/classes/markupeditor.php	2013-03-08 09:32:42 UTC (rev 2654)
@@ -171,6 +171,28 @@
         $this->InsertMarkupFeature($propertyValues);
     }
 
+    //Utility function to close all feature readers in a MgPropertyCollection
+    static function CleanupReaders($propCol)
+    {
+        $errMsg = "";
+        for ($i = 0; $i < $propCol->GetCount(); $i++)
+        {
+            $prop = $propCol->GetItem($i);
+            if ($prop->GetPropertyType() == MgPropertyType::Feature)
+            {
+                $fr = $prop->GetValue();
+                $fr->Close();
+            }
+            else if ($prop->GetPropertyType() == MgPropertyType::String)
+            {
+                $errMsg = $prop->GetValue();
+            }
+        }
+        if (strlen($errMsg) > 0) {
+            throw new Exception($errMsg);
+        }
+    }
+
     function InsertMarkupFeature($propertyValues)
     {
         $featureService = $this->site->CreateService(MgServiceType::FeatureService);
@@ -179,7 +201,8 @@
         $commands = new MgFeatureCommandCollection();
         $commands->Add(new MgInsertFeatures('Markup', $propertyValues));
 
-        $featureService->UpdateFeatures($featureSourceId, $commands, false);
+        $result = $featureService->UpdateFeatures($featureSourceId, $commands, false);
+        MarkupEditor::CleanupReaders($result);
     }
 
     function DeleteMarkup()
@@ -190,7 +213,8 @@
         $commands = new MgFeatureCommandCollection();
         $commands->Add(new MgDeleteFeatures('Markup', 'ID = ' . $this->args['MARKUPFEATURE']));
 
-        $featureService->UpdateFeatures($featureSourceId, $commands, false);
+        $result = $featureService->UpdateFeatures($featureSourceId, $commands, false);
+        MarkupEditor::CleanupReaders($result);
     }
 
     function UpdateMarkup()
@@ -204,7 +228,8 @@
         $commands = new MgFeatureCommandCollection();
         $commands->Add(new MgUpdateFeatures('Markup', $propertyValues, 'ID = ' . $this->args['MARKUPFEATURE']));
 
-        $featureService->UpdateFeatures($featureSourceId, $commands, false);
+        $result = $featureService->UpdateFeatures($featureSourceId, $commands, false);
+        MarkupEditor::CleanupReaders($result);
     }
 
     function GetSelectionXML()

Modified: trunk/widgets/Redline/classes/markupmanager.php
===================================================================
--- trunk/widgets/Redline/classes/markupmanager.php	2013-03-08 01:39:50 UTC (rev 2653)
+++ trunk/widgets/Redline/classes/markupmanager.php	2013-03-08 09:32:42 UTC (rev 2654)
@@ -153,31 +153,6 @@
         }
         $fr->Close();
 
-        /*
-        $resourceService = $this->site->CreateService(MgServiceType::ResourceService);
-        $resourceID = new MgResourceIdentifier("Library://Markup/");
-
-        try
-        {
-            $byteReader = $resourceService->EnumerateResources($resourceID, 1, "LayerDefinition");
-            $resourceListXML = $byteReader->ToString();
-
-            $doc = DOMDocument::loadXML($resourceListXML);
-            $nodeList = $doc->getElementsByTagName('ResourceId');
-
-            foreach ($nodeList as $node)
-            {
-                $resourceId = new MgResourceIdentifier($node->nodeValue);
-                $markup[$resourceId->ToString()] = $resourceId->GetName();
-            }
-            asort($markup);
-        }
-        catch (MgResourceNotFoundException $mge)
-        {
-            // If the Library://Markup folder does not exist, create it.
-            $resourceService->SetResource($resourceID, null, null);
-        }*/
-
         return $markup;
     }
 
@@ -343,7 +318,7 @@
         }
     }
 
-    function CreateMarkupLayerDefinitionContent($featureSourceId)
+    function CreateMarkupLayerDefinitionContent($featureSourceId, $className)
     {
         // Create the Markup Layer Definition. Create or update, this code is the same.
 
@@ -356,6 +331,7 @@
         $markupLayerDefinition = file_get_contents("templates/markuplayerdefinition.xml");
         $markupLayerDefinition = sprintf($markupLayerDefinition,
             $featureSourceId,						            //<ResourceId> - Feature Source
+            $className,                                         //<FeatureName> - Class Name
             $this->args['LABELSIZEUNITS'],						//<Unit> - Mark Label
             $this->args['LABELFONTSIZE'],						//<SizeX> - Mark Label Size
             $this->args['LABELFONTSIZE'],						//<SizeY> - Mark Label Size
@@ -436,7 +412,16 @@
             $featureSourceId = $this->args["EDITFEATURESOURCE"];
         }
 
-        $markupLayerDefinition = $this->CreateMarkupLayerDefinitionContent($featureSourceId);
+        //HACK: SQLite leaky abstraction (hard-coded schema name), SHP probably has some leaks of its own, so we can't assume MarkupSchema:Markup
+        //as the class name interrogate our schema to figure it out
+        $fsId = new MgResourceIdentifier($featureSourceId);
+        $schemas = $featureService->DescribeSchema($fsId, "", null);
+        $schema = $schemas->GetItem(0);
+        $classes = $schema->GetClasses();
+        $cls = $classes->GetItem(0);
+        $className = $schema->GetName().":".$cls->GetName();
+
+        $markupLayerDefinition = $this->CreateMarkupLayerDefinitionContent($featureSourceId, $className);
         $byteSource = new MgByteSource($markupLayerDefinition, strlen($markupLayerDefinition));
         //Save to new resource or overwrite existing
         $layerDefId = new MgResourceIdentifier($bUpdate ? $this->args["EDITMARKUPLAYER"] : ($this->GetResourceIdPrefix() . $markupName . '.LayerDefinition'));
@@ -522,28 +507,67 @@
         echo $outputBuffer;
     }
 
+    function GetProviderFromExtension($ext)
+    {
+        $extNorm = strtolower($ext);
+        if ( substr( $extNorm, strlen( $extNorm ) - strlen( "sdf" ) ) == "sdf" ) {
+            return "OSGeo.SDF";
+        } else if ( substr( $extNorm, strlen( $extNorm ) - strlen( "sqlite" ) ) == "sqlite" ) {
+            return "OSGeo.SQLite";
+        } else if ( substr( $extNorm, strlen( $extNorm ) - strlen( "db" ) ) == "db" ) {
+            return "OSGeo.SQLite";
+        //} else if ( substr( $extNorm, strlen( $extNorm ) - strlen( "zip" ) ) == "zip" ) { //SHP file uploads will be zipped
+        //    return "OSGeo.SHP";
+        } else {
+            return null;
+        }
+    }
+
     function UploadMarkup()
     {
+        $locale = "en";
+        if (array_key_exists($this->args, "LOCALE"))
+            $locale = $this->args["LOCALE"];
+        $uploadFileParts = pathinfo($_FILES["UPLOADFILE"]["name"]);
+        $fdoProvider = $this->GetProviderFromExtension($uploadFileParts["extension"]);
+        if ($fdoProvider == null) {
+            throw new Exception(GetLocalizedString("REDLINEUPLOADUNKNOWNPROVIDER", $locale));
+        }
+
         $resourceService = $this->site->CreateService(MgServiceType::ResourceService);
         $featureService = $this->site->CreateService(MgServiceType::FeatureService);
         $bs = new MgByteSource($_FILES["UPLOADFILE"]["tmp_name"]);
         $br = $bs->GetReader();
 
-        $uploadFileParts = pathinfo($_FILES["UPLOADFILE"]["name"]);
         //Use file name to drive all parameters
         $baseName = $uploadFileParts["filename"];
         $this->UniqueMarkupName($baseName); //Guard against potential duplicates
         $ext = $uploadFileParts["extension"];
 
         $markupLayerResId = new MgResourceIdentifier($this->GetResourceIdPrefix() . $baseName . ".LayerDefinition");
-        $markupSdfResId = new MgResourceIdentifier($this->GetResourceIdPrefix() . $baseName . '.FeatureSource');
+        $markupFsId = new MgResourceIdentifier($this->GetResourceIdPrefix() . $baseName . '.FeatureSource');
 
         $dataName = $baseName . "." . $ext;
         $fsXml = sprintf(file_get_contents("templates/markupfeaturesource.xml"), $dataName);
         $bs2 = new MgByteSource($fsXml, strlen($fsXml));
-        $resourceService->SetResource($markupSdfResId, $bs2->GetReader(), null);
-        $resourceService->SetResourceData($markupSdfResId, $dataName, "File", $bs->GetReader());
+        $resourceService->SetResource($markupFsId, $bs2->GetReader(), null);
+        $resourceService->SetResourceData($markupFsId, $dataName, "File", $bs->GetReader());
 
+        //Query the geometry types
+        $schemas = $featureService->DescribeSchema($markupFsId, "", null);
+        $schema = $schemas->GetItem(0);
+        $classes = $schema->GetClasses();
+        $klass = $classes->GetItem(0);
+        $geomProp = $klass->GetDefaultGeometryPropertyName();
+        $clsProps = $klass->GetProperties();
+        $geomTypes = -1;
+        if ($clsProps->IndexOf($geomProp) >= 0) {
+            $geom = $clsProps->GetItem($geomProp);
+            $geomTypes = $geom->GetGeometryTypes();
+        } else {
+            throw new Exception(GetLocalizedString("REDLINEUPLOADNOGEOMETRY", $locale));
+        }
+
         //Set up default style args
         $this->args["MARKUPNAME"] = $baseName;
 
@@ -577,7 +601,7 @@
         $this->args["LABELBACKCOLOR"] = DefaultStyle::LABEL_BACK_COLOR;
         $this->args["LABELBACKSTYLE"] = DefaultStyle::LABEL_BACK_STYLE;
 
-        $markupLayerDefinition = $this->CreateMarkupLayerDefinitionContent($markupSdfResId->ToString());
+        $markupLayerDefinition = $this->CreateMarkupLayerDefinitionContent($markupFsId->ToString());
 
         $layerBs = new MgByteSource($markupLayerDefinition, strlen($markupLayerDefinition));
         //Save to new resource or overwrite existing
@@ -586,9 +610,11 @@
         //Add to markup registry
         $cmds = new MgFeatureCommandCollection();
         $props = new MgPropertyCollection();
-        $props->Add(new MgStringProperty("ResourceId", $markupSdfResId->ToString()));
+        $props->Add(new MgStringProperty("ResourceId", $markupFsId->ToString()));
         $props->Add(new MgStringProperty("LayerDefinition", $markupLayerResId->ToString()));
         $props->Add(new MgStringProperty("Name", $markupLayerResId->GetName()));
+        $props->Add(new MgStringProperty("FdoProvider", $fdoProvider));
+        $props->Add(new MgInt32Property("GeometryTypes", $geomTypes));
         $insertCmd = new MgInsertFeatures("Default:MarkupRegistry", $props);
 
         $cmds->Add($insertCmd);

Modified: trunk/widgets/Redline/editmarkup.php
===================================================================
--- trunk/widgets/Redline/editmarkup.php	2013-03-08 01:39:50 UTC (rev 2653)
+++ trunk/widgets/Redline/editmarkup.php	2013-03-08 09:32:42 UTC (rev 2654)
@@ -27,7 +27,7 @@
     try
     {
         $markupEditor = new MarkupEditor($args);
-        
+
         if (array_key_exists('EDITCOMMAND', $args))
         {
             $cmd = $args['EDITCOMMAND'];
@@ -54,12 +54,12 @@
                 $markupEditor->UpdateMarkup();
                 $refreshMap = true;
                 break;
-                
+
             }
         }
-        
+
         $markupFeatures = $markupEditor->GetMarkupFeatures();
-        
+
         $editLocal = GetLocalizedString('REDLINEEDIT', $locale );
         $defaultHelpLocal = GetLocalizedString('REDLINEEDITDEFAULTHELP', $locale );
         $pointHelpLocal = GetLocalizedString('REDLINEEDITPOINTHELP', $locale );
@@ -86,6 +86,11 @@
         $errorMsg = $e->GetMessage();
         $errorDetail = $e->GetDetails();
     }
+    catch (Exception $e)
+    {
+        $errorMsg = $e->getMessage();
+        $errorDetail = $e->__toString();
+    }
 ?>
 <html>
 <head>
@@ -97,7 +102,7 @@
     <script language="javascript">
         var session = '<?= $args['SESSION'] ?>';
         var mapName = '<?= $args['MAPNAME'] ?>';
-    
+
         var CMD_ADD_POINT		= <?= EditCommand::AddPoint ?>;
         var CMD_ADD_LINE 		= <?= EditCommand::AddLine ?>;
         var CMD_ADD_LINESTRING 	= <?= EditCommand::AddLineString ?>;
@@ -105,14 +110,14 @@
         var CMD_ADD_POLYGON 	= <?= EditCommand::AddPolygon ?>;
         var CMD_DELETE 			= <?= EditCommand::Delete ?>;
         var CMD_UPDATE 			= <?= EditCommand::Update ?>;
-    
+
         var EDIT_DEFAULT_HELP = "<?=$defaultHelpLocal?>";
         var EDIT_POINT_HELP = "<?=$pointHelpLocal?>";
         var EDIT_LINE_HELP = "<?=$lineHelpLocal?>";
         var EDIT_LINESTRING_HELP = "<?=$lineStringHelpLocal?>";
         var EDIT_RECTANGLE_HELP = "<?=$rectangleHelpLocal?>";
         var EDIT_POLYGON_HELP = "<?=$polygonHelpLocal?>";
-    
+
         function SetDigitizeInfo(text)
         {
             var digitizeInfo = document.getElementById("digitizeInfo");
@@ -128,11 +133,11 @@
         {
             var commandInput = document.getElementById("commandInput");
             commandInput.value = cmd;
-            
+
             var editForm = document.getElementById("editForm");
             editForm.submit();
         }
-    
+
         function AddPoint()
         {
             SetDigitizeInfo(EDIT_POINT_HELP);
@@ -174,27 +179,27 @@
             }
             ClearDigitization(true);
         }
-    
+
         function OnPointDigitized(point)
         {
-            PromptAndSetMarkupText();			
+            PromptAndSetMarkupText();
 
             var geometryInput = document.getElementById("geometryInput");
             geometryInput.value = point.X + "," + point.Y;
-            
+
             SubmitCommand(CMD_ADD_POINT);
         }
 
         function OnLineStringDigitized(lineString)
         {
-            PromptAndSetMarkupText();			
+            PromptAndSetMarkupText();
 
             var geomText = lineString.Count;
             for (var i = 0; i < lineString.Count; i++)
             {
                 geomText += "," + lineString.Point(i).X + "," + lineString.Point(i).Y;
             }
-        
+
             var geometryInput = document.getElementById("geometryInput");
             geometryInput.value = geomText;
 
@@ -203,10 +208,10 @@
 
         function OnRectangleDigitized(rectangle)
         {
-            PromptAndSetMarkupText();			
+            PromptAndSetMarkupText();
 
             var geometryInput = document.getElementById("geometryInput");
-            geometryInput.value = "5," 
+            geometryInput.value = "5,"
                 + rectangle.Point1.X + "," + rectangle.Point1.Y + ","
                 + rectangle.Point2.X + "," + rectangle.Point1.Y + ","
                 + rectangle.Point2.X + "," + rectangle.Point2.Y + ","
@@ -215,45 +220,45 @@
 
             SubmitCommand(CMD_ADD_RECTANGLE);
         }
-    
+
         function OnPolyonDigitized(polygon)
         {
             if(polygon.Count < 3)
             {
                 // invalid polygon
                 ClearDigitization(true);
-                
-                return;  
+
+                return;
             }
-                
-            PromptAndSetMarkupText();			
 
+            PromptAndSetMarkupText();
+
             var geomText = polygon.Count;
             for (var i = 0; i < polygon.Count; i++)
             {
                 geomText += "," + polygon.Point(i).X + "," + polygon.Point(i).Y;
             }
-        
+
             var geometryInput = document.getElementById("geometryInput");
             geometryInput.value = geomText;
 
             SubmitCommand(CMD_ADD_POLYGON);
         }
-    
+
         function SelectMarkup()
-        {            
+        {
             markupFeatures = document.getElementById("markupFeatures");
-            
+
             reqParams = "MAPNAME=" + encodeURIComponent(mapName);
             reqParams += "&SESSION=" + encodeURIComponent(session);
             reqParams += "&OPENMARKUP=" + encodeURIComponent('<?= $args['OPENMARKUP']; ?>');
             reqParams += "&MARKUPFEATURE=" + markupFeatures.value;
-            
+
             if(msie)
                 reqHandler = new ActiveXObject("Microsoft.XMLHTTP");
             else
                 reqHandler = new XMLHttpRequest();
-                
+
             reqHandler.open("POST", "getselectionxml.php", false);
             reqHandler.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
 
@@ -263,17 +268,17 @@
                 SetSelectionXML(reqHandler.responseText);
             }
         }
-    
+
         function DeleteMarkup()
         {
             SubmitCommand(CMD_DELETE);
         }
-        
+
         function UpdateMarkup()
         {
             SubmitCommand(CMD_UPDATE);
         }
-    
+
         function CloseEditor()
         {
             ClearDigitization(true);
@@ -282,10 +287,10 @@
 
             var editForm = document.getElementById("editForm");
             editForm.action = "markupmain.php";
-            
+
             editForm.submit();
         }
-    
+
         function OnMarkupFeatureChange()
         {
             var markupFeatures = document.getElementById("markupFeatures");
@@ -293,7 +298,7 @@
             var selectBtn = document.getElementById("selectBtn");
             var deleteBtn = document.getElementById("deleteBtn");
             var updateBtn = document.getElementById("updateBtn");
-            
+
             if (markupFeatures.selectedIndex >= 0)
             {
                 value = markupFeatures.options[markupFeatures.selectedIndex].text;
@@ -301,7 +306,7 @@
                     updateTextInput.value = value;
                 else
                     updateTextInput.value = '';
-                    
+
                 selectBtn.disabled = false;
                 deleteBtn.disabled = false;
                 updateBtn.disabled = false;
@@ -313,12 +318,12 @@
                 deleteBtn.disabled = true;
                 updateBtn.disabled = true;
             }
-        } 
-    
+        }
+
         function OnLoad()
         {
             OnMarkupFeatureChange();
-                        
+
         <?php if ($refreshMap) { ?>
             var map = parent.Fusion.getMapByName(mapName);
             map.reloadMap();
@@ -378,10 +383,10 @@
                     $selected = 'selected';
                     foreach($markupFeatures as $markupId => $markupText) {
                 ?>
-                <option value="<?= $markupId ?>" <?=$selected ?> ><?= (strlen($markupText) > 0) ? htmlentities($markupText) : '[no text]' ?></option> 
+                <option value="<?= $markupId ?>" <?=$selected ?> ><?= (strlen($markupText) > 0) ? htmlentities($markupText) : '[no text]' ?></option>
                 <?php
-                        $selected = ''; 
-                    } 
+                        $selected = '';
+                    }
                 ?>
             </select>
         </td>

Modified: trunk/widgets/Redline/templates/markuplayerdefinition.xml
===================================================================
--- trunk/widgets/Redline/templates/markuplayerdefinition.xml	2013-03-08 01:39:50 UTC (rev 2653)
+++ trunk/widgets/Redline/templates/markuplayerdefinition.xml	2013-03-08 09:32:42 UTC (rev 2654)
@@ -3,7 +3,7 @@
 <LayerDefinition xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xsi:noNamespaceSchemaLocation="LayerDefinition-1.0.0.xsd" version="1.0.0">
   <VectorLayerDefinition>
     <ResourceId>%s</ResourceId>
-    <FeatureName>MarkupSchema:Markup</FeatureName>
+    <FeatureName>%s</FeatureName>
     <FeatureNameType>FeatureClass</FeatureNameType>
     <PropertyMapping>
       <Name>Text</Name>



More information about the fusion-commits mailing list