[fusion-commits] r2712 - in trunk/widgets: . Redline widgetinfo

svn_fusion at osgeo.org svn_fusion at osgeo.org
Thu May 23 00:51:00 PDT 2013


Author: jng
Date: 2013-05-23 00:51:00 -0700 (Thu, 23 May 2013)
New Revision: 2712

Modified:
   trunk/widgets/Redline.js
   trunk/widgets/Redline/editmarkup.php
   trunk/widgets/Redline/editmarkupstyle.php
   trunk/widgets/Redline/markupmain.php
   trunk/widgets/widgetinfo/redline.xml
Log:
#565: Add 2 new extension parameters to the Redline widget:

 - DataStoreFormat: The redline data store format to use (SDF/SHP/SQLite)
 - RedlineGeometryFormat: The types of geometry the user can record with this widget (1=Point, 2=Line, 4=Geometry and any bitmask combination thereof)

If both values are specified (and only a singular geometry type if the format is SHP), then the "Create New Redline" section of the UI is replaced with just a button of the same name. This insulates the user from needing to know what format to use and what geometry types to tick as this can be imposed by the author of the Flexible Layout.

Modified: trunk/widgets/Redline/editmarkup.php
===================================================================
--- trunk/widgets/Redline/editmarkup.php	2013-05-22 04:48:14 UTC (rev 2711)
+++ trunk/widgets/Redline/editmarkup.php	2013-05-23 07:51:00 UTC (rev 2712)
@@ -20,7 +20,23 @@
     $allowLine = false;
     $allowPoly = false;
     $markupFeatures = array();
+    
+    $defaultFormat = null;
+    $defaultGeomType = null;
 
+    if (array_key_exists("REDLINEFORMAT", $args) && array_key_exists("REDLINEGEOMTYPE", $args)) {
+        if (strcmp($args["REDLINEFORMAT"], "SDF") == 0) {
+            $defaultFormat = $args["REDLINEFORMAT"];
+            $defaultGeomType = $args["REDLINEGEOMTYPE"];
+        } else if (strcmp($args["REDLINEFORMAT"], "SHP") == 0) {
+            $defaultFormat = $args["REDLINEFORMAT"];
+            $defaultGeomType = $args["REDLINEGEOMTYPE"];
+        } else if (strcmp($args["REDLINEFORMAT"], "SQLite") == 0) {
+            $defaultFormat = $args["REDLINEFORMAT"];
+            $defaultGeomType = $args["REDLINEGEOMTYPE"];
+        }
+    }
+
     SetLocalizedFilesPath(GetLocalizationPath());
     if(isset($_REQUEST['LOCALE'])) {
         $locale = $_REQUEST['LOCALE'];
@@ -450,6 +466,10 @@
 <input name="EDITCOMMAND" type="hidden" value="" id="commandInput">
 <input name="GEOMETRY" type="hidden" value="" id="geometryInput">
 <input name="TEXT" type="hidden" value="" id="textInput">
+<? if ($defaultFormat != null && $defaultGeomType != null) { ?>
+<input name="REDLINEFORMAT" type="hidden" value="<?= $defaultFormat ?>" />
+<input name="REDLINEGEOMTYPE" type="hidden" value="<?= $defaultGeomType ?>" />
+<? } ?>
 </form>
 <?php } else { ?>
 </head>

Modified: trunk/widgets/Redline/editmarkupstyle.php
===================================================================
--- trunk/widgets/Redline/editmarkupstyle.php	2013-05-22 04:48:14 UTC (rev 2711)
+++ trunk/widgets/Redline/editmarkupstyle.php	2013-05-23 07:51:00 UTC (rev 2712)
@@ -22,6 +22,22 @@
     $errorMsg = null;
     $errorDetail = null;
     
+    $defaultFormat = null;
+    $defaultGeomType = null;
+
+    if (array_key_exists("REDLINEFORMAT", $args) && array_key_exists("REDLINEGEOMTYPE", $args)) {
+        if (strcmp($args["REDLINEFORMAT"], "SDF") == 0) {
+            $defaultFormat = $args["REDLINEFORMAT"];
+            $defaultGeomType = $args["REDLINEGEOMTYPE"];
+        } else if (strcmp($args["REDLINEFORMAT"], "SHP") == 0) {
+            $defaultFormat = $args["REDLINEFORMAT"];
+            $defaultGeomType = $args["REDLINEGEOMTYPE"];
+        } else if (strcmp($args["REDLINEFORMAT"], "SQLite") == 0) {
+            $defaultFormat = $args["REDLINEFORMAT"];
+            $defaultGeomType = $args["REDLINEGEOMTYPE"];
+        }
+    }
+    
     SetLocalizedFilesPath(GetLocalizationPath());
     if(isset($_REQUEST['LOCALE'])) {
         $locale = $_REQUEST['LOCALE'];
@@ -117,18 +133,6 @@
         var labelForeColor = "<?= $style->LABEL_FORE_COLOR ?>";
         var labelBackColor = "<?= $style->LABEL_BACK_COLOR ?>";
         
-        function CheckName()
-        {
-            var el = document.getElementById("markupName");
-            var mkName = el.value.replace(/^\s+|\s+$/g,"");
-            if (mkName == "") {
-                alert("Please enter a name for this new markup layer");
-                el.focus();
-                return false;
-            }
-            return true;
-        }
-        
         function PickColor(whichColor, allowTransparency, transparent)
         {
             var clr;
@@ -223,7 +227,11 @@
         
         function Cancel()
         {
+        <? if ($defaultFormat != null && $defaultGeomType != null) { ?>
+            window.location.href="markupmain.php?SESSION=<?= $args['SESSION']?>&MAPNAME=<?= $args['MAPNAME']?>&REDLINEFORMAT=<?= $defaultFormat ?>&REDLINEGEOMTYPE=<?= $defaultGeomType ?>";
+        <? } else { ?>
             window.location.href="markupmain.php?SESSION=<?= $args['SESSION']?>&MAPNAME=<?= $args['MAPNAME']?>";
+        <? } ?>
         }
     </script>
     
@@ -242,6 +250,11 @@
 <input name="EDITFEATURESOURCE" type="hidden" value="<?= $editFeatureSource ?>">
 <input name="MARKUPLAYERNAME" type="hidden" value="<?= $args['MARKUPLAYERNAME'] ?>">
 
+<? if ($defaultFormat != null && $defaultGeomType != null) { ?>
+<input name="REDLINEFORMAT" type="hidden" value="<?= $defaultFormat ?>" />
+<input name="REDLINEGEOMTYPE" type="hidden" value="<?= $defaultGeomType ?>" />
+<? } ?>
+
 <table class="RegText" border="0" cellspacing="0" width="100%%">
     <tr><td id="elTitle" colspan="2" class="Title"><?= $editLayerStyleLocal ?><hr></td></tr>
     <tr><td colspan="2" class="SubTitle"><?= $layerSettingsLocal ?></td></tr>
@@ -464,7 +477,7 @@
     <tr>
         <td colspan="2" align="right">
             <hr>
-            <input class="Ctrl" name="" type="submit" value="OK" onClick="return CheckName()" style="width:85px">
+            <input class="Ctrl" name="" type="submit" value="OK" style="width:85px">
             <input class="Ctrl" type="button" value="Cancel" style="width:85px" onClick="return Cancel()">
         </td>
     </tr>

Modified: trunk/widgets/Redline/markupmain.php
===================================================================
--- trunk/widgets/Redline/markupmain.php	2013-05-22 04:48:14 UTC (rev 2711)
+++ trunk/widgets/Redline/markupmain.php	2013-05-23 07:51:00 UTC (rev 2712)
@@ -17,7 +17,27 @@
     $refreshMap = false;
     $errorMsg = null;
     $errorDetail = null;
+    
+    $defaultCmd = null;
+    $defaultFormat = null;
+    $defaultGeomType = null;
 
+    if (array_key_exists("REDLINEFORMAT", $args) && array_key_exists("REDLINEGEOMTYPE", $args)) {
+        if (strcmp($args["REDLINEFORMAT"], "SDF") == 0) {
+            $defaultFormat = $args["REDLINEFORMAT"];
+            $defaultCmd = MarkupCommand::CreateSdf;
+            $defaultGeomType = $args["REDLINEGEOMTYPE"];
+        } else if (strcmp($args["REDLINEFORMAT"], "SHP") == 0) {
+            $defaultFormat = $args["REDLINEFORMAT"];
+            $defaultCmd = MarkupCommand::CreateShp;
+            $defaultGeomType = $args["REDLINEGEOMTYPE"];
+        } else if (strcmp($args["REDLINEFORMAT"], "SQLite") == 0) {
+            $defaultFormat = $args["REDLINEFORMAT"];
+            $defaultCmd = MarkupCommand::CreateSqlite;
+            $defaultGeomType = $args["REDLINEGEOMTYPE"];
+        }
+    }
+
     SetLocalizedFilesPath(GetLocalizationPath());
     if(isset($_REQUEST['LOCALE'])) {
         $locale = $_REQUEST['LOCALE'];
@@ -153,6 +173,9 @@
 
         function GetGeometryTypes()
         {
+        <? if ($defaultFormat != null && $defaultGeomType != null) { ?>
+            return <?= $defaultGeomType ?>;
+        <? } else { ?>
             var geomType = 0;
             var bPoint = document.getElementById("chkPoint").checked;
             var bLine = document.getElementById("chkLine").checked;
@@ -166,6 +189,7 @@
                 geomType |= GEOM_POLY;
 
             return geomType;
+        <? } ?>
         }
 
         function GetFdoProvider(cmd)
@@ -178,53 +202,62 @@
                 return "OSGeo.SDF";
         }
 
-        function SubmitCommand(cmd)
+        function SubmitCreateCommand(cmd, geomTypes)
         {
             var commandInput = document.getElementById("commandInput");
             commandInput.value = cmd;
+            
+            if (typeof(geomTypes) == 'undefined') {
+                geomTypes = GetGeometryTypes();
+            }
 
             var markupForm = document.getElementById("markupForm");
-            if (cmd == CMD_NEW_SDF || cmd == CMD_NEW_SHP || cmd == CMD_NEW_SQLITE) {
-                var widget = Fusion.getWidgetsByType("Redline")[0];
-                if (widget.autogenerateLayerNames) {
-                    Fusion.ajaxRequest("widgets/Redline/newmarkup.php", {
-                        onSuccess: OpenLayers.Function.bind(OnMarkupCreated, this),
-                        onFailure: OpenLayers.Function.bind(OnMarkupCreateFailure, this),
-                        parameters: {
-                            SESSION: session,
-                            MAPNAME: mapName,
-                            MARKUPFDOPROVIDER: GetFdoProvider(cmd),
-                            MARKUPGEOMTYPE: GetGeometryTypes()
-                        }
-                    });
-                } else {
-                    var name = prompt("<?= $redlineLayerNameLocal ?>");
-                    Fusion.ajaxRequest("widgets/Redline/newmarkup.php", {
-                        onSuccess: OpenLayers.Function.bind(OnMarkupCreated, this),
-                        onFailure: OpenLayers.Function.bind(OnMarkupCreateFailure, this),
-                        parameters: {
-                            SESSION: session,
-                            MAPNAME: mapName,
-                            NEWLAYERNAME: name,
-                            MARKUPFDOPROVIDER: GetFdoProvider(cmd),
-                            MARKUPGEOMTYPE: GetGeometryTypes()
-                        }
-                    });
-                }
+            
+            var widget = Fusion.getWidgetsByType("Redline")[0];
+            if (widget.autogenerateLayerNames) {
+                Fusion.ajaxRequest("widgets/Redline/newmarkup.php", {
+                    onSuccess: OpenLayers.Function.bind(OnMarkupCreated, this),
+                    onFailure: OpenLayers.Function.bind(OnMarkupCreateFailure, this),
+                    parameters: {
+                        SESSION: session,
+                        MAPNAME: mapName,
+                        MARKUPFDOPROVIDER: GetFdoProvider(cmd),
+                        MARKUPGEOMTYPE: geomTypes
+                    }
+                });
             } else {
-                if (cmd == CMD_EDIT) {
-                    markupForm.action = "editmarkup.php";
-                } else if (cmd == CMD_UPLOAD) {
-                    markupForm.action = "uploadmarkup.php";
-                } else if (cmd == CMD_EDITSTYLE) {
-                    markupForm.action = "editmarkupstyle.php";
-                }
-                else {
-                    markupForm.action = "markupmain.php";
-                }
-                markupForm.submit();
+                var name = prompt("<?= $redlineLayerNameLocal ?>");
+                Fusion.ajaxRequest("widgets/Redline/newmarkup.php", {
+                    onSuccess: OpenLayers.Function.bind(OnMarkupCreated, this),
+                    onFailure: OpenLayers.Function.bind(OnMarkupCreateFailure, this),
+                    parameters: {
+                        SESSION: session,
+                        MAPNAME: mapName,
+                        NEWLAYERNAME: name,
+                        MARKUPFDOPROVIDER: GetFdoProvider(cmd),
+                        MARKUPGEOMTYPE: geomTypes
+                    }
+                });
             }
         }
+        
+        function SubmitCommand(cmd)
+        {
+            var commandInput = document.getElementById("commandInput");
+            commandInput.value = cmd;
+            
+            if (cmd == CMD_EDIT) {
+                markupForm.action = "editmarkup.php";
+            } else if (cmd == CMD_UPLOAD) {
+                markupForm.action = "uploadmarkup.php";
+            } else if (cmd == CMD_EDITSTYLE) {
+                markupForm.action = "editmarkupstyle.php";
+            }
+            else {
+                markupForm.action = "markupmain.php";
+            }
+            markupForm.submit();
+        }
 
         function OnMarkupCreated(response)
         {
@@ -316,10 +349,12 @@
 
         function CheckApplicableProviders()
         {
+        <? if ($defaultFormat == null || $defaultGeomType == null) { ?>
             var gt = GetGeometryTypes();
             document.getElementById("newShpBtn").disabled = (gt != GEOM_POINT && gt != GEOM_LINE && gt != GEOM_POLY);
             document.getElementById("newSdfBtn").disabled = (gt == 0);
             document.getElementById("newSqliteBtn").disabled = (gt == 0);
+        <? } ?>
         }
 
         function OnLoad()
@@ -343,8 +378,15 @@
 <table class="RegText" border="0" cellspacing="0" width="100%">
     <tr><td class="Title"><?=$manageLocal?><hr></td></tr>
     <tr><td class="SubTitle"><?=$newRedlineLayerLocal?></td></tr>
+    <? if ($defaultCmd != null && $defaultGeomType != null) { ?>
     <tr>
         <td>
+            <input class="Ctrl" type="button" id="newBtn" onClick="SubmitCreateCommand(<?= $defaultCmd ?>, <?= $defaultGeomType ?>)" value="<?= $newRedlineLayerLocal ?>" />
+        </td>
+    </tr>
+    <? } else { ?>
+    <tr>
+        <td>
             <?=$pointLocal?> <input class="Ctrl" type="checkbox" id="chkPoint" onClick="CheckApplicableProviders()" checked="checked" />
             <?=$lineLocal?> <input class="Ctrl" type="checkbox" id="chkLine" onClick="CheckApplicableProviders()" checked="checked" />
             <?=$polyLocal?> <input class="Ctrl" type="checkbox" id="chkPoly" onClick="CheckApplicableProviders()" checked="checked" />
@@ -352,11 +394,12 @@
     </tr>
     <tr>
         <td>
-            <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">
+            <input class="Ctrl" type="button" id="newSdfBtn" onClick="SubmitCreateCommand(CMD_NEW_SDF)" value="<?=$newSdfLocal?>" style="width:95px">
+            <input class="Ctrl" type="button" id="newShpBtn" onClick="SubmitCreateCommand(CMD_NEW_SHP)" value="<?=$newShpLocal?>" style="width:95px">
+            <input class="Ctrl" type="button" id="newSqliteBtn" onClick="SubmitCreateCommand(CMD_NEW_SQLITE)" value="<?=$newSqliteLocal?>" style="width:95px">
         </td>
     </tr>
+    <? } ?>
     <tr><td class="SubTitle"><?=$availableLayersLocal?></td></tr>
     <tr>
         <td class="RegText">
@@ -426,6 +469,10 @@
 <input name="MARKUPCOMMAND" type="hidden" value="" id="commandInput">
 <input name="EDITMARKUPLAYER" type="hidden" value="" id="editMarkupLayerId">
 <input name="MARKUPLAYERNAME" type="hidden" value="" id="markupLayerName">
+<? if ($defaultFormat != null && $defaultGeomType != null) { ?>
+<input name="REDLINEFORMAT" type="hidden" value="<?= $defaultFormat ?>" />
+<input name="REDLINEGEOMTYPE" type="hidden" value="<?= $defaultGeomType ?>" />
+<? } ?>
 </form>
 
 <?php } else { ?>

Modified: trunk/widgets/Redline.js
===================================================================
--- trunk/widgets/Redline.js	2013-05-22 04:48:14 UTC (rev 2711)
+++ trunk/widgets/Redline.js	2013-05-23 07:51:00 UTC (rev 2712)
@@ -53,6 +53,12 @@
 
     // Indicates whether to use the MapMessage component to display digitization prompts
     mapMessagePrompt: true,
+    
+    // Indicates the default redline data store to create
+    defaultDataStoreFormat: null,
+    
+    // Indicates the default geometry types the user can record
+    defaultRedlineGeometryTypes: 0,
 
     initializeWidget: function(widgetTag) {
         var json = widgetTag.extension;
@@ -66,6 +72,25 @@
 
         if (json.UseMapMessagePrompt)
             this.mapMessagePrompt = (json.UseMapMessagePrompt[0] == "true");
+            
+        if (json.DataStoreFormat && json.RedlineGeometryFormat) {
+            if (json.DataStoreFormat[0] == "SDF" ||
+                json.DataStoreFormat[0] == "SHP" ||
+                json.DataStoreFormat[0] == "SQLite") {
+                
+                var geomTypes = parseInt(json.RedlineGeometryFormat[0]);
+                if (json.DataStoreFormat[0] == "SHP") {
+                    //Only accept if geometry type is singular
+                    if (geomTypes == 1 || geomTypes == 2 || geomTypes == 4) {
+                        this.defaultDataStoreFormat = json.DataStoreFormat[0];
+                        this.defaultRedlineGeometryType = geomTypes;
+                    }
+                } else {
+                    this.defaultDataStoreFormat = json.DataStoreFormat[0];
+                    this.defaultRedlineGeometryType = geomTypes;
+                }
+            }
+        }
 
         // register Redline specific events
         this.registerEventID(Fusion.Event.REDLINE_FEATURE_ADDED);
@@ -125,6 +150,11 @@
         params.push('LOCALE='+Fusion.locale);
         params.push('MAPNAME='+this.widget.getMapName());
         params.push('SESSION='+this.widget.getSessionID());
+        
+        if (this.widget.defaultDataStoreFormat != null && this.widget.defaultRedlineGeometryType > 0) {
+            params.push('REDLINEFORMAT=' + this.widget.defaultDataStoreFormat);
+            params.push('REDLINEGEOMTYPE=' + this.widget.defaultRedlineGeometryType);
+        }
 
         if (url.indexOf('?') < 0) {
             url += '?';

Modified: trunk/widgets/widgetinfo/redline.xml
===================================================================
--- trunk/widgets/widgetinfo/redline.xml	2013-05-22 04:48:14 UTC (rev 2711)
+++ trunk/widgets/widgetinfo/redline.xml	2013-05-23 07:51:00 UTC (rev 2712)
@@ -41,4 +41,60 @@
         <DefaultValue>true</DefaultValue>
         <IsMandatory>false</IsMandatory>
     </Parameter>
+    <Parameter>
+        <Name>DataStoreFormat</Name>
+        <Description>The default data store format</Description>
+        <Type>String</Type>
+        <Label>DataStoreFormat</Label>
+        <AllowedValue>
+          <Name>SDF</Name>
+          <Label>SDF</Label>
+        </AllowedValue>
+        <AllowedValue>
+          <Name>SHP</Name>
+          <Label>SHP</Label>
+        </AllowedValue>
+        <AllowedValue>
+          <Name>SQLite</Name>
+          <Label>SQLite</Label>
+        </AllowedValue>
+        <DefaultValue></DefaultValue>
+        <IsMandatory>false</IsMandatory>
+    </Parameter>
+    <Parameter>
+        <Name>RedlineGeometryFormat</Name>
+        <Description>The types of redline geometry that the user can record. If the data store is SHP, only one geometry type can be specified</Description>
+        <Type>integer</Type>
+        <Label>RedlineGeometryFormat</Label>
+        <AllowedValue>
+          <Name>1</Name>
+          <Label>Point</Label>
+        </AllowedValue>
+        <AllowedValue>
+          <Name>2</Name>
+          <Label>Line</Label>
+        </AllowedValue>
+        <AllowedValue>
+          <Name>4</Name>
+          <Label>Polygon</Label>
+        </AllowedValue>
+        <AllowedValue>
+          <Name>3</Name>
+          <Label>Point+Line</Label>
+        </AllowedValue>
+        <AllowedValue>
+          <Name>5</Name>
+          <Label>Point+Polygon</Label>
+        </AllowedValue>
+        <AllowedValue>
+          <Name>6</Name>
+          <Label>Line+Polygon</Label>
+        </AllowedValue>
+        <AllowedValue>
+          <Name>7</Name>
+          <Label>Point+Line+Polygon</Label>
+        </AllowedValue>
+        <DefaultValue>7</DefaultValue>
+        <IsMandatory>false</IsMandatory>
+    </Parameter>
 </WidgetInfo>



More information about the fusion-commits mailing list