Highlighting selected features

5 messages Options
Embed this post
Permalink
Langen, Gido

Highlighting selected features

Reply Threaded More More options
Print post
Permalink
Some javascript/style in this post has been disabled (why?)
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
[hidden email]
http://lists.osgeo.org/mailman/listinfo/mapguide-users
Nichols, Mark A.

RE: Highlighting selected features

Reply Threaded More More options
Print post
Permalink

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: [hidden email] on behalf of Langen, Gido
Sent: Tue 10/27/2009 4:49 PM
To: [hidden email]
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
[hidden email]
http://lists.osgeo.org/mailman/listinfo/mapguide-users
Langen, Gido

RE: Highlighting selected features

Reply Threaded More More options
Print post
Permalink
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: [hidden email]
[mailto:[hidden email]] On Behalf Of Nichols,
Mark A.
Sent: October 27, 2009 19:55
To: MapGuide Users Mail List; [hidden email]
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: [hidden email] on behalf of Langen, Gido
Sent: Tue 10/27/2009 4:49 PM
To: [hidden email]
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
[hidden email]
http://lists.osgeo.org/mailman/listinfo/mapguide-users
_______________________________________________
mapguide-users mailing list
[hidden email]
http://lists.osgeo.org/mailman/listinfo/mapguide-users
Langen, Gido

RE: Highlighting selected features

Reply Threaded More More options
Print post
Permalink
In reply to this post by Nichols, Mark A.
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: [hidden email]
[mailto:[hidden email]] On Behalf Of Nichols,
Mark A.
Sent: October 27, 2009 19:55
To: MapGuide Users Mail List; [hidden email]
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: [hidden email] on behalf of Langen, Gido
Sent: Tue 10/27/2009 4:49 PM
To: [hidden email]
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
[hidden email]
http://lists.osgeo.org/mailman/listinfo/mapguide-users
_______________________________________________
mapguide-users mailing list
[hidden email]
http://lists.osgeo.org/mailman/listinfo/mapguide-users
sathishpsk9

RE: Highlighting selected features

Reply Threaded More More options
Print post
Permalink

Hi Gido

     Thanks for this. It helped me , but my map doest not have SRS . I do know how to add this ?


Thanks
Satish