缩放后查找原始(x,y)坐标

时间:2018-05-06 08:23:49

标签: java javafx

我使用以下代码进行缩放效果,此代码将应用于由地图图像组成的组,该图像允许用户点击城市以获取有关它的信息,但问题是当用户缩放时需要知道原始(x,y)坐标才能显示正确的信息。我怎么解决这个问题?我所尝试的是获得缩放比率,然后通过它获得多个(缩小)或分割(放大)新坐标。

 private Parent createZoomPane(final Group group) {
        final double SCALE_DELTA = 1.1;
        final StackPane zoomPane = new StackPane();

        zoomPane.getChildren().add(group);
        zoomPane.setOnScroll(new EventHandler<ScrollEvent>() {
          @Override public void handle(ScrollEvent event) {
            event.consume();

            if (event.getDeltaY() == 0) {
              return;
            }

            double scaleFactor =
              (event.getDeltaY() > 0)
                ? SCALE_DELTA
                : 1/SCALE_DELTA;

            group.setScaleX(group.getScaleX() * scaleFactor);
            group.setScaleY(group.getScaleY() * scaleFactor);
          }
        });

        return zoomPane;
      }




root.addEventFilter(MouseEvent.MOUSE_CLICKED, new EventHandler<MouseEvent>() {
        @Override
        // root is the map parent.
        public void handle(MouseEvent mouseEvent) {
            double x = mouseEvent.getX();
            double y = mouseEvent.getY();
            // Then I use x,y to find the city which the user wants, but when i apply zoom
            // effect the x,y changes fron the orignal values.

        }
    });

0 个答案:

没有答案