Hexagon Geospatial
MENU

Shared Samples

GeoMedia Smart Client Workflow Manager provides tools for building and delivering highly-constrained, map-based workflows for the office or the field.
Showing results for 
Search instead for 
Do you mean 

Map Interaction

by Community Manager ‎01-19-2016 02:35 AM - edited ‎01-19-2016 04:04 AM (768 Views)

Abstract

The map interaction samples quickly show how you can interact with the map. The MapInteractionPlugin uses a selected element in the map to display the WKT representation of the selected element. The MousClickPlugin implements a listener that listens on mouse clicks on the map and displays the WKT representation of the clicked position.   

Bitbucket Link

 https://bitbucket.org/HGDN/hgdn_gmsc/src/2eef0f0f7111d9de952d94e8f91052c2bc6946c7/Client/MapInteract...

Description

The Map Interaction sample contains two plugins:

  • MapInteractionPlugin
  • MouseClickPlugin

The MapInteractionPlugin  extends the AbstractPlugin and offers two actions:

  • selectPrimitiveAndShowWKTDialog
  • captureGeometryAndShowWKTDialog

The selectPrimitiveAndShowWKTDialog action is only active in case that one layer is active and exactly one element in the map is selected (see Action configuration):

 

@Plugin(alias = "MapInteraction", vendor = "Hexagon Geospatial")
public class MapInteractionPlugin extends AbstractPlugin 
{
	@Action(actionLocation = ActionLocation.PLUGINTAB, activeRequired = true, minimumSelection = 1, maximumSelection = 1)
	public void selectPrimitiveAndShowWKTDialog() 
        {
		MapSelectionCurator mapSelectionCurator = ApplicationContext.getBrowser().getMapSelectionCurator();
		GMap map = ApplicationContext.getBrowser().getMap();		
		Object[] selectedElementIds = mapSelectionCurator.getSelectedElements();
		GPrimitive[] selectedPrimitives = map.getElements(mapSelectionCurator.getActiveFeature().getUniqueId(), selectedElementIds);		
		DefaultDialog wktViewerDialog = new WKTViewerDialog(selectedPrimitives[0]);
		wktViewerDialog.setVisible(true);
	}	
}

Within the method, the selected primitive is used to show a new dialog containing the WKT representation of the selected primitive. 

 

The captureGeometryAndShowWKTDialog action starts a new GeometryCaptureInstance to capture a polygon and show the result of the captured primitive in a new dialog: 

@Action(actionLocation = ActionLocation.PLUGINTAB)
public void captureGeometryAndShowWKTDialog() 
{
	GeometryCaptureFactory.getCaptureInstance(GeometryCaptureType.Polygon, ApplicationContext.getBrowser().getMap(),
new IGeometryCaptureListener() { @Override public void captureFinished(GeometryCapture source) {}
@Override public void captureAborted(GeometryCapture source) {} @Override public void addCapturePrimitive(GeometryCapture source, GPrimitive... newPrimitives) { DefaultDialog wktViewerDialog = new WKTViewerDialog(newPrimitives[0]); wktViewerDialog.setVisible(true); } }).run(); }

 

The MouseClickPlugin adds a MouseListener to the map to log the point coordinates of the MouseEvent: 

@Plugin(alias="MouseClickPlugin", vendor="Hexagon Geospatial")
public class MouseClickPlugin extends AbstractPlugin
{
	@Override
	public void start() throws Exception 
	{
		ApplicationContext.getBrowser().getMap().addMouseListener(new MouseListener() {
			
			@Override
			public void mouseReleased(MouseEvent e) {}
			
			@Override
			public void mousePressed(MouseEvent e) {}
			
			@Override
			public void mouseExited(MouseEvent e) {}
			
			@Override
			public void mouseEntered(MouseEvent e) {}
			
			@Override
			public void mouseClicked(MouseEvent e) {
				DefaultMapProducer mapProducer =  ApplicationContext.getBrowser().getMap().getMapProducer();				
				Log.getLogger().log(Level.FINE, String.format("X: %s | Y: %s ", mapProducer.toWorldX(e.getX()), mapProducer.toWorldY(e.getY())));
			}
		});		
	}
}

 

Overview
Contributors