From b1ffe7fe67fc117058241f1693f04ce7343e6e6a Mon Sep 17 00:00:00 2001 From: bruse Date: Tue, 16 Sep 2014 13:23:06 +0000 Subject: [PATCH] Question: How to obtain the coordinates from the map at the current mouse position? --- .../simstadt/regionchooser/RegionChooser.fxml | 2 +- .../RegionChooserController.java | 36 +++++++++++++++---- 2 files changed, 30 insertions(+), 8 deletions(-) diff --git a/src/eu/simstadt/regionchooser/RegionChooser.fxml b/src/eu/simstadt/regionchooser/RegionChooser.fxml index 2e4f3e6..086b4dd 100644 --- a/src/eu/simstadt/regionchooser/RegionChooser.fxml +++ b/src/eu/simstadt/regionchooser/RegionChooser.fxml @@ -11,7 +11,7 @@
- +
diff --git a/src/eu/simstadt/regionchooser/RegionChooserController.java b/src/eu/simstadt/regionchooser/RegionChooserController.java index 7b2b86a..e858e89 100644 --- a/src/eu/simstadt/regionchooser/RegionChooserController.java +++ b/src/eu/simstadt/regionchooser/RegionChooserController.java @@ -1,14 +1,18 @@ package eu.simstadt.regionchooser; +import java.util.ArrayList; import java.util.Arrays; import java.util.List; + import javafx.concurrent.Service; import javafx.concurrent.Task; import javafx.event.ActionEvent; import javafx.fxml.FXML; import javafx.scene.control.TextArea; + import com.lynden.gmapsfx.GoogleMapView; import com.lynden.gmapsfx.MapComponentInitializedListener; +import com.lynden.gmapsfx.javascript.JavascriptObject; import com.lynden.gmapsfx.javascript.object.GoogleMap; import com.lynden.gmapsfx.javascript.object.InfoWindow; import com.lynden.gmapsfx.javascript.object.InfoWindowOptions; @@ -17,13 +21,14 @@ import com.lynden.gmapsfx.javascript.object.MapTypeIdEnum; import com.lynden.gmapsfx.javascript.object.Marker; import com.lynden.gmapsfx.javascript.object.MarkerOptions; + import eu.simstadt.nf.Coord; import eu.simstadt.nf.NFJobBuilder; public class RegionChooserController implements MapComponentInitializedListener { - List regionPolygon; + ArrayList regionPolygon = new ArrayList<>(); @FXML private TextArea outputTA; @@ -89,12 +94,10 @@ public void mapInitialized() { InfoWindow bochumInfoWindow = new InfoWindow(infoWindowOptions); bochumInfoWindow.open(map, bochumMarker); - regionPolygon = Arrays.asList( - new Coord(bochumLoc.getLatitude(), bochumLoc.getLongitude()), - new Coord(hamburgLoc.getLatitude(), bochumLoc.getLongitude()), - new Coord(stuttgartLoc.getLatitude(), bochumLoc.getLongitude()), - new Coord(dresdenLoc.getLatitude(), bochumLoc.getLongitude()) - ); + regionPolygon.add(new Coord(bochumLoc.getLatitude(), bochumLoc.getLongitude())); + regionPolygon.add(new Coord(hamburgLoc.getLatitude(), bochumLoc.getLongitude())); + regionPolygon.add(new Coord(stuttgartLoc.getLatitude(), bochumLoc.getLongitude())); + regionPolygon.add(new Coord(dresdenLoc.getLatitude(), bochumLoc.getLongitude())); } // Build the nF export job description from a region polygon @@ -116,4 +119,23 @@ protected String call() throws Exception { }); exportRunner.start(); } + + @FXML + void clicked() { + // Test, if this LatLong will be returned by getCenter(). Seams to work. + System.out.println("Center: " + map.getCenter()); + + // Adding a fifth marker to the map seams to work without any problems. + LatLong loc = new LatLong(48.880003, 9.216849); + MarkerOptions markerOptions = new MarkerOptions(); + markerOptions.position(loc); + Marker marker = new Marker(markerOptions); + map.addMarker(marker); + + // Now I want to obtain the current coordinates from the map at the mouse position in order + // to instantiate and set a new marker. + // + // This statement fails. Why? + mapView.getMap().getLatLong(); + } } \ No newline at end of file -- GitLab