Skip to content
Snippets Groups Projects

Add infowindows to markers

Merged Eirik Steira requested to merge refactor/map-markers into dev
All threads resolved!
3 files
+ 48
23
Compare changes
  • Side-by-side
  • Inline
Files
3
@@ -3,7 +3,9 @@ package NTNU.IDATT1002.controllers;
import NTNU.IDATT1002.models.GeoLocation;
import NTNU.IDATT1002.models.Image;
import com.lynden.gmapsfx.GoogleMapView;
import com.lynden.gmapsfx.javascript.event.UIEventType;
import com.lynden.gmapsfx.javascript.object.*;
import netscape.javascript.JSObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -19,19 +21,26 @@ import java.util.stream.Collectors;
*/
public class ImageMapFactory {
private static Logger logger = LoggerFactory.getLogger(ImageMapFactory.class);
private GoogleMap map;
private Logger logger = LoggerFactory.getLogger(ImageMapFactory.class);
private ImageMapFactory() {}
/**
*
*/
public ImageMapFactory() {
}
/**
* Create a map from given {@link GoogleMapView} with default options.
*
* @param googleMapView the map view to add the map to
* @param mapView the map view to add the map to
* @return the {@link GoogleMap} created to enable further customization
*/
public static GoogleMap createMap(GoogleMapView googleMapView) {
public GoogleMap createMap(GoogleMapView mapView) {
MapOptions mapOptions = getMapOptions();
return googleMapView.createMap(mapOptions);
map = mapView.createMap(mapOptions);
logger.debug("[x] Map created");
return map;
}
/**
@@ -40,17 +49,15 @@ public class ImageMapFactory {
*
* @return the default map options
*/
private static MapOptions getMapOptions() {
LatLong berlin = new LatLong(52.520008, 13.404954);
private MapOptions getMapOptions() {
LatLong copenhagen = new LatLong(55.676098, 12.568337);
return new MapOptions()
.center(berlin)
.center(copenhagen)
.mapType(MapTypeIdEnum.ROADMAP)
.overviewMapControl(false)
.panControl(false)
.rotateControl(false)
.scaleControl(false)
.streetViewControl(false)
.zoomControl(false)
.zoomControl(true)
.zoom(3);
}
@@ -60,7 +67,7 @@ public class ImageMapFactory {
* @param images the list of images
* @return a list of markers created from the images
*/
public static List<Marker> createMarkers(List<Image> images) {
public List<Marker> createMarkers(List<Image> images) {
List<LatLong> locations = getLatLongs(images);
List<Marker> markers = getMarkers(locations);
logger.info("[x] {} markers created", markers.size());
@@ -73,7 +80,7 @@ public class ImageMapFactory {
* @param images the list of images
* @return a list of {@link LatLong}
*/
private static List<LatLong> getLatLongs(List<Image> images) {
private List<LatLong> getLatLongs(List<Image> images) {
return images.stream()
.map(Image::getGeoLocation)
.filter(GeoLocation::hasLatLong)
@@ -91,15 +98,32 @@ public class ImageMapFactory {
* @param locations the list containing the locations
* @return the list of markers created
*/
private static List<Marker> getMarkers(List<LatLong> locations) {
private List<Marker> getMarkers(List<LatLong> locations) {
return locations.stream()
.map(location -> {
MarkerOptions markerOptions = new MarkerOptions()
.position(location);
logger.info("[x] Marker created for location: {}", location);
return new Marker(markerOptions);
})
.map(this::getMarker)
.collect(Collectors.toList());
}
/**
* Create {@link Marker} for given location with map zoom and center on click event.
*
* @param location the location of the marker
* @return marker created
*/
private Marker getMarker(LatLong location) {
MarkerOptions markerOptions = new MarkerOptions()
.position(location)
.animation(Animation.DROP);
logger.info("[x] Marker created for location: {}", location);
Marker marker = new Marker(markerOptions);
map.addUIEventHandler(marker, UIEventType.click, (JSObject obj) -> {
map.setZoom(10);
map.setCenter(location);
});
return marker;
}
}
Loading