[mapguide-users] Re: SetSelectionXML Problem (Selection and Zoom to selected Feature)

Nickthetemp nickthetemp at gmail.com
Fri Feb 19 14:18:16 EST 2010


Here is how I achieve  what you are trying to do in php.

Here is my javascript function:

function CellClicked(sel)
{
   
    parent.parent.mapFrame.SetSelectionXML(sel);  
    parent.parent.mapFrame.ExecuteMapAction(10);
  
}

This is my php stuff

Initialize Mapguide:

      MgInitializeWebTier ($webconfigFilePath);

      $userInfo = new MgUserInformation($sessionId);
      $siteConnection = new MgSiteConnection();
      $siteConnection->Open($userInfo);
      
      $resourceService =
$siteConnection->CreateService(MgServiceType::ResourceService);
      $featureSrvc =
$siteConnection->CreateService(MgServiceType::FeatureService);

      $map = new MgMap($siteConnection);
      $map->Open($resourceService, $mapName);


Then you have to set up your query in order to get the item you want to
select:
In this case I am querying a unique number. (number is a column in my
feature table that I am searching)

$queryOptions = new MgFeatureQueryOptions();
$queryOptions->SetFilter("number = $number "); <-----------enter your search
criteria here

I then get the layer I want to query and select the feature based on the
query set previous:

$layer = $map->GetLayers()->GetItem('Business'); <-------Enter you layer
name here
$featureReader = $layer->SelectFeatures($queryOptions);

I then set the selection and change it to a xml, and EscapeForHtml.

$selection = new MgSelection($map);
$selection->AddFeatures($layer, $featureReader, 1);
$selectionXml = $selection->ToXml();
$selectionXml = EscapeForHtml($selectionXml, true);

Then I send the selectionxml to my function. In order to do this I use a
little trick. Since I want my function to be called automatically when the
script runs I have a 1by1.gif image which is  located in the same place as
my script. I then echo the image and call my function in the image load:
Note: the image is just a blank 1 x 1 pixel image which is not visable.

echo " 1by1.gif ";  <--xxxxxx = onload - had to remove for fourm rules

In this Script I am calling it from the task page.
I have the user select a number from a dropdown list.
this number is then passes to my script as the query number.

Hope this gives you some help
-- 
View this message in context: http://n2.nabble.com/SetSelectionXML-Problem-Selection-and-Zoom-to-selected-Feature-tp4585892p4599603.html
Sent from the MapGuide Users mailing list archive at Nabble.com.


More information about the mapguide-users mailing list