Hi Mark, the problems is here
ActiveSelection.GetLayers
returns nothing. That means ActiveSelection wasn't initialized?
Could be the class php file doesn't process properly the posted
xmlSelection....
I really don't understand what is wrong...
2007/7/13, Mark Pendergraft <[EMAIL PROTECTED]>:
Well first off, I would open the Map with the siteconnection.
After you create the new selection object with the XML selection like so:
Dim Selection as New MgSelection(Map, mapSelection)
You then need to find out what layers are selected, then generate a filter
for each layer.
Then you can use a featureReader to read the selected objects, and then
your code can perform functions based off of the selection.
Here is an example function in VB (sorry, but I have to translate your
guy's php all the time, so I don't feel that bad)
''''''''''''''''''''''''''' Begin Code
'''''''''''''''''''''''''''''''''''''''''''
Function MakePolygonFromSelection(ByVal featureService As
MgFeatureService, ByVal Map As MgMap, ByVal JobNo As String, ByVal XmlSel As
String) As MgPropertyCollection
' Open the map with the XML selection that was passed through javascript
Dim ActiveSelection As New MgSelection(Map, XmlSel)
' Get the layers in the activeselection as a
mgreadonlylayercollection
Dim Layers As MgReadOnlyLayerCollection =
ActiveSelection.GetLayers
' I only want to use the selection if one object was selected…. If you
wanted multiple objects, you would loop through the layers
' to find out which layers are selected.. then you could generate an array
of strings containing the selections generated filter (like below)
If Not Layers.GetCount = 1 Then
ErrorMessage = "More than one object was selected"
Return Nothing
Exit Function
End If
' Now get the layer from the selection
Dim Layer As MgLayer = Map.GetLayers.GetItem(Layers.Item(0).Name)
' Generate the selection filter for the layer, which you
will use to get the selected objects on that layer
Dim selectionFilter As String = ActiveSelection.GenerateFilter(Layer,
Layer.FeatureClassName)
' create a new mgFeatureQueryOptions and set the filter to
the selection filter obtained from the active selection set
Dim queryOptions As New MgFeatureQueryOptions
queryOptions.SetFilter(selectionFilter)
' now create the feature reader, and set it to obtain the objects from the
active selection (using the layer, and the query options created using the
generatefilter command
Dim fr As MgFeatureReader = featureService.SelectFeatures(New
MgResourceIdentifier(Layer.GetFeatureSourceId), Layer.GetFeatureClassName,
queryOptions)
' read the first feature
fr.ReadNext()
'the rest of this code transfers the geometry from the
selected feature to another feature source..
' this is where you would insert your code to act upon the
map features that were selected.
Dim Geom As MgByteReader = fr.GetGeometry(
Layer.GetFeatureGeometryName)
Dim geometryProperty As New MgGeometryProperty("Geometry", Geom)
Dim JobNoProperty As New MgStringProperty("JobNo", JobNo)
Dim propertyCollection As New MgPropertyCollection
propertyCollection.Add(geometryProperty)
propertyCollection.Add(JobNoProperty)
fr.Close()
fr.Dispose()
' this is the end of the function… you will also want to
save your map back to the user session should you update anything on it.
Return propertyCollection
End Function
''''''''''''''''''''''''''' End Code
'''''''''''''''''''''''''''''''''''''''''''
Well, I hope that clears things up a bit.
-Mark Pendergraft
*From:* [EMAIL PROTECTED] [mailto:
[EMAIL PROTECTED] *On Behalf Of *Jorge Rubio
*Sent:* Friday, July 13, 2007 10:41 AM
*To:* MapGuide Users Mail List
*Subject:* Re: [mapguide-users] Problems with xmlSelection
My problems begin before to show selection. $mgSelection is not
initialized!
2007/7/13, Scott Hameister <[EMAIL PROTECTED]>:
The map needs to be saved and refreshed before a selection can show
*From:* [EMAIL PROTECTED] [mailto:
[EMAIL PROTECTED] *On Behalf Of *Jorge Rubio
*Sent:* Friday, July 13, 2007 9:35 AM
*To:* MapGuide Users Mail List
*Subject:* [mapguide-users] Problems with xmlSelection
Hi list
I need to pass an xmlSlection to a php class in order to be used by a
member function
Using javascript I get xmlSelection
var xmlSel = parent.parent.mapFrame.GetSelectionXML();
I post the selection like this
someParams + "&SELECTION=" + encodeURIComponent(xmlSel);
I get the params at php class file like this
$mgSessionId = ($_SERVER['REQUEST_METHOD'] == "POST")? $_POST['SESSION']:
$_GET['SESSION'];
$mapName = ($_SERVER['REQUEST_METHOD'] == "POST")? $_POST['MAPNAME']:
$_GET['MAPNAME'];
$mapSelection = rawurldecode(($_SERVER['REQUEST_METHOD'] == "POST")?
$_POST['SELECTION']: $_GET['SELECTION']);
so $mapSelection is an XML string.
Then, I need to get that selection
$featureService =
$this->site->CreateService(MgServiceType::FeatureService);
$resourceService =
$this->site->CreateService(MgServiceType::ResourceService);
$map = new MgMap();
$map->Open($resourceService, $mapName);
$mgSelection = new MgSelection($map,$mapSelection);
None selection is created!!
What I'm doing wrong?
Thanks in advance.
--
Lic. Jorge Rubio
_______________________________________________
mapguide-users mailing list
[email protected]
http://lists.osgeo.org/mailman/listinfo/mapguide-users
--
Lic. Jorge Rubio
_______________________________________________
mapguide-users mailing list
[email protected]
http://lists.osgeo.org/mailman/listinfo/mapguide-users
--
Lic. Jorge Rubio
_______________________________________________
mapguide-users mailing list
[email protected]
http://lists.osgeo.org/mailman/listinfo/mapguide-users