Developer Discussions

Discuss topics with other Hexagon Geospatial Power Portfolio developers and experts to get the most out of our products.
Showing results for 
Search instead for 
Do you mean 
Reply
Highlighted
New Contributor
Posts: 2
Registered: ‎05-22-2018

Get user selection for MapSelectionTools

Hi, 

 

I am doing a plugin and i would like to use the MapSelectionTools function.

 

I want to get the feature name of the user's selection contains in the list below.

 

mapSelectionTools.PNG

 

 

I did not found a listener for the MapSelectionTools. 

 

 

	private MapSelectionTools mapSelectionTools;
	
	public void GetUserSelection() {
		mapSelectionTools = new MapSelectionTools();
		mapSelectionTools.setQuickPickMode(true);
		mapSelectionTools.MAPSELECTPOINT(null);    	
  	}
	

 

How can I get the feature name selected by user ?

 

Thank you,

 

Romain

Highlighted
Technical Evangelist
Posts: 148
Registered: ‎10-20-2015

Re: Get user selection for MapSelectionTools

Hi Romain,

the selected layer will be the active layer if the spatial relate hit any geometries.

 

The MapSelection Tools uses the com.intergraph.web.extension.analyse.SpatialAnalysis. You can also execute this class by your own, if you want more control.

 

new SpatialAnalysis(yourSpatialAnalysisListener, SelectionMode.Point, null).selectWithShape();

The ISpatialAnalysisListener does the following. Every SpatialRelationResult is the result for one layer and the SpatialRelateFeatureSelection.showDialog(relationResults) call, shows the selection dialog.

 

@Override
public void selectionShapeCaptured(SpatialAnalysis spatialAnalysis, Shape capturedShape)
{
Feature activeFeature = ApplicationContext.getBrowser().getActiveFeature();
if(quickPickMode || spatialAnalysis.getSelectionMode() == SelectionMode.Geometry || activeFeature == null)
spatialAnalysis.relateWithFeatures(FeatureFilterFactory.filterFeatureList(ApplicationContext.getProject().getVisibleFeatures(), FeatureFilterFactory.getLocateableFilter()));
else if(activeFeature != null)
spatialAnalysis.relateWithFeatures(Utils.asModifyableList(ApplicationContext.getBrowser().getActiveFeature()));
}

@Override public void spatialAnalyseFinished(SpatialAnalysis spatialAnalysis, List<SpatialRelationResult> relationResults) { if (!Assertion.isValid(relationResults)) { if (Log.isInfoEnabled()) Log.getLogger().info("no elements selected!"); ApplicationContext.getBrowser().refreshView(); return; } SpatialRelationResult selectedResult = relationResults.get(0); if (relationResults.size() > 1) selectedResult = SpatialRelateFeatureSelection.showDialog(relationResults); if (selectedResult == null) return; showSelectionInMap(selectedResult); } private void showSelectionInMap(SpatialRelationResult relationResult) { List<Object> selection = relationResult.getSelection(); int resultcount = selection.size(); if (Log.isInfoEnabled()) Log.getLogger().info("count of found elements: " + resultcount); FeatureID activeFeature = ApplicationContext.getBrowser().getActiveFeatureID(); if (activeFeature == null || !activeFeature.equals(relationResult.getFeature().getID())) relationResult.getFeature().setActive(true); ApplicationContext.getBrowser().getMapSelectionCurator().select(selection.toArray(new Object[selection.size()])); }

I hope that helps you.

Best Regards,

Steve

Highlighted
Visitor
Posts: 1
Registered: ‎02-24-2020

Re: Get user selection for MapSelectionTools

Hi all, I have a similar problem to this.

 

private static final RPAction	action	= null;

@Action(icon = "selector-25.svg", actionLocation = ActionLocation.FAVORITES)
	public void SelectFeatureByPoint()
	{
		//abort everything first then only start
			GMap map = context.getMap();
			
			map.getMeasurementController().abortAll();
			if (map.getState() != MapState.IDLE)
				map.setState(MapState.IDLE);
			 ApplicationContext.getBrowser().clearMapSelection();
			 
			// MapSelectionTools myTools = new MapSelectionTools();
			 //myTools.setQuickPickMode(true);
			 //myTools.MAPSELECTPOINT(action);

			QuickPickPlugin myQuickPick =  (QuickPickPlugin) ApplicationContext.getPluginCurator().getByName("QuickPickPlugin");
			myQuickPick.quickPickWithPoint(action);
			
	}

this code was working in GMSC 2016.

I try to migrate the same code to GMSC 2020, but it does not work.

 

the error i keep getting is:

 

22 May 2020 9:27:52 am SEVERE:	Error during spatial relation with feature '[333] MV Cable Joint (Site)'!				--> [pool-2-thread-23] com.intergraph.web.extension.analyse.SpatialAnalysis.relateWithFeatures
java.lang.NullPointerException
	at java.base/java.util.Objects.requireNonNull(Unknown Source)
	at java.base/java.util.Arrays$ArrayList.<init>(Unknown Source)
	at java.base/java.util.Arrays.asList(Unknown Source)
	at com.intergraph.web.extension.analyse.SpatialAnalysis.spatialRelateWithFeature(SpatialAnalysis.java:249)
	at com.intergraph.web.extension.analyse.SpatialAnalysis.relateWithFeatures(SpatialAnalysis.java:205)
	at com.intergraph.web.plugin.quickpick.QuickPickPlugin.selectionShapeCaptured(QuickPickPlugin.java:105)
	at com.intergraph.web.extension.analyse.SpatialAnalysis.selectionShapeCaptured(SpatialAnalysis.java:167)
	at com.intergraph.web.extension.analyse.SelectWithShapeTask.run(SelectWithShapeTask.java:29)
	at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
	at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
	at java.base/java.lang.Thread.run(Unknown Source)
22 May 2020 9:27:52 am SEVERE:	error during selection: 				--> [pool-2-thread-23] com.intergraph.web.extension.analyse.SpatialAnalysis.showMapSelectError
java.lang.NullPointerException
	at java.base/java.util.Objects.requireNonNull(Unknown Source)
	at java.base/java.util.Arrays$ArrayList.<init>(Unknown Source)
	at java.base/java.util.Arrays.asList(Unknown Source)
	at com.intergraph.web.extension.analyse.SpatialAnalysis.spatialRelateWithFeature(SpatialAnalysis.java:249)
	at com.intergraph.web.extension.analyse.SpatialAnalysis.relateWithFeatures(SpatialAnalysis.java:205)
	at com.intergraph.web.plugin.quickpick.QuickPickPlugin.selectionShapeCaptured(QuickPickPlugin.java:105)
	at com.intergraph.web.extension.analyse.SpatialAnalysis.selectionShapeCaptured(SpatialAnalysis.java:167)
	at com.intergraph.web.extension.analyse.SelectWithShapeTask.run(SelectWithShapeTask.java:29)
	at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
	at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
	at java.base/java.lang.Thread.run(Unknown Source)

what am i doing wrong?