[mapguide-users] Highlight selections problem
Rodolfo Moreno
rodolfoamoreno at gmail.com
Thu Aug 6 11:36:00 EDT 2009
Hi Jo,
I thinks that your problem is with your database. does your table containing
the geometries have primary key and spatial indexs?
regards,
Jo Cook wrote:
>
> Dear All,
>
> I have the fairly common problem of wanting to pick a feature from a
> database and have the map automatically zoom to the correct location and
> highlight the feature. I am doing this in php and javascript (MGOS 2.1
> with bundled apache configuration), following some extremely helpful code
> snippets I found in the forum. Thanks!
>
> I have now got stuck at the point where a lot of other people seem to get
> stuck, namely that the map zooms to the correct location and shows in the
> status bar that one feature is selected, but the feature doesn't show up
> as highlighted. I understand, from trawling the forum, that I need to save
> and refresh in order to highlight the feature.
>
> The only problem is that I have tried many combinations of map save and
> selection save, and have looked in the api documentation, and tried
> figuring out where in my code it needs to go, and nothing seems to work,
> and now I'm horribly confused as to which of these I am supposed to be
> using. Am I saving a selection, or saving a map?
>
> This is the relevant section of php:
>
> $resourceSrvc =
> $siteConn->CreateService(MgServiceType::ResourceService);
> $map = new MgMap();
> $resId = new
> MgResourceIdentifier("Library://maps/map1.MapDefinition");
> $mapName = $resId->GetName();
> $map->Create($resourceSrvc, $resId, $mapName);
>
>
> $layers = $map->GetLayers();
> $selLayer = $layers->GetItem($SMAlayer);
> $featureResourceId = new
> MgResourceIdentifier($selLayer->GetFeatureSourceId());
> $featureClassName = $selLayer->GetFeatureClassName();
>
>
> $filter = "site_code = '$SMAlocation'";
>
> $queryOptions = new MgFeatureQueryOptions();
> $queryOptions->SetFilter($filter);
>
> $featureSrvc =
> $siteConn->CreateService(MgServiceType::FeatureService);
> $featureReader = $featureSrvc->SelectFeatures($featureResourceId,
> $featureClassName, $queryOptions);
>
> $selection = new MgSelection($map);
> $selection->AddFeatures($selLayer, $featureReader, 1);
> $selectionXml = $selection->ToXml();
> $selection->Save($resourceSrvc, $mapName);
>
> Then this is the javascript
>
> <SCRIPT LANGUAGE="JavaScript">
>
> var initTimer;
>
> function InitDocument()
> {
> //wait for map to be fully initialized
> //then call the initial function
> initTimer = setInterval(DelayedInit, 200);
>
> }
>
> function DelayedInit() {
> try {
> if(parent.ViewerFrame.mapFrame.mapInit) {
> clearInterval(initTimer);
> parent.ViewerFrame.mapFrame.ZoomToView(<?php echo $centerX; ?>,
> <?php echo $centerY; ?>, 2000, true);
> var selectionXml = '<?php echo $selectionXml; ?>';
> parent.ViewerFrame.mapFrame.SetSelectionXML(selectionXml);
> parent.ViewerFrame.mapFrame.ExecuteMapAction(1);
> parent.ViewerFrame.mapFrame.Refresh();
>
> }
> }
> catch(e) {}
> }
>
> </SCRIPT>
>
> </HEAD>
>
> <BODY onLoad="InitDocument()">
>
>
> </BODY>
> </HTML>
>
>
> This doesn't work, but doesn't seem to throw up any errors. Any help would
> be very much appreciated! To reiterate, I have searched the documentation
> and forums, but remain confused...
>
> Thanks
>
> Jo
> --
> -----------------------------------------------------
> Joanne Cook
> Senior IT Support and Development
> Oxford Archaeology (North)
> 01524 880212
> http://thehumanjourney.net
>
>
> ------
> Files attached to this email may be in ISO 26300 format (OASIS Open
> Document Format). If you have difficulty opening them, please visit
> http://iso26300.info for more information.
>
> _______________________________________________
> mapguide-users mailing list
> mapguide-users at lists.osgeo.org
> http://lists.osgeo.org/mailman/listinfo/mapguide-users
>
>
-----
Rodolfo Moreno
CivilEng
--
View this message in context: http://n2.nabble.com/Highlight-selections-problem-tp3398199p3398989.html
Sent from the MapGuide Users mailing list archive at Nabble.com.
More information about the mapguide-users
mailing list