[fusion-commits] r1743 - in trunk/layers/MapGuide: . php
svn_fusion at osgeo.org
svn_fusion at osgeo.org
Fri Jan 23 15:33:54 EST 2009
Author: chrisclaydon
Date: 2009-01-23 15:33:53 -0500 (Fri, 23 Jan 2009)
New Revision: 1743
Added:
trunk/layers/MapGuide/php/GetSelectionProperties.php
trunk/layers/MapGuide/php/SaveSelection.php
Removed:
trunk/layers/MapGuide/php/SetSelection.php
Modified:
trunk/layers/MapGuide/MapGuide.js
Log:
Fix #199 - Add selection enhancements previously added to mg21 branch to trunk code stream.
Modified: trunk/layers/MapGuide/MapGuide.js
===================================================================
--- trunk/layers/MapGuide/MapGuide.js 2009-01-22 21:01:39 UTC (rev 1742)
+++ trunk/layers/MapGuide/MapGuide.js 2009-01-23 20:33:53 UTC (rev 1743)
@@ -147,13 +147,12 @@
showgroups: showgroups == '' ? [] : showgroups.split(','),
hidegroups: hidegroups == '' ? [] : hidegroups.split(',')
};
- }
+ }
this.loadMap(this.sMapResourceId, options);
}
window.setInterval(OpenLayers.Function.bind(this.pingServer, this), this.keepAliveInterval * 1000);
},
-
sessionReady: function() {
return (typeof this.session[0] == 'string');
},
@@ -643,14 +642,13 @@
},
/**
- * advertise a new selection is available and redraw the map
+ * advertise a new selection is available
*/
newSelection: function() {
if (this.oSelection) {
this.oSelection = null;
}
this.bSelectionOn = true;
- this.drawSelection();
this.triggerEvent(Fusion.Event.MAP_SELECTION_ON);
},
@@ -691,22 +689,62 @@
return layers;
},
+ /**
+ * Updates the current map selection with the provided XML selection string.
+ * Optionally zooms to the new selection on the map, if zoomTo is set to true.
+ */
setSelection: function (selText, zoomTo) {
+
+ //TODO Update this.previousSelection when the selection is set using
+ //this API to allow the selection to be extended with a shift-click.
+
+ if(selText != "" && selText != null) {
+ this.updateSelection(selText, zoomTo, false);
+ }
+ else {
+ this.clearSelection();
+ }
+ },
+
+ updateSelection: function (selText, zoomTo, extendSelection) {
+ this.updateMapSelection(selText, zoomTo);
+ this.getSelectedFeatureProperties(selText);
+ },
+
+
+ getSelectedFeatureProperties: function (selText) {
this.mapWidget._addWorker();
var sl = Fusion.getScriptLanguage();
- var setSelectionScript = 'layers/' + this.arch + '/' + sl + '/SetSelection.' + sl;
+ var getPropertiesScript = 'layers/' + this.arch + '/' + sl + '/GetSelectionProperties.' + sl;
var params = {
'mapname': this.getMapName(),
'session': this.getSessionID(),
'selection': selText,
'seq': Math.random()
};
- var options = {onSuccess: OpenLayers.Function.bind(this.processQueryResults, this, zoomTo),
- parameters:params, asynchronous:false};
- Fusion.ajaxRequest(setSelectionScript, options);
+ var options = {onSuccess: OpenLayers.Function.bind(this.processSelectedFeatureProperties, this),
+ parameters:params};
+ Fusion.ajaxRequest(getPropertiesScript, options);
},
+ updateMapSelection: function (selText, zoomTo) {
+ this.mapWidget._addWorker();
+ var sl = Fusion.getScriptLanguage();
+ var updateSelectionScript = 'layers/' + this.arch + '/' + sl + '/SaveSelection.' + sl;
+ var params = {
+ 'mapname': this.getMapName(),
+ 'session': this.getSessionID(),
+ 'selection': selText,
+ 'seq': Math.random(),
+ 'getextents' : zoomTo ? 'true' : 'false'
+ };
+ var options = {onSuccess: OpenLayers.Function.bind(this.renderSelection, this, zoomTo),
+ parameters:params};
+ Fusion.ajaxRequest(updateSelectionScript, options);
+ },
+
+
/**
* asynchronously load the current selection. When the current
* selection changes, the selection is not loaded because it
@@ -782,6 +820,10 @@
};
Fusion.ajaxRequest(s, options);
}
+ if (this.previousSelection != null)
+ {
+ this.previousSelection.clear();
+ }
},
/**
@@ -796,15 +838,35 @@
/**
- Call back function when slect functions are called (eg queryRect)
+ Call back function when select functions are called (eg queryRect)
+ to handle feature attributes
*/
- processQueryResults: function(zoomTo, r) {
+ processSelectedFeatureProperties: function(r) {
this.mapWidget._removeWorker();
if (r.responseText) { //TODO: make the equivalent change to MapServer.js
var oNode;
eval('oNode='+r.responseText);
if (oNode.hasSelection) {
+ this.newSelection();
+ } else {
+ this.clearSelection();
+ return;
+ }
+ }
+ },
+
+ /**
+ Call back function when select functions are called (eg queryRect)
+ to render the selection
+ */
+ renderSelection: function(zoomTo, r) {
+ this.mapWidget._removeWorker();
+ if (r.responseText) { //TODO: make the equivalent change to MapServer.js
+ var oNode;
+ eval('oNode='+r.responseText);
+
+ if (oNode.hasSelection) {
if (this.selectionAsOverlay) {
if (!this.queryLayer) {
this.queryLayer = this.createOLLayer("query layer", false, true, 5);
@@ -831,7 +893,7 @@
var extents = new OpenLayers.Bounds(ext.minx, ext.miny, ext.maxx, ext.maxy);
this.mapWidget.setExtents(extents);
}
- this.newSelection();
+ this.drawSelection();
} else {
this.clearSelection();
return;
@@ -850,34 +912,23 @@
this.aLayers[j].selectedFeatureCount = 0;
}
- var bPersistant = options.persistent || true;
- var zoomTo = options.zoomTo ? true : false;
- var sl = Fusion.getScriptLanguage();
- var loadmapScript = 'layers/' + this.arch + '/' + sl + '/Query.' + sl;
-
- var params = {
- 'mapname': this._sMapname,
- 'session': this.getSessionID(),
- 'spatialfilter': options.geometry || '',
- 'computed': options.computed || '',
- 'queryHiddenLayers': options.queryHiddenLayers || 'false',
- 'maxfeatures': options.maxFeatures || 0, //zero means select all features
- 'layers': options.layers || '',
- 'variant': options.selectionType || this.selectionType
- };
- if (options.filter) {
- params.filter= options.filter;
+ var persist = 1;
+ var layerAttributeFilter = 3;
+ var maxFeatures = options.maxFeatures;
+ if(maxFeatures == null || maxFeatures == 0)
+ {
+ maxFeatures = -1;
}
- if (options.extendSelection) {
- params.extendselection = true;
- }
- if (options.computedProperties) {
- params.computed = true;
- }
- var ajaxOptions = {
- onSuccess: OpenLayers.Function.bind(this.processQueryResults, this, zoomTo),
- parameters: params};
- Fusion.ajaxRequest(loadmapScript, ajaxOptions);
+ var r = new Fusion.Lib.MGRequest.MGQueryMapFeatures(this.getSessionID(),
+ this._sMapname,
+ options.geometry,
+ maxFeatures,
+ persist,
+ options.selectionType || this.selectionType,
+ options.layers,
+ layerAttributeFilter);
+ var callback = (options.extendSelection == true) ? OpenLayers.Function.bind(this.processAndMergeFeatureInfo, this) : OpenLayers.Function.bind(this.processFeatureInfo, this);
+ Fusion.oBroker.dispatchRequest(r, OpenLayers.Function.bind(Fusion.xml2json, this, callback));
},
showLayer: function( layer, noDraw ) {
@@ -1044,7 +1095,250 @@
url += "&TS=" + (new Date()).getTime();
}
return url;
+ },
+
+
+ processAndMergeFeatureInfo: function (r) {
+ this.processSelectedFeatureInfo(r, true);
+ },
+
+ processFeatureInfo: function (r) {
+ this.processSelectedFeatureInfo(r, false);
+ },
+
+ processSelectedFeatureInfo: function (r, mergeSelection) {
+ eval('o='+r.responseText);
+
+ var newSelection = new Fusion.SimpleSelectionObject(o);
+ if(mergeSelection == true)
+ {
+ newSelection.merge(this.previousSelection);
+ }
+ this.previousSelection = newSelection;
+
+ var selText = newSelection.getSelectionXml();
+ this.setSelection(selText, false);
+ this.mapWidget._removeWorker();
}
+});
+Fusion.SimpleSelectionObject = OpenLayers.Class({
+ aLayers : null,
+ nLayers : 0,
+
+ initialize: function(featureInfoResponse)
+ {
+ this.aLayers = [];
+ this.nLayers = 0;
+ try
+ {
+ var layers = featureInfoResponse.FeatureInformation.FeatureSet[0].Layer;
+ if (layers != null)
+ {
+ for(var i = 0; i < layers.length; i++)
+ {
+ var layerId = o['FeatureInformation']['FeatureSet'][0]['Layer'][i]['@id'][0];
+
+ var classElt = o['FeatureInformation']['FeatureSet'][0]['Layer'][i]['Class'][0];
+ var className = o['FeatureInformation']['FeatureSet'][0]['Layer'][i]['Class'][0]['@id'][0];
+
+ var layer = new Fusion.SimpleSelectionObject.Layer(layerId, className);
+
+ this.addLayer(layer);
+
+ var features = classElt.ID;
+ for(var j=0; j < features.length; j++)
+ {
+ layer.addFeature(features[j]);
+ }
+ }
+ }
+ }
+ catch(e) {}
+
+ },
+
+ addLayer: function(layer)
+ {
+ this.aLayers[this.nLayers] = layer;
+ this.nLayers++;
+ },
+
+ getNumLayers : function()
+ {
+ return this.nLayers;
+ },
+
+ getLayerByName : function(name)
+ {
+ var oLayer = null;
+ for (var i=0; i<this.nLayers; i++)
+ {
+ if (this.aLayers[i].getName() == name)
+ {
+ oLayer = this.aLayers[i];
+ break;
+ }
+ }
+ return oLayer;
+ },
+
+ getLayer : function(iIndice)
+ {
+ if (iIndice >=0 && iIndice < this.nLayers)
+ {
+ return this.aLayers[iIndice];
+ }
+ else
+ {
+ return null;
+ }
+ },
+
+ getSelectionXml : function()
+ {
+ var xmlSelection = "";
+ if(this.nLayers > 0)
+ {
+ xmlSelection = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<FeatureSet>\n";
+ for(var i = 0; i < this.nLayers; i++)
+ {
+ var layer = this.aLayers[i];
+ xmlSelection += "<Layer id=\"" + layer.getName() + "\">\n";
+ xmlSelection += "<Class id=\"" + layer.getClassName() + "\">\n";
+ for(var j = 0; j < layer.getNumFeatures(); j++)
+ {
+ var featId = layer.featIds[j];
+ xmlSelection += "<ID>" + featId + "</ID>\n";
+ }
+ xmlSelection += "</Class>\n</Layer>\n";
+ }
+ xmlSelection += "</FeatureSet>\n";
+ }
+ return xmlSelection;
+ },
+
+ merge : function(previousSelection)
+ {
+ if (previousSelection != null && previousSelection.nLayers > 0)
+ {
+ for (var prevSelIndex = 0; prevSelIndex < previousSelection.nLayers; prevSelIndex++)
+ {
+ var prevSelLayer = previousSelection.aLayers[prevSelIndex];
+
+ // find the previously selected layer name in the current selection
+ var currentLayer = this.getLayerByName(prevSelLayer.getName());
+ if (currentLayer != null)
+ {
+ // add the previously selected features for this layer
+ for (var j = 0; j < prevSelLayer.getNumFeatures(); j++)
+ {
+ var prevSelFeatureIndexes = currentLayer.featIds.find(prevSelLayer.featIds[j]);
+ if (prevSelFeatureIndexes == null)
+ {
+ currentLayer.addFeature(prevSelLayer.featIds[j]);
+ }
+ else
+ {
+ // the feature was previously selected, so toggle it off when selected again
+ currentLayer.removeFeatures(prevSelFeatureIndexes);
+ }
+ }
+ if (currentLayer.featIds.length == 0)
+ {
+ this.clear();
+ }
+ }
+ else
+ {
+ // the current selection does not include this previously selected layer
+
+ // need to add this previously selected layer and its features
+ var missingLayer = new Fusion.SimpleSelectionObject.Layer(prevSelLayer.getName(), prevSelLayer.getClassName());
+ for (var k = 0; k < prevSelLayer.getNumFeatures(); k++)
+ {
+ missingLayer.addFeature(prevSelLayer.featIds[k]);
+ }
+ this.addLayer(missingLayer);
+ }
+ }
+ }
+ },
+
+ clear: function()
+ {
+ this.aLayers = [];
+ this.nLayers = 0;
+ }
});
+Fusion.SimpleSelectionObject.Layer = OpenLayers.Class({
+ name: "",
+ className: "",
+ featIds: null,
+ nFeatures: 0,
+
+ initialize: function(layerName, className)
+ {
+ this.name = layerName;
+ this.className = className;
+ this.nFeatures = 0;
+ this.featIds = [];
+ },
+
+ addFeature : function (featId)
+ {
+ this.featIds[this.nFeatures] = featId;
+ this.nFeatures++;
+ },
+
+ getName : function()
+ {
+ return this.name;
+ },
+
+ getClassName : function()
+ {
+ return this.className;
+ },
+
+ getNumFeatures : function()
+ {
+ return this.nFeatures;
+ },
+
+ removeFeatures : function (featureIndexes)
+ {
+ var numIndexes = featureIndexes.length;
+ for (var featIndex = 0; featIndex < numIndexes; featIndex++)
+ {
+ this.featIds.remove(featureIndexes[featIndex]);
+ this.nFeatures--;
+ }
+ }
+});
+
+Array.prototype.find = function(searchStr) {
+ var returnArray = null;
+ for (i=0; i<this.length; i++) {
+ if (typeof(searchStr) == 'function') {
+ if (searchStr.test(this[i])) {
+ if (!returnArray) { returnArray = [] }
+ returnArray.push(i);
+ }
+ } else {
+ if (this[i]===searchStr) {
+ if (!returnArray) { returnArray = [] }
+ returnArray.push(i);
+ }
+ }
+ }
+ return returnArray;
+};
+
+Array.prototype.remove = function(indexToRemove) {
+ this.splice(indexToRemove, 1);
+};
+
+
+
Added: trunk/layers/MapGuide/php/GetSelectionProperties.php
===================================================================
--- trunk/layers/MapGuide/php/GetSelectionProperties.php (rev 0)
+++ trunk/layers/MapGuide/php/GetSelectionProperties.php 2009-01-23 20:33:53 UTC (rev 1743)
@@ -0,0 +1,208 @@
+<?php
+/**
+ * SetSelection
+ *
+ * $Id: SetSelection.php 1664 2008-11-12 21:41:00Z 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.
+ */
+
+include('Common.php');
+include('../../../common/php/Utilities.php');
+include('Utilities.php');
+
+ $selText = "";
+ GetRequestParameters();
+
+ try
+ {
+ //load the map runtime state
+ //
+ $map = new MgMap();
+ $map->Open($resourceService, $mapName);
+ // Create the selection set
+ $selection = new MgSelection($map);
+ if($selText != "") {
+ $selection->FromXml($selText);
+ }
+
+ //now return a data struture which is the same as Query.php
+ $featureService = $siteConnection->CreateService(MgServiceType::FeatureService);
+
+ /* Get the map SRS - we use this to convert distances */
+ $srsFactory = new MgCoordinateSystemFactory();
+ //safely get an SRS ... (in Utilities)
+ $srsDefMap = GetMapSRS($map);
+ $srsMap = $srsFactory->Create($srsDefMap);
+
+ /*holds selection array*/
+ $properties = NULL;
+ $properties->layers = array();
+
+ //process
+ header('Content-type: text/x-json');
+ header('X-JSON: true');
+ $layers = $selection->GetLayers();
+ $nLayers = $layers->GetCount();
+ echo "/* nLayers:".$nLayers."*/";
+ for ($i=0; $i<$nLayers; $i++) {
+ $oLayer = $layers->GetItem($i);
+ $featureResId = new MgResourceIdentifier($oLayer->GetFeatureSourceId());
+ /* the class that is used for this layer will be used to select features */
+ $class = $oLayer->GetFeatureClassName();
+
+ /* select the features */
+ $queryOptions = new MgFeatureQueryOptions();
+
+ //TODO : seems that property mapping breaks the selection ????
+ //could it be that $selection->AddFeatures($layerObj, $featureReader, 0) is
+ //the one causing a problem when the properies are limited ?
+ $mappings = $_SESSION['property_mappings'][$oLayer->GetObjectId()];
+ if (0 && count($mappings) > 0) {
+ foreach($mappings as $name => $value) {
+ $queryOptions->AddFeatureProperty($name);
+ //echo "$name $value <br>\n";
+ }
+ $geomName = $oLayer->GetFeatureGeometryName();
+ $queryOptions->AddFeatureProperty($geomName);
+ }
+
+ $filter = $selection->GenerateFilter($oLayer, $class);
+ $queryOptions->SetFilter($filter);
+ $featureReader = $featureService->SelectFeatures($featureResId, $class, $queryOptions);
+ //$featureReader = $selection->GetSelectedFeatures($oLayer, $class, true );//this doesn't seem to work but would replace much of the above code
+
+ $layerName = $oLayer->GetName();
+ array_push($properties->layers, $layerName);
+
+ // TODO: Check if computed properties are needed?
+ $bComputedProperties = false;
+ $bNeedsTransform = false;
+ $srsLayer = NULL;
+ if ($bComputedProperties)
+ {
+ $spatialContext = $featureService->GetSpatialContexts($featureResId, true);
+ $srsLayerWkt = false;
+ if($spatialContext != null && $spatialContext->ReadNext() != null) {
+ $srsLayerWkt = $spatialContext->GetCoordinateSystemWkt();
+ /* skip this layer if the srs is empty */
+ }
+ if ($srsLayerWkt == null) {
+ $srsLayerWkt = $srsDefMap;
+ }
+ /* create a coordinate system from the layer's SRS wkt */
+ $srsLayer = $srsFactory->Create($srsLayerWkt);
+
+ // exclude layer if:
+ // the map is non-arbitrary and the layer is arbitrary or vice-versa
+ // or
+ // layer and map are both arbitrary but have different units
+ //
+ $bLayerSrsIsArbitrary = ($srsLayer->GetType() == MgCoordinateSystemType::Arbitrary);
+ $bMapSrsIsArbitrary = ($srsMap->GetType() == MgCoordinateSystemType::Arbitrary);
+ if (($bLayerSrsIsArbitrary != $bMapSrsIsArbitrary) ||
+ ($bLayerSrsIsArbitrary && ($srsLayer->GetUnits() != $srsMap->GetUnits()))) {
+ $bComputedProperties = false;
+ } else {
+ $srsTarget = null;
+ $srsXform = null;
+ $bNeedsTransform = ($srsLayer->GetUnitScale() != 1.0);
+ }
+ }
+
+ $properties = BuildSelectionArray($featureReader, $layerName, $properties,
+ $bComputedProperties,
+ $srsLayer, $bNeedsTransform, $oLayer);
+ $featureReader->Close();
+ }
+
+ $result = NULL;
+ $result->hasSelection = false;
+ if ($layers && $layers->GetCount() >= 0)
+ {
+ $result->hasSelection = true;
+ $oExtents = $selection->GetExtents($featureService);
+ if ($oExtents)
+ {
+ $oMin = $oExtents->GetLowerLeftCoordinate();
+ $oMax = $oExtents->GetUpperRightCoordinate();
+ $result->extents = NULL;
+ $result->extents->minx = $oMin->GetX();
+ $result->extents->miny = $oMin->GetY();
+ $result->extents->maxx = $oMax->GetX();
+ $result->extents->maxy = $oMax->GetY();
+
+ /*keep the full extents of the selection when saving the selection in the session*/
+ $properties->extents = NULL;
+ $properties->extents->minx = $oMin->GetX();
+ $properties->extents->miny = $oMin->GetY();
+ $properties->extents->maxx = $oMax->GetX();
+ $properties->extents->maxy = $oMax->GetY();
+ }
+ $result->layers = array();
+ for ($i=0; $i<$layers->GetCount(); $i++) {
+ $layer = $layers->GetItem($i);
+ $layerName = $layer->GetName();
+ array_push($result->layers, $layerName);
+ $layerClassName = $layer->GetFeatureClassName();
+ $result->$layerName->featureCount = $selection->GetSelectedFeaturesCount($layer, $layerClassName);
+ }
+
+ /*save selection in the session*/
+ $_SESSION['selection_array'] = $properties;
+ }
+ echo var2json($result);
+
+
+ } catch(MgException $e) {
+ echo "/* SetSelection Exception: " . $e->GetDetails()."*/";
+ }
+
+function GetParameters($params)
+{
+ global $selText;
+
+ $selText = UnescapeMagicQuotes($params['selection']);
+}
+
+
+function UnescapeMagicQuotes($str)
+{
+ if(ini_get("magic_quotes_sybase") == "1")
+ return str_replace("''", "'", $str);
+ else if(get_magic_quotes_gpc() == "1")
+ {
+ //Unescape double quotes
+ $str = str_replace('\\"', '"', $str);
+
+ //remove additional backslash
+ return str_replace("\\", "", $str);
+ }
+ return $str;
+}
+
+function GetRequestParameters()
+{
+ if($_SERVER['REQUEST_METHOD'] == "POST")
+ GetParameters($_POST);
+ else
+ GetParameters($_GET);
+}
+?>
Property changes on: trunk/layers/MapGuide/php/GetSelectionProperties.php
___________________________________________________________________
Name: svn:eol-style
+ native
Added: trunk/layers/MapGuide/php/SaveSelection.php
===================================================================
--- trunk/layers/MapGuide/php/SaveSelection.php (rev 0)
+++ trunk/layers/MapGuide/php/SaveSelection.php 2009-01-23 20:33:53 UTC (rev 1743)
@@ -0,0 +1,126 @@
+<?php
+/**
+ * SetSelection
+ *
+ * $Id: SetSelection.php 1664 2008-11-12 21:41:00Z 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.
+ */
+
+include('Common.php');
+include('../../../common/php/Utilities.php');
+include('Utilities.php');
+
+ $selText = "";
+ $getExtents = false;
+
+ GetRequestParameters();
+
+ try
+ {
+ //load the map runtime state
+ //
+ $map = new MgMap();
+ $map->Open($resourceService, $mapName);
+ // Create the selection set and save it
+ $selection = new MgSelection($map);
+ if($selText != "") {
+ $selection->FromXml($selText);
+ }
+ $selection->Save($resourceService, $mapName);
+
+ //now return a data struture which is the same as Query.php
+
+ //process
+ header('Content-type: text/x-json');
+ header('X-JSON: true');
+ $layers = $selection->GetLayers();
+
+ $result = NULL;
+ $result->hasSelection = false;
+ if ($layers && $layers->GetCount() >= 0)
+ {
+ $result->hasSelection = true;
+ $result->extents = NULL;
+ if($getExtents)
+ {
+ $featureService = $siteConnection->CreateService(MgServiceType::FeatureService);
+ $oExtents = $selection->GetExtents($featureService);
+ if ($oExtents)
+ {
+ $oMin = $oExtents->GetLowerLeftCoordinate();
+ $oMax = $oExtents->GetUpperRightCoordinate();
+ $result->extents->minx = $oMin->GetX();
+ $result->extents->miny = $oMin->GetY();
+ $result->extents->maxx = $oMax->GetX();
+ $result->extents->maxy = $oMax->GetY();
+ }
+ }
+ $result->layers = array();
+ for ($i=0; $i<$layers->GetCount(); $i++)
+ {
+ $layer = $layers->GetItem($i);
+ $layerName = $layer->GetName();
+ array_push($result->layers, $layerName);
+ $layerClassName = $layer->GetFeatureClassName();
+ $result->$layerName->featureCount = $selection->GetSelectedFeaturesCount($layer, $layerClassName);
+ }
+ }
+
+ echo var2json($result);
+
+
+ } catch(MgException $e) {
+ echo "/* SetSelection Exception: " . $e->GetDetails()."*/";
+ }
+
+function GetParameters($params)
+{
+ global $selText;
+ global $getExtents;
+
+ $selText = UnescapeMagicQuotes($params['selection']);
+ $getExtents = ($params['getextents'] == "true") ? true : false;
+}
+
+
+function UnescapeMagicQuotes($str)
+{
+ if(ini_get("magic_quotes_sybase") == "1")
+ return str_replace("''", "'", $str);
+ else if(get_magic_quotes_gpc() == "1")
+ {
+ //Unescape double quotes
+ $str = str_replace('\\"', '"', $str);
+
+ //remove additional backslash
+ return str_replace("\\", "", $str);
+ }
+ return $str;
+}
+
+function GetRequestParameters()
+{
+ if($_SERVER['REQUEST_METHOD'] == "POST")
+ GetParameters($_POST);
+ else
+ GetParameters($_GET);
+}
+?>
Property changes on: trunk/layers/MapGuide/php/SaveSelection.php
___________________________________________________________________
Name: svn:eol-style
+ native
Deleted: trunk/layers/MapGuide/php/SetSelection.php
===================================================================
--- trunk/layers/MapGuide/php/SetSelection.php 2009-01-22 21:01:39 UTC (rev 1742)
+++ trunk/layers/MapGuide/php/SetSelection.php 2009-01-23 20:33:53 UTC (rev 1743)
@@ -1,206 +0,0 @@
-<?php
-/**
- * SetSelection
- *
- * $Id$
- *
- * 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.
- */
-
-include('Common.php');
-include('../../../common/php/Utilities.php');
-include('Utilities.php');
-
- $selText = "";
- GetRequestParameters();
-
- try
- {
- //load the map runtime state
- //
- $map = new MgMap();
- $map->Open($resourceService, $mapName);
- // Create the selection set and save it
- $selection = new MgSelection($map);
- if($selText != "") {
- $selection->FromXml($selText);
- }
- $selection->Save($resourceService, $mapName);
-
- //now return a data struture which is the same as Query.php
- $featureService = $siteConnection->CreateService(MgServiceType::FeatureService);
-
- /* Get the map SRS - we use this to convert distances */
- $srsFactory = new MgCoordinateSystemFactory();
- //safely get an SRS ... (in Utilities)
- $srsDefMap = GetMapSRS($map);
- $srsMap = $srsFactory->Create($srsDefMap);
-
- /*holds selection array*/
- $properties = NULL;
- $properties->layers = array();
-
- //process
- header('Content-type: text/x-json');
- header('X-JSON: true');
- $layers = $selection->GetLayers();
- $nLayers = $layers->GetCount();
- echo "/* nLayers:".$nLayers."*/";
- for ($i=0; $i<$nLayers; $i++) {
- $oLayer = $layers->GetItem($i);
- $featureResId = new MgResourceIdentifier($oLayer->GetFeatureSourceId());
- /* the class that is used for this layer will be used to select features */
- $class = $oLayer->GetFeatureClassName();
-
- /* select the features */
- $queryOptions = new MgFeatureQueryOptions();
-
- //TODO : seems that property mapping breaks the selection ????
- //could it be that $selection->AddFeatures($layerObj, $featureReader, 0) is
- //the one causing a problem when the properies are limited ?
- $mappings = $_SESSION['property_mappings'][$oLayer->GetObjectId()];
- if (0 && count($mappings) > 0) {
- foreach($mappings as $name => $value) {
- $queryOptions->AddFeatureProperty($name);
- //echo "$name $value <br>\n";
- }
- $geomName = $oLayer->GetFeatureGeometryName();
- $queryOptions->AddFeatureProperty($geomName);
- }
-
- $filter = $selection->GenerateFilter($oLayer, $class);
- $queryOptions->SetFilter($filter);
- $featureReader = $featureService->SelectFeatures($featureResId, $class, $queryOptions);
- //$featureReader = $selection->GetSelectedFeatures($oLayer, $class, true );//this doesn't seem to work but would replace much of the above code
-
- $layerName = $oLayer->GetName();
- array_push($properties->layers, $layerName);
-
- $spatialContext = $featureService->GetSpatialContexts($featureResId, true);
- $srsLayerWkt = false;
- if($spatialContext != null && $spatialContext->ReadNext() != null) {
- $srsLayerWkt = $spatialContext->GetCoordinateSystemWkt();
- /* skip this layer if the srs is empty */
- }
- if ($srsLayerWkt == null) {
- $srsLayerWkt = $srsDefMap;
- }
- /* create a coordinate system from the layer's SRS wkt */
- $srsLayer = $srsFactory->Create($srsLayerWkt);
-
- // exclude layer if:
- // the map is non-arbitrary and the layer is arbitrary or vice-versa
- // or
- // layer and map are both arbitrary but have different units
- //
- $bLayerSrsIsArbitrary = ($srsLayer->GetType() == MgCoordinateSystemType::Arbitrary);
- $bMapSrsIsArbitrary = ($srsMap->GetType() == MgCoordinateSystemType::Arbitrary);
- $bComputedProperties = false;
- $bNeedsTransform = false;
- if (($bLayerSrsIsArbitrary != $bMapSrsIsArbitrary) ||
- ($bLayerSrsIsArbitrary && ($srsLayer->GetUnits() != $srsMap->GetUnits()))) {
- $bComputedProperties = false;
- } else {
- $srsTarget = null;
- $srsXform = null;
- $bNeedsTransform = ($srsLayer->GetUnitScale() != 1.0);
- }
-
- $properties = BuildSelectionArray($featureReader, $layerName, $properties,
- $bComputedProperties,
- $srsLayer, $bNeedsTransform, $oLayer);
- $featureReader->Close();
- }
-
- $result = NULL;
- $result->hasSelection = false;
- if ($layers && $layers->GetCount() >= 0)
- {
- $result->hasSelection = true;
- $oExtents = $selection->GetExtents($featureService);
- if ($oExtents)
- {
- $oMin = $oExtents->GetLowerLeftCoordinate();
- $oMax = $oExtents->GetUpperRightCoordinate();
- $result->extents = NULL;
- $result->extents->minx = $oMin->GetX();
- $result->extents->miny = $oMin->GetY();
- $result->extents->maxx = $oMax->GetX();
- $result->extents->maxy = $oMax->GetY();
-
- /*keep the full extents of the selection when saving the selection in the session*/
- $properties->extents = NULL;
- $properties->extents->minx = $oMin->GetX();
- $properties->extents->miny = $oMin->GetY();
- $properties->extents->maxx = $oMax->GetX();
- $properties->extents->maxy = $oMax->GetY();
- }
- $result->layers = array();
- for ($i=0; $i<$layers->GetCount(); $i++) {
- $layer = $layers->GetItem($i);
- $layerName = $layer->GetName();
- array_push($result->layers, $layerName);
- $layerClassName = $layer->GetFeatureClassName();
- $filter = $selection->GenerateFilter($layer, $layerClassName);
- $a = explode('OR', $filter);
- $result->$layerName->featureCount = count($a);
- }
-
- /*save selection in the session*/
- $_SESSION['selection_array'] = $properties;
- }
- echo var2json($result);
-
-
- } catch(MgException $e) {
- echo "/* SetSelection Exception: " . $e->GetDetails()."*/";
- }
-
-function GetParameters($params)
-{
- global $selText;
-
- $selText = UnescapeMagicQuotes($params['selection']);
-}
-
-
-function UnescapeMagicQuotes($str)
-{
- if(ini_get("magic_quotes_sybase") == "1")
- return str_replace("''", "'", $str);
- else if(get_magic_quotes_gpc() == "1")
- {
- //Unescape double quotes
- $str = str_replace('\\"', '"', $str);
-
- //remove additional backslash
- return str_replace("\\", "", $str);
- }
- return $str;
-}
-
-function GetRequestParameters()
-{
- if($_SERVER['REQUEST_METHOD'] == "POST")
- GetParameters($_POST);
- else
- GetParameters($_GET);
-}
-?>
More information about the fusion-commits
mailing list