Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
Eric Duminil
RegionChooser
Commits
b1ffe7fe
Commit
b1ffe7fe
authored
Sep 16, 2014
by
bruse
Browse files
Question: How to obtain the coordinates from the map at the current mouse position?
parent
359e7d6d
Changes
2
Hide whitespace changes
Inline
Side-by-side
src/eu/simstadt/regionchooser/RegionChooser.fxml
View file @
b1ffe7fe
...
...
@@ -11,7 +11,7 @@
<BorderPane
fx:controller=
"eu.simstadt.regionchooser.RegionChooserController"
maxHeight=
"-Infinity"
maxWidth=
"-Infinity"
minHeight=
"-Infinity"
minWidth=
"-Infinity"
prefHeight=
"400.0"
prefWidth=
"600.0"
xmlns=
"http://javafx.com/javafx/8"
xmlns:fx=
"http://javafx.com/fxml/1"
>
<center>
<GoogleMapView
fx:id=
"mapView"
prefHeight=
"750.0"
prefWidth=
"750.0"
AnchorPane.bottomAnchor=
"0.0"
AnchorPane.leftAnchor=
"0.0"
AnchorPane.rightAnchor=
"0.0"
AnchorPane.topAnchor=
"0.0"
/>
<GoogleMapView
onMouseClicked=
"#clicked"
fx:id=
"mapView"
prefHeight=
"750.0"
prefWidth=
"750.0"
AnchorPane.bottomAnchor=
"0.0"
AnchorPane.leftAnchor=
"0.0"
AnchorPane.rightAnchor=
"0.0"
AnchorPane.topAnchor=
"0.0"
/>
</center>
<bottom>
<HBox
BorderPane.alignment=
"CENTER"
>
...
...
src/eu/simstadt/regionchooser/RegionChooserController.java
View file @
b1ffe7fe
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
<
Coord
>
regionPolygon
;
Array
List
<
Coord
>
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
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment