Shared Samples

Build, modify and run workflows on geospatial data using Spatial Modeler SDK. Build complex algorithms or run routine tasks, and build add-ons to ERDAS IMAGINE and GeoMedia.
Showing results for 
Search instead for 
Do you mean 

Map Interaction

by Technical Evangelist ‎09-30-2019 04:26 AM - edited ‎09-30-2019 06:40 AM (120 Views)

Abstract

The map interaction sample shows how you can interact with the map. The MapInteractionPlugin shows the WKT representation of a captured/selected geometry. The MouseClickPlugin implements a listener that listens on mouse clicks on the map and logs the coordinates of the clicked position.   

Bitbucket Link

https://bitbucket.org/HGDN/hgdn_mae/src/master/Desktop/MapInteraction/

Description

The Map Interaction sample contains two plugins:

  • MapInteractionPlugin
  • MouseClickPlugin

The MapInteractionPlugin  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):

 

@Action(actionLocation = ActionLocation.PluginTab.class, activeLayerRequired = true,
      minSelection = 1, maxSelection = 1)
  public void selectPrimitiveAndShowWKTDialog() {
    ...

    DefaultDialog wktViewerDialog = new WKTViewerDialog(geometry);
    wktViewerDialog.setVisible(true);
  }

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

 

The captureGeometryAndShowWKTDialog action starts a new GeometryCapture instance to capture a polygon. The WKT representation of the captured geometry is shown in a new dialog: 

@Action(actionLocation = ActionLocation.PluginTab.class)
  public void captureGeometryAndShowWKTDialog() {
    GeometryCaptureListener<Polygon> geometryCaptureListener =
        new GeometryCaptureListener<Polygon>() {

          ...

          @Override
          public void onGeometriesCaptured(GeometryCapture source, Stream<Polygon> geometries) {
            geometries.findFirst().ifPresent(g -> {
              DefaultDialog wktViewerDialog = new WKTViewerDialog(g);
              wktViewerDialog.setVisible(true);
            });
          }
        };

    ...
  }

 

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

public class MouseClickPlugin implements Plugin {
  
  @Override
  public void onMapReady() {
    ApplicationContext.getBrowser().getMap().onclick((e) -> {
      MapProducer mapProducer = ApplicationContext.getBrowser().getMap().getMapProducer();
      Coordinate coordinate = mapProducer.getTransformFunctions().world(Coordinate2d.of(e.getClientX(), e.getClientY()));
      Log.getLogger().log(Level.FINE, String.format("X: %s | Y: %s ", coordinate.getX(), coordinate.getY()));
    });
  }
}

 

Overview
Contributors