Select to view content in your preferred language

How to get Current X and Y on webmap on touch or clicklistener

320
2
Jump to solution
07-09-2024 10:43 PM
NancySuez
Emerging Contributor

I am trying to get current x and current y (lat/lng) on webmap ontouchlistener, As I have implemented webmap layer and trying to get click x and y but unable to get if anyone knows how to get please let me know

0 Kudos
1 Solution

Accepted Solutions
MarkBaird
Esri Regular Contributor

@NancySuez 

Assuming you are writing a desktop JavaFX application (not a JavaScript web app), take a look at this sample application which listens to a setOnMouseClicked event and converts the screen coordinates to a WGS84 (lat / long) point.  

Key steps are:

      // click event to display the callout
      mapView.setOnMouseClicked(e -> {

        // check that the primary mouse button was clicked and user is not panning
        if (e.getButton() == MouseButton.PRIMARY && e.isStillSincePress()) {

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

          // create a map point from a point
          Point mapPoint = mapView.screenToLocation(point);

          // project user-tapped map point location
          Point projectedPoint = (Point)GeometryEngine.project(mapPoint, SpatialReferences.getWgs84());

 

 Does this help?

View solution in original post

2 Replies
MarkBaird
Esri Regular Contributor

@NancySuez 

Assuming you are writing a desktop JavaFX application (not a JavaScript web app), take a look at this sample application which listens to a setOnMouseClicked event and converts the screen coordinates to a WGS84 (lat / long) point.  

Key steps are:

      // click event to display the callout
      mapView.setOnMouseClicked(e -> {

        // check that the primary mouse button was clicked and user is not panning
        if (e.getButton() == MouseButton.PRIMARY && e.isStillSincePress()) {

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

          // create a map point from a point
          Point mapPoint = mapView.screenToLocation(point);

          // project user-tapped map point location
          Point projectedPoint = (Point)GeometryEngine.project(mapPoint, SpatialReferences.getWgs84());

 

 Does this help?

NancySuez
Emerging Contributor

@MarkBaird Thankyou for sharing the solution....Its working

0 Kudos