0

我目前正在开发一个利用 Javafx 和 ArcGIS esri 映射功能的应用程序。我遇到的问题是与地图上的图形符号进行交互后,无论是删除还是移动/拖动,应用程序的地图(MapView 场景视图)不再响应鼠标拖动(放大和缩小继续起作用)尽管所有功能起作用,例如删除和移动等。我几乎按照https://developers.arcgis.com/java/sample-code/update-graphics/的示例进行了操作,该示例也表现出相同的行为。关于处理鼠标功能有更好的方法吗?我当前的代码如下。任何建议表示赞赏。

@FXML
void selectSymbol(MouseEvent event) throws InterruptedException, ExecutionException {
    if (event.getButton() == MouseButton.PRIMARY && event.isStillSincePress() && event.getClickCount() == 2) {
        // set the cursor to default
        sceneView.setCursor(Cursor.DEFAULT);

        // clear any selected graphic
        graphicsOverlay.clearSelection();

        // create a point where the user clicked
        mapViewPoint = new Point2D(event.getX(), event.getY());

        // identify graphics on the graphics overlay
        identifyGraphics = sceneView.identifyGraphicsOverlayAsync(graphicsOverlay, mapViewPoint, 10, false);

        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);

                    sceneView.setOnMouseDragged(e -> {

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

                            // set the cursor to closed hand to indicate graphic dragging is active
                            sceneView.setCursor(Cursor.CLOSED_HAND);
                            // create a point from the dragged location
                            mapViewPoint = new Point2D(e.getX(), e.getY());
                            Point mapPoint = sceneView.screenToLocation(mapViewPoint);
                            identifiedGraphic.setGeometry(mapPoint);
                            String latLonDecimalDegrees = CoordinateFormatter.toLatitudeLongitude(mapPoint,
                                    CoordinateFormatter.LatitudeLongitudeFormat.DECIMAL_DEGREES, 4);
                            String coordinates = Tools.degreesToString(latLonDecimalDegrees);
                            // update the location of the graphic to the dragged location

                            updateonmap = mapPoint.toJson();
                            Map<String, Object> id1 = identifiedGraphic.getAttributes();
                            identifiedGraphicid = (String) id1.get("_id");
                            try {

                                moveSymbolTransmission(coordinates, updateonmap);
                                deleteRecord.UpdateSymbol(identifiedGraphicid.trim(), coordinates.trim());

                            } catch (Exception e1) {
                                // TODO Auto-generated catch block
                                e1.printStackTrace();
                            }
                        }
                    });

                }
            } catch (InterruptedException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            } catch (ExecutionException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }

        });
    } else if (event.getButton().equals(MouseButton.PRIMARY) && event.getClickCount() == 3) {
        Point2D point = new Point2D(event.getX(), event.getY());
        Point mapPoint = sceneView.screenToLocation(point);
        showCalloutWithLocationCoordinates(mapPoint);
    } else if (event.getButton().equals(MouseButton.MIDDLE)) {
        identifiedGraphic.setSelected(false);
        Map<String, Object> id = identifiedGraphic.getAttributes();
        identifiedGraphicid = (String) id.get("_id");

        try {
            networkMessages.sendGeoMessageDelete(null, identifiedGraphicid);
            deleteSymbol(identifiedGraphicid.trim());

        } catch (Exception e1) {
            // TODO Auto-generated catch block
            e1.printStackTrace();
        }

    } else if (event.getButton().equals(MouseButton.SECONDARY)) {
        Point2D point = new Point2D(event.getX(), event.getY());
        Point mapPoint = sceneView.screenToLocation(point);
        try {
            openSymbol(mapPoint, geoMessage, insertRecord);
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

    }

}

@FXML
void updateCoords(MouseEvent event) {
    Point2D point = new Point2D(event.getX(), event.getY());
    Point mapPoint = sceneView.screenToLocation(point);
    String latLonDecimalDegrees = CoordinateFormatter.toLatitudeLongitude(mapPoint,
            CoordinateFormatter.LatitudeLongitudeFormat.DECIMAL_DEGREES, 4);
    longpos.setText(latLonDecimalDegrees);

}
    
4

0 回答 0