[mapguide-users] Highlight selections problem

Jo Cook j.cook at oxfordarch.co.uk
Fri Aug 7 10:59:36 EDT 2009


Hi,

I've taken this a little further. Firebug gives me the following error:

Error: There must be exactly one feature in the set.

This comes from setselection.php, and in particular the lines 

if($queryInfo) {
            //Query feature info for the feature in the selection set. This
will return the current set
            //along with property info
            //There must be only one feature in the feature set
            $layers = $sel->GetLayers();
            if($layers == null || $layers->GetCount() != 1) {
                echo "Error: There must be exactly one feature in the set.";
///NOXLATE dbg report only
                return;
            }

(rather than the other instance of this error in that file). I know that the
test polygon I am trying to select comprises one feature, and that I am
using a unique id so I can't see how there can be more than one feature
selected...

Thanks

Jo

Jo Cook wrote:
> 
> Hi Rodolfo,
> 
> I'm actually using a shapefile for my test implementation (as my
> postgresql/postgis setup is version 8.4/1.4 which the fdo provider doesn't
> like). The field I am using to make the selection is a unique integer-
> should that be enough? 
> Thanks
> 
> Jo
> 
> Rodolfo Moreno wrote:
>> 
>> 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
>>> 
>>> 
>> 
>> 
> 
> 

-- 
View this message in context: http://n2.nabble.com/Highlight-selections-problem-tp3398199p3404846.html
Sent from the MapGuide Users mailing list archive at Nabble.com.


More information about the mapguide-users mailing list