[mapguide-users] Re: Search for a feature based on feature ID
GordonL
gordon.luckett at arrowgeomatics.com
Mon Sep 26 09:29:08 EDT 2011
Perhaps try to simplify. Your shape files use DBF as the attributes, you
could just launch a web page that seaches for the field you need.
http://www.yinfor.com/blog/archives/2008/01/php_connect_dbf_file.html
Then you can use a combination of the JavaScript API and Web API to zoom in.
For Basic Web Layout try
http://www.osgeo.org/files/mapguide/docs/viewerapi/viewerapi.html
Specifically SetSelectionXML(selectionXml) and ExecuteMapAction(10)
For Fusion Application Definitions try
www\fusion\layers\MapGuide\MapGuideViewerApi.js
function SetSelectionXML(selectionXml) {
var Fusion = window.top.myEmbeddedFrameNameWhateverItsCalled.Fusion;
var mapWidget = Fusion.getWidgetById(mgApiMapWidgetId);
if (mapWidget && mapWidget.isMapLoaded()) {
mapWidget.setSelection(selectionXml, true);
}
}
You can use this PHP if you invokeURL - it sends the MAPNAME and SESSION to
the page, you just need to pass the KEY (i.e. 234) the KEYNAME (i.e.
PARCEL_ID) and the LAYERNAME (i.e. PARCELS)
<?php
$configFilePath = "C:\Program Files\OSGeo\MapGuide\Web\www\webconfig.ini";
$session = urldecode(($_SERVER['REQUEST_METHOD'] == "POST")?
$_POST['SESSION']: $_GET['SESSION']);
$mapName = urldecode(($_SERVER['REQUEST_METHOD'] == "POST")?
$_POST['MAPNAME']: $_GET['MAPNAME']);
$key = urldecode(stripslashes($_REQUEST["KEY"]));
//SINGLE QUOTES AROUND STRINGS -COMMENT OUT THESE LINES IF THE FILTER IS NOT
A STRING
$key = $key . ",0";
$key = str_replace(",", "','", $key);
$key = "'" . $key . "'";
//END OF PUTTING SINGLE QUOTES AROUND THE LIST
$keyName = urldecode(stripslashes($_REQUEST["KEYNAME"]));
$layerName = urldecode(stripslashes($_REQUEST["LAYERNAME"]));
try
{
MgInitializeWebTier($configFilePath);
$userInfo = new MgUserInformation($session);
$siteConnection = new MgSiteConnection();
$siteConnection->Open($userInfo);
$featureService = $siteConnection->CreateService(2);
$resourceService = $siteConnection->CreateService(0);
$map = new MgMap($siteConnection);
$map->Open($mapName);
$queryOptions = new MgFeatureQueryOptions();
$queryOptions->SetFilter($keyName . " in (" . $key . ")");
$layer = $map->GetLayers()->GetItem($layerName);
$ResId = new MgResourceIdentifier($layer->GetFeatureSourceId());
$featureReader = $featureService->SelectFeatures($ResId, $layerName,
$queryOptions);
$selection = new MgSelection($map);
$selection->AddFeatures($layer, $featureReader, 0);
$selectionXml = $selection->ToXml();
$selection->Save($resourceService, $map->GetName());
//dump the XML out to a JAVASCRIPT variable
echo $selectionXml;
$featureReader->Close();
}
catch (MgException $e)
{
echo $e->GetMessage();
echo $e->GetDetails();
}
?>
regards
gordon
--
View this message in context: http://osgeo-org.1803224.n2.nabble.com/Search-for-a-feature-based-on-feature-ID-tp6829659p6831863.html
Sent from the MapGuide Users mailing list archive at Nabble.com.
More information about the mapguide-users
mailing list