[mapguide-users] Highlighting selected features

Langen, Gido Gido.Langen at NRCan-RNCan.gc.ca
Wed Oct 28 14:35:14 EDT 2009


Mark - I looked some more at your code and I found the solution.  The
MgFeatureReader provides a forward-only iterator.  I had loop through
the record set to display the selected features in the task list frame
and then wanted to display the selected features in the map; I did not
realize that the ->ToXml() request requires the cursor position to be at
the beginning of the feature reader.  It makes sense once I knew since
the cursor is simply a pointer.  It seems that others had a similar
misunderstanding.

Thanks again,
Gido 


-----Original Message-----
From: mapguide-users-bounces at lists.osgeo.org
[mailto:mapguide-users-bounces at lists.osgeo.org] On Behalf Of Nichols,
Mark A.
Sent: October 27, 2009 19:55
To: MapGuide Users Mail List; mapguide-users at lists.osgeo.org
Subject: RE: [mapguide-users] Highlighting selected features


I had similar problems last week.  I've attached my source code below.
This source code runs within the task pane.

I had used ArcGIS to create a personal geodatabase with an x and a y
field.  So I can do all of my querying outside of MapGuide but within
the task pane.  However I still wanted to zoom to the feature in
MapGuide and select it.

Here's the code to do that....if you already have coordinates of the
feature.  That's probably the biggest difference in our code.  I have
all of my parcel centroids created outside of mapguide as well as the
parcel numbers to query on.  And those parcel centroids are only used to
zoom to that area, not for selecting the features.  I select by the
parcel number.

I did run into some problems to note:
- I had a hard time querying the parcel based on a string.  That's why
I'm querying on OBJECTID because its a number field.  I can't explain
this.
- In my MAP in MapGuide Maestro, be careful of the name on the layer
under the layer properties.  The name must match whats in your code.

Maybe my code will help you troubleshoot yours.  Maybe someone else has
a direct answer to your question.


*********** PAGE SOURCE CODE ************


<script language="javascript">

<?php

    include 'common.php';
    include 'constants.php';

    SetLocalizedFilesPath(GetLocalizationPath());
    GetRequestParameters();

        InitializeWebTier();
        $cred = new MgUserInformation($sessionId);

        //connect to the site and get a feature service and a resource
service instances
        $site = new MgSiteConnection();
        $site->Open($cred);
        $featureSrvc =
$site->CreateService(MgServiceType::FeatureService);
        $resourceSrvc =
$site->CreateService(MgServiceType::ResourceService);

		$map = new MgMap();
		$map->Open($resourceSrvc, "Default");

		$queryOptions = new MgFeatureQueryOptions();
		$queryOptions->SetFilter("OBJECTID = $QueryID");
		
		$countryDataResId = new
MgResourceIdentifier("Library://Site_Folder/Data and
Layers/parcel_hyperlinks.FeatureSource");
		
		$featureReader =
$featureSrvc->SelectFeatures($countryDataResId, "Hyperlinks_Parcels",
$queryOptions);
		$layer =
$map->GetLayers()->GetItem('parcel_hyperlinks');
		$selection = new MgSelection($map);
		$selection->AddFeatures($layer, $featureReader, 0);
		$selectionXml = $selection->ToXml();
		echo 'var theXML=\'' . $selectionXml . '\';';	

		?>
			
	
parent.parent.mapFrame.SetSelectionXML(theXML);
				parent.parent.mapFrame.ZoomToView(<?php
echo $gotoxy; ?>, 980, true)
				history.back()
			
			</script>
		
		<?php




function GetParameters($params)
{
    global $mapName, $sessionId;

    if(isset($params['LOCALE']))
        $locale = $params['LOCALE'];
    $mapName = $params['MAPNAME'];
    $sessionId = $params['SESSION'];
}

function GetRequestParameters()
{
    if($_SERVER['REQUEST_METHOD'] == "POST")
        GetParameters($_POST);
    else
        GetParameters($_GET);
}


?>

************** END PAGE ************




-----Original Message-----
From: mapguide-users-bounces at lists.osgeo.org on behalf of Langen, Gido
Sent: Tue 10/27/2009 4:49 PM
To: mapguide-users at lists.osgeo.org
Subject: [mapguide-users] Highlighting selected features
 
I want to highlight selected features.  I have pretty much copied the
code from the documentation.  But it doesn't work.  Below is the code.
Aside from not highlighting the selected feature, I do not understand
why the line    "<br>XML: <? echo $selectionXML; ?>"  in the code does
not print the XML block that I would expect.  At appears to me that the
"$selection->ToXML"   request doesn't create output.  

Can anybody help?
Gido




<?
include '../mapviewerphp/common.php';
include '../mapviewerphp/constants.php'; $configFilePath =
'../webconfig.ini';
 
MgInitializeWebTier($configFilePath);

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

$sessionId = $args['SESSION'];
$mapName = $args['MAPNAME'];

$userInfo = new MgUserInformation($sessionId); $siteConnection = new
MgSiteConnection(); $siteConnection->Open($userInfo); ?>

<html>
<head> <title> TEST </title> </head>

<body onLoad="OnPageLoad">

<?
$map = new MgMap($siteConnection);
$map->Open($mapName);
$layer = $map->GetLayers()->GetItem('peguis');
$layerName = $layer->GetName();
$parcelQuery = new MgFeatureQueryOptions(); $parcelQuery->SetFilter("PIN
= 1092213"); $featureReader = $layer->SelectFeatures($parcelQuery);
$featureReader->ReadNext();
$attVal = $featureReader->GetString("PARCELDESI");
$selection = new MgSelection($map);
$selection->AddFeatures($layer, $featureReader, 0); $selectionXML =
$selection->ToXml; ?>

<br>Test: <? echo $attVal; ?>
<br>XML: <? echo $selectionXML; ?>
</body>

<script language="javascript" type="text/javascript">
  function OnPageLoad() {
    selXML = '<? echo $selectionXML; ?>
    parent.parent.mapFrame.SetSelectionXML(selXML);
  }
</script>
</html>

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


More information about the mapguide-users mailing list