[mapguide-users] Select features on map load

Paulo Veríssimo pauloverissimo at hotmail.com
Thu Jul 23 05:00:04 EDT 2009


Hi all,

Since I posted the first message about this subject I've been trying to
solve my problem and I already did it. I'll desbribe it shortly:

First, in the startup.php include the php code to receive the parameters by
url like layer and objectid:
$layer =  $_GET['layer'];
$objectid =  $_GET['objectid'];

Next, in this same file, in the javascript function OnMapInitialized(),
include the instruction to deal with the parameters and call a php to select
the features after the map is loaded (for now I am using the Task frame):
if("<?php echo $layer ?>" != "") //if parameters received
{  var timerselection;
    var watchselection = function()
    {  try
        {  var loaded = parent.ViewerFrame.mapFrame.GetScale();
            if(loaded != 0) //ok, map is ready!
            {  clearInterval(timerselection);
               
document.frames[1].frames[5].location.href="selectbyparameters.php?SESSION=<?
echo $sessionId ?>&MAPNAME=Map&layer=<?php echo $layer ?>&objectid=<?php
echo $objectid ?>";
            }
        }
        catch(e)
    {
  }				
};
timerselection = setInterval(watchselection, 4000);

Then, the file selectbyparameters.php can do the rest, that is to select the
features from the map because it is already loaded:
<?php
$layer =  $_GET['layer'];
$objectid =  $_GET['objectid'];
$sessionId = $_GET['SESSION'];
$mapName = $_GET['MAPNAME'];
$webconfigFilePath = "c:\\Program
Files\\Autodesk\\MapGuideEnterprise2010\\Server\\Bin\\serverconfig.ini";
MgInitializeWebTier ($webconfigFilePath);
$userInfo = new MgUserInformation($sessionId);
$siteConnection = new MgSiteConnection();
$siteConnection->Open($userInfo);
$map = new MgMap($siteConnection);
$map->Open($mapName);
$selection = new MgSelection($map);
$layer = $map->GetLayers()->GetItem($layerName);
//Turn on Layer and GroupLayer if they're off
$grouplayer = $layer->GetGroup();
$queryOptions = new MgFeatureQueryOptions();
if($layer->IsVisible() == false)
{  $layer->setVisible(true);
    $layer->ForceRefresh();
    $map->Save($resourceService);
}
if($grouplayer->IsVisible() == false)
{  $grouplayer->setVisible(true);
    $map->Save($resourceService);
}
$filter = "objectid = $objectid";
$queryOptions->SetFilter("$filter");
$featureReader = $layer->SelectFeatures($queryOptions);
$selection->AddFeatures($layer, $featureReader, 0);
$selectionXml = $selection->ToXml();
$featureReader->Close();
?>

And finally the javascript section in this same file:
<script language="javascript">
selectionXml = '<?php echo $selectionXml; ?>';
top.ViewerFrame.mapFrame.SetSelectionXML(selectionXml);
top.ViewerFrame.mapFrame.ZoomSelection(); //the same as:
parent.parent.mapFrame.ExecuteMapAction(10);
//if scale lower then 1:10.000, go to scale 1:20.000
var mapscale=top.ViewerFrame.mapFrame.GetScale();
if(mapscale<10000)
{	top.ViewerFrame.mapFrame.ZoomToScale(20000);
}
top.ViewerFrame.mapFrame.Refresh();
history.go(-1); //leave the task frame
</script>

I hope this can help. It is working in my intranet.

Thank you all for your help.

Paulo



Mauricio Villablanca wrote:
> 
> Check out the GetSelectionXML() function in the query.php file from the
> phpviewersample demo
> (http://download.osgeo.org/mapguide/releases/2.0.0/samples/phpviewersample.zip) 
> to see how it's done in PHP.
> 
> 
> 
> Paulo Veríssimo wrote:
>> 
>> Hi
>> 
>> Does anyone have done this operation?
>> I want to call the map page from another web application so I can see the
>> feature selected in that web application.
>> With this funcionality, I want to make a button in the web application
>> saying "see this feature on map page" that calls the map page and
>> highlighs and zooms the feature on map load.
>> I am using the ajax viewer and php.
>> The idea is to call the Mapguide URL invoking the layer name and the
>> objectid, something like this:
>> 'http://mapguideserver/mapguidesite/mapguideviewerpage.php?layername=layerX&objectdid=123'
>> Can this be done this way? Is there is a onLoad event? Where can I find
>> it? How do I pass the url parameters there?
>> 
>> Thank you
>> 
>> Paulo
>> _______________________________________________
>> mapguide-users mailing list
>> mapguide-users at lists.osgeo.org
>> http://lists.osgeo.org/mailman/listinfo/mapguide-users
>> 
>> 
> 
> 

-- 
View this message in context: http://n2.nabble.com/Select-features-on-map-load-tp3174763p3308335.html
Sent from the MapGuide Users mailing list archive at Nabble.com.


More information about the mapguide-users mailing list