[fusion-commits] r2940 - in trunk/widgets: . Search widgetinfo

svn_fusion at osgeo.org svn_fusion at osgeo.org
Wed May 4 09:54:12 PDT 2016


Author: jng
Date: 2016-05-04 09:54:12 -0700 (Wed, 04 May 2016)
New Revision: 2940

Modified:
   trunk/widgets/Search.js
   trunk/widgets/Search/Search.php
   trunk/widgets/Search/Search.templ
   trunk/widgets/Search/SearchPrompt.php
   trunk/widgets/Search/SearchPrompt.templ
   trunk/widgets/widgetinfo/search.xml
Log:
#641: Add support for zooming of point features in Search widget through a new PointZoomLevel property. Because point features don't have a bounding box, the default zoom to selection behaviour (which is extent-based) does nothing for points. This submission adds a separate point cell click handler for point-feature search results, that will compute an appropriate extent from (x, y, PointZoomLevel) and zoom to that extent. Through the new widget extension property, the author can customize the zoom level of this widget based on the map they intend to use this widget for.

Modified: trunk/widgets/Search/Search.php
===================================================================
--- trunk/widgets/Search/Search.php	2016-05-04 16:04:31 UTC (rev 2939)
+++ trunk/widgets/Search/Search.php	2016-05-04 16:54:12 UTC (rev 2940)
@@ -58,6 +58,7 @@
     $resProps = array();
     $matchLimit = "";
     $features = NULL;
+    $pointZoom = 500.0;
 
     GetRequestParameters();
     SetLocalizedFilesPath(GetLocalizationPath());
@@ -132,6 +133,36 @@
             print sprintf($templ, $colCount, $target, $popup, $mapName);
 
             $classDef = $features->GetClassDefinition();
+            $clsProps = $classDef->GetProperties();
+            $geomName = $classDef->GetDefaultGeometryPropertyName();
+            $bHasPoint = false;
+            $xform = NULL; // layer -> map transform
+            $agfRw = new MgAgfReaderWriter();
+            if ($geomName != NULL && $geomName != "") {
+                $gidx = $clsProps->IndexOf($geomName);
+                if ($gidx >= 0) {
+                    $geomProp = $clsProps->GetItem($gidx);
+                    if ($geomProp->GetGeometryTypes() & MgFeatureGeometricType::Point == MgFeatureGeometricType::Point) {
+                        $bHasPoint = true;
+                        // Set layer -> map transform if required
+                        $scReader = $featureSrvc->GetSpatialContexts($srcId, false);
+                        while ($scReader->ReadNext()) {
+                            if ($scReader->GetName() == $geomProp->GetSpatialContextAssociation()) {
+                                $csFactory = new MgCoordinateSystemFactory();
+                                try {
+                                    $mapCs = $csFactory->Create($map->GetMapSRS());
+                                    $layerCs = $csFactory->Create($scReader->GetCoordinateSystemWkt());
+                                    $xform = $csFactory->GetTransform($layerCs, $mapCs);
+                                } catch (MgException $ex) {
+                                    
+                                }
+                            }
+                        }
+                        $scReader->Close();
+                    }
+                }
+            }
+            
             $idProps = $classDef->GetIdentityProperties();
             $idPropNames = array();
             for($j = 0; $j < $idProps->GetCount(); $j++)
@@ -235,7 +266,23 @@
                     $sel->AddFeatureIds($layer, $featureClassName, $idProps);
                     $selText = EscapeForHtml($sel->ToXml(), true);
 
-                    echo sprintf("<td class=\"%s\" id=\"%d:%d\" onmousemove=\"SelectRow(%d)\" onclick=\"CellClicked('%s')\"> %s</td>\n", !($row%2)? "Search" : "Search2", $row, $i, $row, $selText, $val);
+                    //For points, we want to wire up a different cell click handler
+                    if ($bHasPoint) {
+                        try {
+                            $agf = $features->GetGeometry($geomName);
+                            $geom = $agfRw->Read($agf, $xform);
+                            if ($geom->GetGeometryType() == MgGeometryType::Point) {
+                                $coord = $geom->GetCoordinate();
+                                $x = $coord->GetX();
+                                $y = $coord->GetY();
+                            }
+                            echo sprintf("<td class=\"%s\" id=\"%d:%d\" onmousemove=\"SelectRow(%d)\" onclick=\"PointCellClicked('%s', %g, %g, %g)\"> %s</td>\n", !($row%2)? "Search" : "Search2", $row, $i, $row, $selText, $x, $y, $pointZoom, $val);
+                        } catch (MgException $ex) {
+                            echo sprintf("<td class=\"%s\" id=\"%d:%d\" onmousemove=\"SelectRow(%d)\" onclick=\"CellClicked('%s')\"> %s</td>\n", !($row%2)? "Search" : "Search2", $row, $i, $row, $selText, $val);
+                        }
+                    } else {
+                        echo sprintf("<td class=\"%s\" id=\"%d:%d\" onmousemove=\"SelectRow(%d)\" onclick=\"CellClicked('%s')\"> %s</td>\n", !($row%2)? "Search" : "Search2", $row, $i, $row, $selText, $val);
+                    }
                 }
                 echo "</tr>";
                 if (++ $row == $matchLimit)
@@ -290,6 +337,7 @@
 {
     global $userInput, $target, $layerName, $popup, $locale;
     global $mapName, $sessionId, $filter, $resNames, $resProps, $matchLimit;
+    global $pointZoom;
 
     if(isset($params['locale']))
         $locale = $params['locale'];
@@ -310,6 +358,9 @@
             array_push($resProps, $params['CP' . $i]);
         }
     }
+    if (isset($params['pointZoom'])) {
+        $pointZoom = $params['pointZoom'];
+    }
 }
 
 function GetRequestParameters()

Modified: trunk/widgets/Search/Search.templ
===================================================================
--- trunk/widgets/Search/Search.templ	2016-05-04 16:04:31 UTC (rev 2939)
+++ trunk/widgets/Search/Search.templ	2016-05-04 16:54:12 UTC (rev 2940)
@@ -86,6 +86,14 @@
     map.setSelection(sel, true);
 }
 
+function PointCellClicked(sel, x, y, zoom)
+{
+    var map = GetParent().Fusion.getMapByName(mapName);
+    map.setSelection(sel, true);
+    var extents = map.mapWidget.getExtentFromPoint(x, y, zoom);
+    map.mapWidget.setExtents(extents);
+}
+
 function highlightRow(index, mode)
 {
     for(var i=0; i < colCount; i++)

Modified: trunk/widgets/Search/SearchPrompt.php
===================================================================
--- trunk/widgets/Search/SearchPrompt.php	2016-05-04 16:04:31 UTC (rev 2939)
+++ trunk/widgets/Search/SearchPrompt.php	2016-05-04 16:54:12 UTC (rev 2940)
@@ -37,6 +37,7 @@
     $mapName = "";
     $sessionId = "";
     $widgetName = "";
+    $pointZoomLevel = 500.0;
 
     GetRequestParameters();
 
@@ -44,7 +45,7 @@
     SetLocalizedFilesPath(GetLocalizationPath());
     $templ = Localize($templ, $locale, GetClientOS());
     $vpath = GetSurroundVirtualPath();
-    print sprintf($templ, $popup, $properties, $propNames, $title, $prompt, $target, $filter, $layer, $limit, $vpath."Search.php", $mapName, $sessionId, $locale);
+    print sprintf($templ, $popup, $properties, $propNames, $title, $prompt, $target, $filter, $layer, $limit, $vpath."Search.php", $mapName, $sessionId, $locale, $pointZoomLevel);
 
 
 
@@ -54,6 +55,7 @@
     global $mapName, $sessionId;
     global $title, $prompt, $target, $filter, $layer, $limit;
     global $propNames, $properties;
+    global $pointZoomLevel;
 
     if(isset($params['locale'])) {
         $locale = $params['locale'];
@@ -69,6 +71,9 @@
     $filter = $params['filter'];
     $layer = $params['layer'];
     $limit = $params['limit'];
+    if (isset($params['pointZoomLevel'])) {
+        $pointZoomLevel = $params['pointZoomLevel'];
+    }
 }
 
 function GetRequestParameters()

Modified: trunk/widgets/Search/SearchPrompt.templ
===================================================================
--- trunk/widgets/Search/SearchPrompt.templ	2016-05-04 16:04:31 UTC (rev 2939)
+++ trunk/widgets/Search/SearchPrompt.templ	2016-05-04 16:54:12 UTC (rev 2940)
@@ -122,6 +122,7 @@
         <input type="hidden" name="layer" id="layer">
         <input type="hidden" name="filter" id="filter">
         <input type="hidden" name="limit" id="limit">
+        <input type="hidden" name="pointZoom" id="pointZoom" value="%s">
         <div id="MatchLabel">
         </div>
         <br><br>

Modified: trunk/widgets/Search.js
===================================================================
--- trunk/widgets/Search.js	2016-05-04 16:04:31 UTC (rev 2939)
+++ trunk/widgets/Search.js	2016-05-04 16:54:12 UTC (rev 2940)
@@ -50,6 +50,7 @@
         this.limit = json.MatchLimit ? json.MatchLimit[0] : 100;
         this.resultColumns = json.ResultColumns ? json.ResultColumns[0].Column : [];
         this.title = json.Title ? json.Title[0] : widgetTag.label;
+        this.pointZoomLevel = json.PointZoomLevel ? json.PointZoomLevel[0] : 500.0;
     },
 
     activate: function() {
@@ -75,6 +76,7 @@
         params.push('filter='+this.filter);
         params.push('layer='+this.layer);
         params.push('limit='+this.limit);
+        params.push('pointZoomLevel='+this.pointZoomLevel);
         var names = [];
         var props = [];
         for (var i=0; i<this.resultColumns.length; ++i) {

Modified: trunk/widgets/widgetinfo/search.xml
===================================================================
--- trunk/widgets/widgetinfo/search.xml	2016-05-04 16:04:31 UTC (rev 2939)
+++ trunk/widgets/widgetinfo/search.xml	2016-05-04 16:54:12 UTC (rev 2940)
@@ -66,4 +66,12 @@
     <DefaultValue></DefaultValue>
     <IsMandatory>false</IsMandatory>
   </Parameter>
+  <Parameter>
+    <Name>PointZoomLevel</Name>
+    <Label>Point zoom level</Label>
+    <Type>double</Type>
+    <Description>The zoom level to use when clicking on a point feature search result. Note that when basemaps are active, it will zoom to the discrete zoom level closest to the specified value</Description>
+    <DefaultValue>500.0</DefaultValue>
+    <IsMandatory>false</IsMandatory>
+  </Parameter>
 </WidgetInfo>



More information about the fusion-commits mailing list