[mapguide-users] Highlighting selected features

Langen, Gido Gido.Langen at NRCan-RNCan.gc.ca
Wed Oct 28 10:53:03 EDT 2009


Mark - Thanks for your sample code.  Unfortunately, the core problem did
persists: The ToXml() request is producing an empty XML selection
Feature Set:

<?xml version="1.0' encoding="UTF-8"?><FeatureSet
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="FeatureSet-1.0.0.xsd"></FeatureSet>

However, I think I have a solution to one of your other issues - the
coordinates: I inserted some sample code that permits you to extract X/Y
coordinates from features and in addition re-projects them.

May-be you can bebefit from it,
Gido 

P.S.: MapGuide also has a centroid function.

=== setting up the transformation (re-projection) ===
$featureService =
$siteConnection->CreateService(MgServiceType::FeatureService);
$featureSource = new MgResourceIdentifier($layer->GetFeatureSourceId());
$featureSC = $featureService->GetSpatialContexts($featureSource, true);
$featureSC->ReadNext();
$featureSRS = $featureSC->GetCoordinateSystemWkt();
$coordSysFactory = new MgCoordinateSystemFactory();
$sourceSRS = $coordSysFactory->Create($featureSRS);
$targetSRS = $coordSysFactory->Create($mapSRS);
$LL2LamCC = $coordSysFactory->GetTransform($sourceSRS, $targetSRS);
=== reading the coordinates from the feature ===
$agfObj = $featureReader->GetGeometry("Geometry");
$agfRW  = new MgAgfReaderWriter();
$geoObj = $agfRW->Read($agfObj);
$wktRW  = new MgWktReaderWriter();
$wktObj = $wktRW->Write($geoObj);
==============================================================




-----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