R

283
1
08-30-2019 02:13 PM
RickSanders1
New Contributor

Using the latest ArcGIS Runtime SDK for Java, I wanted to find a API call to calculate the number of pixels between 2 points on a map.

0 Kudos
1 Reply
MarkBaird
Esri Regular Contributor

It's just a case of converting your map coordinates to screen coordinates.

It is actually very common to convert from screen coordinates and move to map coordinates when you listen into click events.  I've shown this in the code below with an extra line of code to convert to back again:

mapView.setOnMouseClicked(e-> {
  // display the screen coordinate
  Point2D screenPoint = new Point2D(e.getX(), e.getY());
  System.out.println("screen " + screenPoint.getX() +"," + screenPoint.getY() );

  // convert the screen coordinate to map coordinate
  Point actualPoint = mapView.screenToLocation(screenPoint);
  System.out.println("actual point " + actualPoint.getX() +"," + actualPoint.getY());

  // convert the map coordinate back to the screen coordinate
  Point2D calcScreenPoint = mapView.locationToScreen(actualPoint);
  System.out.println("calc screen point " + calcScreenPoint.getX() + "," + calcScreenPoint.getY());
});

So if you have 2 map coordinates and convert these to screen coordinates it's just simple maths to work out the number of pixels between the 2 points.

Note the import statements so you get the types correct:

import com.esri.arcgisruntime.geometry.Point;
import javafx.geometry.Point2D;

Does this help?

0 Kudos