Skip to content

Commit 943f006

Browse files
authored
Nearest Vertex / Convex Hull - normalise point for wrapping around date line (#519)
1 parent 5027338 commit 943f006

File tree

2 files changed

+23
-9
lines changed

2 files changed

+23
-9
lines changed

geometry/convex-hull/src/main/java/com/esri/samples/convex_hull/ConvexHullSample.java

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -133,12 +133,20 @@ public void start(Stage stage) {
133133
vBox.getStyleClass().add("panel-region");
134134
vBox.getChildren().addAll(convexHullButton, clearButton);
135135

136-
// add a point where the user clicks on the map
136+
// create a point from where the user clicked
137137
mapView.setOnMouseClicked(e -> {
138138
if (e.isStillSincePress() && e.getButton() == MouseButton.PRIMARY) {
139-
Point2D point2D = new Point2D(e.getX(), e.getY());
140-
Point point = mapView.screenToLocation(point2D);
141-
inputs.add(point);
139+
140+
Point2D point = new Point2D(e.getX(), e.getY());
141+
142+
// create a map point from a point
143+
Point mapPoint = mapView.screenToLocation(point);
144+
145+
// the map point should be normalized to the central meridian when wrapping around a map, so its value stays within the coordinate system of the map view
146+
Point normalizedMapPoint = (Point) GeometryEngine.normalizeCentralMeridian(mapPoint);
147+
148+
// add a point where the user clicks on the map
149+
inputs.add(normalizedMapPoint);
142150
// update the inputs graphic geometry
143151
Multipoint inputsGeometry = new Multipoint(new PointCollection(inputs));
144152
inputsGraphic.setGeometry(inputsGeometry);

geometry/nearest-vertex/src/main/java/com/esri/samples/nearest_vertex/NearestVertexSample.java

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -123,14 +123,20 @@ public void start(Stage stage) {
123123
// get the nearest vertex and coordinate where the user clicks
124124
mapView.setOnMouseClicked(e -> {
125125
if (e.isStillSincePress() && e.getButton() == MouseButton.PRIMARY) {
126+
// create a point from where the user clicked
127+
Point2D point = new Point2D(e.getX(), e.getY());
128+
129+
// create a map point from a point
130+
Point mapPoint = mapView.screenToLocation(point);
131+
132+
// the map point should be normalized to the central meridian when wrapping around a map, so its value stays within the coordinate system of the map view
133+
Point normalizedMapPoint = (Point) GeometryEngine.normalizeCentralMeridian(mapPoint);
126134
// show where the user clicked
127-
Point2D point2D = new Point2D(e.getX(), e.getY());
128-
Point point = mapView.screenToLocation(point2D);
129-
clickedLocationGraphic.setGeometry(point);
135+
clickedLocationGraphic.setGeometry(normalizedMapPoint);
130136

131137
// show the nearest coordinate and vertex
132-
ProximityResult nearestCoordinateResult = GeometryEngine.nearestCoordinate(polygon, point);
133-
ProximityResult nearestVertexResult = GeometryEngine.nearestVertex(polygon, point);
138+
ProximityResult nearestCoordinateResult = GeometryEngine.nearestCoordinate(polygon, normalizedMapPoint);
139+
ProximityResult nearestVertexResult = GeometryEngine.nearestVertex(polygon, normalizedMapPoint);
134140
nearestVertexGraphic.setGeometry(nearestVertexResult.getCoordinate());
135141
nearestCoordinateGraphic.setGeometry(nearestCoordinateResult.getCoordinate());
136142

0 commit comments

Comments
 (0)