How to move multiple coordinate MIL-STD252D symbols via mouse drag

277
1
04-07-2022 07:29 PM
rod182211
New Contributor II

Hi All, I am seeking advice on an approach to enable moving multiple coordinate symbols such as the arrow line below via the mouse. I have no issues moving single coordinate symbols. My current code for a single coordinate is below.   Has someone developed or could share a method they have developed?

 

rod182211_0-1649384669615.png

identifyGraphics.addDoneListener(() -> {

try {
if (!identifyGraphics.get().getGraphics().isEmpty()) {
// get the first identified graphic
identifiedGraphic = identifyGraphics.get().getGraphics().get(0);
// select the identified graphic
identifiedGraphic.setSelected(true);
eventHandlersymbolfirstmove = new EventHandler<javafx.scene.input.MouseEvent>() {
@Override
public void handle(javafx.scene.input.MouseEvent event) {

if (identifiedGraphic.isSelected() && identifiedGraphic != null) {

// set the cursor to closed hand to indicate graphic dragging is active
sceneView.setCursor(Cursor.CLOSED_HAND);
//Get the selected graphic attributes and reference the current graphic ID
Map<String, Object> identified = identifiedGraphic.getAttributes();
identifiedGraphicid = (String) identified.get("_id");
//Get the current array of coordiates
// String identifiedGraphiccoordinates = (String) identified.get("_control_points");

// System.out.println(identifiedGraphiccoordinates);
// create a point from the dragged location
mapViewPoint = new Point2D(event.getX(), event.getY());
Point mapPoint = sceneView.screenToLocation(mapViewPoint);
// update the location of the graphic to the dragged location
identifiedGraphic.setGeometry(mapPoint);
//Convert to lat long decimal
String latLonDecimalDegrees = CoordinateFormatter.toLatitudeLongitude(mapPoint,
CoordinateFormatter.LatitudeLongitudeFormat.DECIMAL_DEGREES, 4);
//Convert for my symbol attribute method
String coordinates = Tools.degreesToString(latLonDecimalDegrees);
// Concert to JSON for transmission across the network
updateonmap = mapPoint.toJson();
eventHandlersymbolmove = (javafx.scene.input.MouseEvent e1) -> {
identifiedGraphic.setSelected(false);
sceneView.setCursor(Cursor.DEFAULT);
// clear any selected graphic
graphicsOverlay.clearSelection();
sceneView.removeEventFilter(javafx.scene.input.MouseEvent.MOUSE_DRAGGED,
eventHandlersymbolfirstmove);
event.consume();
};

sceneView.addEventFilter(javafx.scene.input.MouseEvent.MOUSE_RELEASED,
eventHandlersymbolmove);

try {
/* send the move information over the network and updates the database with
the new information for the coordinates */
moveSymbolTransmission(coordinates, updateonmap);
/* update the database with the changes */
updateRecord.UpdateSymbol(identifiedGraphicid.trim(), coordinates.trim());

} catch (Exception e11) {
LOG.severe(e11, "Failed to move symbol and update database: %s",
e11.getMessage());
}

}

event.consume();

};

};
sceneView.addEventFilter(javafx.scene.input.MouseEvent.MOUSE_DRAGGED,
eventHandlersymbolfirstmove);
}
} catch (InterruptedException e1) {
LOG.severe(e1, "Error graphic: %s", e1.getMessage());
e1.printStackTrace();
} catch (ExecutionException e1) {
new Alert(Alert.AlertType.ERROR, "Error identifying clicked graphic").show();
LOG.severe(e1, "Error identifying clicked graphic: %s", e1.getMessage());
}

});

0 Kudos
1 Reply
MarkBaird
Esri Regular Contributor

I don't have any specific code to do what you are looking for, but I'd approach it something like this:

  • When you identify or get the geometry of say an arrow you you'll get back a MultiPoint which will contain the control points for your arrow.
  • You should be able to work out a delta x and y from your dragging operation.
  • You can create a new MultiPoint by looping through the points in the old geometry, apply the delta to each point and then set the new geometry to your graphic.

Does this help?

 

0 Kudos