[mapguide-users] Problems with xmlSelection

Mark Pendergraft markp at Meadgilman.com
Fri Jul 13 15:29:53 EDT 2007


And your sure something is selected?  How did you select the feature?

I can't imagine the php file isn't working.

 

So, what does your active selection yield after you retrieve it?

 

Meaning, after your page calls the function:

$mapSelection = rawurldecode(($_SERVER['REQUEST_METHOD'] == "POST")?
$_POST['SELECTION']: $_GET['SELECTION']);

 

What is the value of $mapSelection afterwards?

 

I had a problem passing XML to another page, because the server
recognized it as potentially harmful code...

I had to add the following  '  ValidateRequest="false"  ' to the page
directive at the top of the page... not sure how that works in PHP, but
if $mapSelection does not return a valid XML file after you retrieve
it... I'd imagine that it has something to do with the above.

 

From: mapguide-users-bounces at lists.osgeo.org
[mailto:mapguide-users-bounces at lists.osgeo.org] On Behalf Of Jorge Rubio
Sent: Friday, July 13, 2007 12:08 PM
To: MapGuide Users Mail List
Subject: Re: [mapguide-users] Problems with xmlSelection

 

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 <markp at meadgilman.com>: 

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: mapguide-users-bounces at lists.osgeo.org
[mailto:mapguide-users-bounces at lists.osgeo.org] 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 <scotth at mpower-tech.com>: 

The map needs to be saved and refreshed before a selection can show

 

From: mapguide-users-bounces at lists.osgeo.org
[mailto:mapguide-users-bounces at lists.osgeo.org] 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
mapguide-users at lists.osgeo.org
http://lists.osgeo.org/mailman/listinfo/mapguide-users 




-- 
Lic. Jorge Rubio 


_______________________________________________
mapguide-users mailing list
mapguide-users at lists.osgeo.org
http://lists.osgeo.org/mailman/listinfo/mapguide-users 




-- 
Lic. Jorge Rubio 

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.osgeo.org/pipermail/mapguide-users/attachments/20070713/b39d9868/attachment.html


More information about the mapguide-users mailing list