[fusion-commits] r2039 - in sandbox/jxlib-3.0: layers/MapServer layers/MapServer/php widgets

svn_fusion at osgeo.org svn_fusion at osgeo.org
Fri Jan 15 15:41:29 EST 2010


Author: madair
Date: 2010-01-15 15:41:28 -0500 (Fri, 15 Jan 2010)
New Revision: 2039

Added:
   sandbox/jxlib-3.0/layers/MapServer/php/GetAttributes.php
   sandbox/jxlib-3.0/widgets/GetFeatureInfo.js
   sandbox/jxlib-3.0/widgets/SelectAttribute.js
Modified:
   sandbox/jxlib-3.0/layers/MapServer/MapServer.js
   sandbox/jxlib-3.0/layers/MapServer/php/Query.php
Log:
adding initial version of Query by Attribute and GetFeatureInfo

Modified: sandbox/jxlib-3.0/layers/MapServer/MapServer.js
===================================================================
--- sandbox/jxlib-3.0/layers/MapServer/MapServer.js	2010-01-14 21:01:35 UTC (rev 2038)
+++ sandbox/jxlib-3.0/layers/MapServer/MapServer.js	2010-01-15 20:41:28 UTC (rev 2039)
@@ -755,6 +755,7 @@
         };
         if (options.filter) {
             params.filter = options.filter;
+            params.filterItem = options.filterItem;
         }
         if (options.extendSelection) {
             params.extendselection = true;

Added: sandbox/jxlib-3.0/layers/MapServer/php/GetAttributes.php
===================================================================
--- sandbox/jxlib-3.0/layers/MapServer/php/GetAttributes.php	                        (rev 0)
+++ sandbox/jxlib-3.0/layers/MapServer/php/GetAttributes.php	2010-01-15 20:41:28 UTC (rev 2039)
@@ -0,0 +1,113 @@
+<?php
+/**
+ * GetAttributes
+ *
+ * $Id: GetAttributes.php 1972 2009-11-11 20:47:47Z pagameba $
+ *
+ * Copyright (c) 2007, DM Solutions Group Inc.
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included
+ * in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ */
+
+/*****************************************************************************
+ * Purpose: create a new selection based on one or more attribute filters and
+ *          a spatial filter
+ *****************************************************************************/
+
+/* set up the session */
+include ("Common.php");
+include('../../../common/php/Utilities.php');
+
+header('Content-type: application/json');
+header('X-JSON: true');
+
+/* the name of the layer in the map to query */
+if ($_REQUEST['layers'] != '') {
+    $layers = explode(',',$_REQUEST['layers']);
+} else {
+    $layers = array();
+}
+
+//echo "<!--";
+//print_r($_REQUEST);
+//echo "-->";
+
+if (!isset($mapName)) {
+    die('mapname not set');
+}
+if (isset($_SESSION['maps']) && isset($_SESSION['maps'][$mapName])) {
+    $oMap = ms_newMapObj($_SESSION['maps'][$mapName]);
+}
+
+$bAllLayers = false;
+$nLayers = count($layers);
+if ($nLayers == 0) {
+    $nLayers = $oMap->numlayers;
+    $bAllLayers = true;
+}
+
+/*holds selection array*/
+$properties = NULL;
+$properties->layers = array();
+    echo "/* nLayers: ".$nLayers." */";
+
+for ($i=0; $i<$nLayers; $i++) {
+    if (!$bAllLayers) {
+        $oLayer = $oMap->GetLayerByName($layers[$i]);
+    } else {
+        $oLayer = $oMap->GetLayer($i);
+    }
+    
+    $selectable = strtolower($oLayer->getMetaData('selectable'));
+    if ( $selectable == 'true' ) {
+       
+       
+      $oLayer->open();
+      $layerName = $oLayer->name != "" ? $oLayer->name : "Layer_".$i; 
+      echo "/* layername: ".$layerName." */";
+      
+      array_push($properties->layers, $layerName);
+  
+      $properties->$layerName->propertynames = array();
+      $properties->$layerName->propertyvalues = array();
+      $properties->$layerName->propertytypes = array();
+  
+      /*get first shape to get the attributes*/
+      //$oRes = $oLayer->getResult(0);
+      //$oShape = $oLayer->getShape($oRes->tileindex,$oRes->shapeindex);
+      $oShape = $oLayer->getFeature(0);
+      
+      while ( list($key,$val) = each($oShape->values) ) {
+              array_push($properties->$layerName->propertynames, $key);
+              //TODO : we should define away to give alias to field names
+              array_push($properties->$layerName->propertyvalues, $key);
+              //TODO we do not know the types of the attributes in MS. Just output 0
+              //we shouls possibly use OGR to get the attributes
+              array_push($properties->$layerName->propertytypes, 0);
+      }
+      
+      $oLayer->close();
+    }
+}
+
+/*save selection in the session*/
+$_SESSION['selection_array'] = $properties; 
+
+echo var2json($properties);
+
+?>

Modified: sandbox/jxlib-3.0/layers/MapServer/php/Query.php
===================================================================
--- sandbox/jxlib-3.0/layers/MapServer/php/Query.php	2010-01-14 21:01:35 UTC (rev 2038)
+++ sandbox/jxlib-3.0/layers/MapServer/php/Query.php	2010-01-15 20:41:28 UTC (rev 2039)
@@ -34,6 +34,9 @@
 include ("Utilities.php");
 include('../../../common/php/Utilities.php');
 
+header('Content-type: application/json');
+header('X-JSON: true');
+
 /* the name of the layer in the map to query */
 if ($_REQUEST['layers'] != '') {
     $layers = explode(',',$_REQUEST['layers']);
@@ -54,8 +57,9 @@
         $variant = 'inside';
     }
 }
-/* a filter expression to apply, in the form of an FDO SQL statement */
-$filter = isset($_REQUEST['filter']) ? str_replace(array('*', '"'), array('%', "'"),html_entity_decode(urldecode( $_REQUEST['filter']))) : false;
+/* a filter expression to apply, in the form of an MapServer expression statement */
+$filter = isset($_REQUEST['filter']) ? html_entity_decode(urldecode( $_REQUEST['filter'])) : false;
+$filterItem = isset($_REQUEST['filterItem']) ? html_entity_decode(urldecode( $_REQUEST['filterItem'])) : false;
 //echo "<!-- filter: $filter -->\n";
 /* a spatial filter in the form on a WKT geometry */
 $spatialFilter = (isset($_REQUEST['spatialfilter']) && $_REQUEST['spatialfilter'] != '') ? urldecode($_REQUEST['spatialfilter']) : false;
@@ -103,7 +107,6 @@
     $nLayers = $oMap->numlayers;
     $bAllLayers = true;
 }
-
 $result = NULL;
 $result->hasSelection = false;
 $result->layers = array();
@@ -118,15 +121,26 @@
         $oLayer->type ==  MS_LAYER_CIRCLE ||  $oLayer->type == MS_LAYER_CHART) {
         continue;            
     }
-
-    
-    if (@$oLayer->queryByShape($oSpatialFilter) == MS_SUCCESS) {
-        $result->hasSelection = true;
-        $layerName = $oLayer->name;
-        array_push($result->layers, $layerName);
-        $result->$layerName->featureCount = $oLayer->getNumResults();
-        //TODO: dump out the extents of the selection
+    if ($spatialFilter !== false ) {
+      if (@$oLayer->queryByShape($oSpatialFilter) == MS_SUCCESS) {
+          $result->hasSelection = true;
+          $layerName = $oLayer->name;
+          array_push($result->layers, $layerName);
+          $result->$layerName->featureCount = $oLayer->getNumResults();
+          //TODO: dump out the extents of the selection
+      }
     }
+    if ($filter !== false ) {
+      if (@$oLayer->queryByAttributes($filterItem,$filter,MS_MULTIPLE) == MS_SUCCESS) {
+      //if (@$oLayer->queryByAttributes($filterItem,'([REG_CODE] eq 61)',MS_MULTIPLE) == MS_SUCCESS) {
+      //if (@$oLayer->queryByAttributes('NAME_E','/.*Buffalo.*/gi',MS_MULTIPLE) == MS_SUCCESS) {
+          $result->hasSelection = true;
+          $layerName = $oLayer->name;
+          array_push($result->layers, $layerName);
+          $result->$layerName->featureCount = $oLayer->getNumResults();
+          //TODO: dump out the extents of the selection
+      }
+    }
 
     if ($bExtendSelection) {
     } else {
@@ -135,8 +149,6 @@
 if ($bExtendSelection) {
 }
 
-header('Content-type: application/json');
-header('X-JSON: true');
 if ($result->hasSelection) {
     $oMap->savequery(getSessionSavePath()."query.qy");
     $result->queryFile = getSessionSavePath()."query.qy";

Added: sandbox/jxlib-3.0/widgets/GetFeatureInfo.js
===================================================================
--- sandbox/jxlib-3.0/widgets/GetFeatureInfo.js	                        (rev 0)
+++ sandbox/jxlib-3.0/widgets/GetFeatureInfo.js	2010-01-15 20:41:28 UTC (rev 2039)
@@ -0,0 +1,164 @@
+/**
+ * Fusion.Widget.GetFeatureInfo
+ *
+ * $Id: GetFeatureInfo.js 1377 2008-04-16 19:27:32Z madair $
+ *
+ * Copyright (c) 2007, DM Solutions Group Inc.
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included
+ * in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ */
+
+ /********************************************************************
+ * Class: Fusion.Widget.GetFeatureInfo
+ *
+ * A widget that displays a pre-configured search form to the user and then
+ * runs the search.  Searches are done on the attributes of specifiedd layers.
+ *
+ * uses JavaScript Scale Bar for MapServer 
+ * (http://mapserver.commenspace.org/tools/scalebar/
+ * **********************************************************************/
+
+Fusion.Event.GET_FEATURE_INFO_COMPLETE = Fusion.Event.lastEventId++;
+
+Fusion.Widget.GetFeatureInfo = OpenLayers.Class(Fusion.Widget, 
+{
+    wmsLayers: [],
+    isExclusive: true,
+    uiClass: Jx.Button,
+    
+    initializeWidget: function(widgetTag) {
+        //console.log('GetFeatureInfo.initialize');
+        var json = widgetTag.extension;
+        
+        var map = this.getMap().oMapOL;
+        // create a new event handler for single click query
+        this.handler = new OpenLayers.Handler.Click({ 'map': map }, {
+            'click': OpenLayers.Function.bind(this.issueRequest, this) }); 
+        
+        this.registerEventID(Fusion.Event.GET_FEATURE_INFO_COMPLETE);
+        this.getMap().registerEventID(Fusion.Event.WMS_LAYER_ADDED);
+        this.getMap().registerForEvent(Fusion.Event.WMS_LAYER_ADDED, 
+                          OpenLayers.Function.bind(this.layerAdded,this));
+        this.cursorNormal = ["url('images/grab.cur'),move", 'grab', '-moz-grab', 'move'];
+    },
+    
+    /**
+     * (public) activate()
+     *
+     * activate the measure tool
+     */
+    activateTool: function() {
+        this.getMap().activateWidget(this);
+    },
+
+    activate: function() {
+        this.handler.activate();
+    },
+    
+    deactivate: function() {
+        this.handler.deactivate();
+    },
+    
+    issueRequest: function(e) {
+      if (this.wmsLayers.length < 1) {
+        alert("there are no WMS layers to query");
+        return;
+      }
+      
+      var map = this.getMap();
+      var queryLayer = map.getActiveLayer();
+      var layer = null;
+      if (queryLayer) {
+        for (var i=0; i<this.wmsLayers.length; ++i) {
+          if (queryLayer.layerName == this.wmsLayers[i].wms_name) {
+            layer = this.wmsLayers[i];
+            break;
+          }
+        }
+      }
+      if (!layer) {
+        alert('Please select a WMS layer by clicking on the layer name in the legend.');
+        return;
+      }
+      
+      var infoFormat = 'text/html';
+      if (e.shiftKey) {
+        infoFormat = 'text/plain';
+      } else if (e.ctrlKey) {
+        infoFormat = 'text/xml';
+      }
+      var size = map.oMapOL.getSize();
+      var mouseLoc = map.oMapOL.getLonLatFromPixel(e.xy);
+      //for (var i=0; i<this.wmsLayers.length; ++i) {
+        //var layer = this.wmsLayers[i];
+        var params = {
+                      REQUEST: "GetFeatureInfo",
+                      VERSION: layer.wms_version,
+                      SRS: layer.wms_srs,
+                      FORMAT: layer.wms_format,
+                      STYLES: "",
+                      EXCEPTIONS: "application/vnd.ogc.se_xml",
+                      BBOX: map.getCurrentExtents().toBBOX(),
+                      X: e.xy.x,
+                      Y: e.xy.y,
+                      INFO_FORMAT: infoFormat,
+                      LAYERS: layer.wms_name,
+                      QUERY_LAYERS: layer.wms_name,
+                      WIDTH: size.w,
+                      HEIGHT: size.h};
+        var join = (layer.wms_connection.indexOf('?')<0) ? '?' : '&';
+        var url = layer.wms_connection + join + OpenLayers.Util.getParameterString(params);
+        /*
+        var proxy = '/fusion-1.1/ext/coin/php/RemoteQuery.php?rawoutput=true&remoteUrl=';
+        url = proxy + url;
+        var infoDialog = new Jx.Dialog({
+            contentURL: url,
+            modal: false,
+            title: 'Feature information for '+layer.wms_name,
+            resizable: true
+        });
+        infoDialog.open();
+        */
+        //console.log(url);
+        window.open(url);
+        /*
+        OpenLayers.Request.GET({
+            url: layer.wms_connection, 
+            params: params,
+            success: OpenLayers.Function.bind(this.displayResults, this), 
+            failure: OpenLayers.Function.bind(this.getFeatureInfoFailed, this), 
+            scope: this
+        });
+        */
+      //}
+      OpenLayers.Event.stop(e);
+    },
+    
+    displayResults: function(arg1, arg2) {
+    },
+    
+    getFeatureInfoFailed: function(arg1, arg2) {
+    },
+    
+    layerAdded: function(eventId, layers) {
+      for (var i=0; i<layers.length; ++i) {
+        this.wmsLayers.push(layers[i]);
+      }
+    }
+});
+

Added: sandbox/jxlib-3.0/widgets/SelectAttribute.js
===================================================================
--- sandbox/jxlib-3.0/widgets/SelectAttribute.js	                        (rev 0)
+++ sandbox/jxlib-3.0/widgets/SelectAttribute.js	2010-01-15 20:41:28 UTC (rev 2039)
@@ -0,0 +1,184 @@
+/**
+ * Fusion.Widget.SelectRadius
+ *
+ * $Id: SelectRadius.js 1816 2009-03-11 20:33:51Z pagameba $
+ *
+ * Copyright (c) 2007, DM Solutions Group Inc.
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included
+ * in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ */
+
+ /********************************************************************
+ * Class: Fusion.Widget.SelectRadius
+ *
+ * perform a selection by radius from a point
+ * 
+ * **********************************************************************/
+Fusion.Event.RADIUS_WIDGET_ACTIVATED = Fusion.Event.lastEventId++;
+
+Fusion.Widget.SelectAttribute = OpenLayers.Class(Fusion.Widget, {
+    isExclusive: true,
+    uiClass: Jx.Button,
+    
+    initializeWidget: function(widgetTag) {
+        var json = widgetTag.extension;
+        
+        if (json.Container) {
+          this.container = $(json.Container[0]);
+        }
+        this.workArea = document.createElement('div');
+        this.workArea.style.display = 'none';
+        this.container.appendChild(this.workArea);
+        
+        //eventually there will be multiple rows for AND/OR ops on attributes
+        this.attrRow = document.createElement('div');
+        this.attrRow.className = 'selectAttrInputs';
+        this.workArea.appendChild(this.attrRow);
+
+        this.getMap().registerForEvent(Fusion.Event.MAP_LOADED, OpenLayers.Function.bind(this.listLayers, this));
+    },
+    
+    /**
+     * populate th list of seletable layers when the map loads
+     */
+    listLayers: function() {
+        var map = this.getMap().aMaps[0]; 
+        var d = document.createElement('div');
+        d.innerHTML = "layer to query:";
+        this.layerList = document.createElement('select');
+        this.layerList.className = 'layerSelector';
+        this.layerList.onchange = OpenLayers.Function.bind(this.setAttributeOptions, this);
+        this.layerList.add(new Option('--select--',''),null);
+        d.appendChild(this.layerList);
+        this.attrRow.appendChild(d);
+        for (var i=0; i<map.aLayers.length; ++i) {
+            var layer = map.aLayers[i];
+            if (layer.selectable) {
+              this.layerList.add(new Option(layer.legendLabel,layer.layerName),null);
+            }
+        }
+        
+        var sl = Fusion.getScriptLanguage();
+        var queryScript = 'layers/' + map.arch + '/' + sl  + '/GetAttributes.' + sl;
+        var params = {
+            'mapname': map._sMapname,
+            'session': map.getSessionID()
+            //'layers': layers,
+        };
+        var ajaxOptions = {
+            onSuccess: OpenLayers.Function.bind(this.setAttributes, this),
+            method: 'GET',
+            parameters: params
+        };
+        Fusion.ajaxRequest(queryScript, ajaxOptions);
+        
+    },
+    
+    setAttributes: function(xhr) {
+      if (xhr.status < 400) {
+          eval('this.attrs='+xhr.responseText);
+      }
+    },
+    
+    setAttributeOptions: function(event) {
+      this.propsList.empty();
+      var layer = this.layerList[this.layerList.selectedIndex].value;
+      var attrs = this.attrs[layer].propertyvalues;
+      var props = this.attrs[layer].propertynames;
+      for (var i=0; i<attrs.length; ++i) {
+          this.propsList.add(new Option(attrs[i],props[i]),null);
+      }
+    },
+    
+    /**
+     * activate the widget (listen to mouse events and change cursor)
+     * This function should be defined for all functions that register
+     * as a widget in the map
+     */
+    activate: function() {
+        this.workArea.style.display = 'block';
+        this.attrRow.innerHTML = "";
+        
+        this.propsList = document.createElement('select');
+        this.propsList.className = 'propsSelector';
+        this.attrRow.appendChild(this.propsList);
+        
+        this.operatorList = document.createElement('select');
+        this.operatorList.className = 'operatorSelector';
+        this.operatorList.add(new Option("=","eq",true),null);
+        this.operatorList.add(new Option("like","like"),null);
+        this.operatorList.add(new Option(">","gt"),null);
+        this.operatorList.add(new Option("<","lt"),null);
+        this.operatorList.add(new Option("<=","le"),null);
+        this.operatorList.add(new Option(">=","ge"),null);
+        this.operatorList.add(new Option("!=","ne"),null);
+        this.attrRow.appendChild(this.operatorList);
+        
+        this.attrValue = document.createElement('input');
+        this.attrValue.className = 'propsValue';
+        this.attrRow.appendChild(this.attrValue);
+        
+        new Jx.Button({
+            label: 'Query',
+            onClick: OpenLayers.Function.bind(this.execute, this)
+        }).addTo(this.attrRow);
+    },
+
+    /**
+     * deactivate the widget (listen to mouse events and change cursor)
+     * This function should be defined for all functions that register
+     * as a widget in the map
+     **/
+    deactivate: function() {
+        this.workArea.style.display = 'none';
+    },
+    
+    /**
+     *  set the extants of the map based on the pixel coordinates
+     * passed
+     * 
+     * @param center
+     * @param radius
+     **/
+    execute: function() {
+        var propertyName = this.propsList[this.propsList.selectedIndex].value;
+        var operator = this.operatorList[this.operatorList.selectedIndex].value;
+        var propertyValue = this.attrValue.value;
+        var numValue = parseFloat(propertyValue);
+        var filter = null;
+        if ( isNaN(numValue) ) {
+          //we have a string
+          if (operator == 'like') {
+            filter = "/.*"+propertyValue+".*/gi";
+          } else {
+            filter = "(["+propertyName+"] "+operator+" '"+propertyValue+"')";
+          }
+        } else {
+          //we have a number
+            filter = "(["+propertyName+"] "+operator+" "+propertyValue+")";
+        }
+        var options = {
+          layers: this.layerList[this.layerList.selectedIndex].value,
+          filterItem: propertyName,
+          filter: filter
+        };
+        
+        this.getMap().query(options);
+        this.attrRow.style.display = 'none';
+    }
+});



More information about the fusion-commits mailing list