Skip to content

Commit f91a1cd

Browse files
committed
Merge branch 'main' into v.next
2 parents 6ab6538 + 4cf3098 commit f91a1cd

File tree

1 file changed

+36
-12
lines changed

1 file changed

+36
-12
lines changed

search/find-place/src/main/java/com/esri/samples/find_place/FindPlaceController.java

Lines changed: 36 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,9 @@
2727
import javafx.geometry.Point2D;
2828
import javafx.scene.control.Button;
2929
import javafx.scene.control.ComboBox;
30+
import javafx.scene.control.skin.ComboBoxListViewSkin;
3031
import javafx.scene.image.Image;
32+
import javafx.scene.input.KeyCode;
3133
import javafx.scene.input.KeyEvent;
3234
import javafx.scene.input.MouseButton;
3335
import javafx.util.Duration;
@@ -72,6 +74,10 @@ public void initialize() {
7274
String yourAPIKey = System.getProperty("apiKey");
7375
ArcGISRuntimeEnvironment.setApiKey(yourAPIKey);
7476

77+
// handle JavaFX bug where entering a space between words in the combobox editor will reset the text there
78+
handleSpaceEntered(placeBox);
79+
handleSpaceEntered(locationBox);
80+
7581
// create a map with the streets basemap style
7682
ArcGISMap map = new ArcGISMap(BasemapStyle.ARCGIS_STREETS);
7783

@@ -139,7 +145,8 @@ public void initialize() {
139145
Point2D point = new Point2D(evt.getX(), evt.getY());
140146

141147
// get layers with elements near the clicked location
142-
ListenableFuture<IdentifyGraphicsOverlayResult> identifyResults = mapView.identifyGraphicsOverlayAsync(graphicsOverlay, point,
148+
ListenableFuture<IdentifyGraphicsOverlayResult> identifyResults =
149+
mapView.identifyGraphicsOverlayAsync(graphicsOverlay, point,
143150
10, false);
144151
identifyResults.addDoneListener(() -> {
145152
try {
@@ -161,6 +168,23 @@ public void initialize() {
161168
});
162169
}
163170

171+
/**
172+
* Handles a JavaFX bug (https://bugs.openjdk.org/browse/JDK-8087549) where when the user enters a space the combobox editor TextField is reset.
173+
*
174+
* @param comboBox the comboBox to apply the JavaFX bug work around to
175+
*/
176+
private void handleSpaceEntered(ComboBox<String> comboBox) {
177+
178+
var comboBoxListViewSkin = new ComboBoxListViewSkin<>(comboBox);
179+
comboBoxListViewSkin.getPopupContent().addEventFilter(KeyEvent.ANY, (event -> {
180+
if (event.getCode() == KeyCode.SPACE) {
181+
event.consume();
182+
}
183+
})
184+
);
185+
comboBox.setSkin(comboBoxListViewSkin);
186+
}
187+
164188
/**
165189
* Searches for places near the chosen location when the "search" button is clicked.
166190
*/
@@ -182,14 +206,14 @@ private void search() {
182206
// create a search area envelope around the location
183207
Point p = points.get(0).getDisplayLocation();
184208
Envelope preferredSearchArea = new Envelope(p.getX() - 10000, p.getY() - 10000, p.getX() + 10000, p.getY
185-
() + 10000, p.getSpatialReference());
209+
() + 10000, p.getSpatialReference());
186210
// set the geocode parameters search area to the envelope
187211
geocodeParameters.setSearchArea(preferredSearchArea);
188212
// zoom to the envelope
189213
mapView.setViewpointAsync(new Viewpoint(preferredSearchArea));
190214
// perform the geocode operation
191215
ListenableFuture<List<GeocodeResult>> geocodeTask = locatorTask.geocodeAsync(placeQuery,
192-
geocodeParameters);
216+
geocodeParameters);
193217

194218
// add a listener to display the results when loaded
195219
geocodeTask.addDoneListener(new ResultsLoadedListener(geocodeTask));
@@ -206,17 +230,17 @@ private void search() {
206230
*/
207231
@FXML
208232
private void searchByCurrentViewpoint() {
209-
String placeQuery = placeBox.getEditor().getText();
210-
GeocodeParameters geocodeParameters = new GeocodeParameters();
211-
geocodeParameters.getResultAttributeNames().add("*"); // return all attributes
212-
geocodeParameters.setOutputSpatialReference(mapView.getSpatialReference());
213-
geocodeParameters.setSearchArea(mapView.getCurrentViewpoint(Viewpoint.Type.BOUNDING_GEOMETRY).getTargetGeometry());
233+
String placeQuery = placeBox.getEditor().getText();
234+
GeocodeParameters geocodeParameters = new GeocodeParameters();
235+
geocodeParameters.getResultAttributeNames().add("*"); // return all attributes
236+
geocodeParameters.setOutputSpatialReference(mapView.getSpatialReference());
237+
geocodeParameters.setSearchArea(mapView.getCurrentViewpoint(Viewpoint.Type.BOUNDING_GEOMETRY).getTargetGeometry());
214238

215-
//perform the geocode operation
216-
ListenableFuture<List<GeocodeResult>> geocodeTask = locatorTask.geocodeAsync(placeQuery, geocodeParameters);
239+
//perform the geocode operation
240+
ListenableFuture<List<GeocodeResult>> geocodeTask = locatorTask.geocodeAsync(placeQuery, geocodeParameters);
217241

218-
// add a listener to display the results when loaded
219-
geocodeTask.addDoneListener(new ResultsLoadedListener(geocodeTask));
242+
// add a listener to display the results when loaded
243+
geocodeTask.addDoneListener(new ResultsLoadedListener(geocodeTask));
220244
}
221245

222246
/**

0 commit comments

Comments
 (0)