Class MapView

  • All Implemented Interfaces:
    javafx.css.Styleable, javafx.event.EventTarget

    public final class MapView
    extends javafx.scene.layout.Region
    Map component. To use the MapView, construct it and add it to your scene. Then the initialized property should be observed as well as bindings/observations to other properties should be established.

    After that, the initialize() Method must be called. When the MapView is initialized and ready to be used, the initialized property is set to true.

    No map is displayed until setCenter(Coordinate) is called.

    The MapView does it's logging using java logging with level FINER.

    All the setters return the MapView itself to enable fluent programming.
    Author:
    P.J. Meisch ([email protected])., Erik Jähne
    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
      class  MapView.JavaConnector
      Connector object.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      static int INITIAL_ZOOM
      initial zoom value for the map.
      static int MAX_ZOOM
      maximal zoom level, OL defines this as 28.
      static int MIN_ZOOM
      minimal zoom level, OL defines this as 0.
      • Fields inherited from class javafx.scene.layout.Region

        USE_COMPUTED_SIZE, USE_PREF_SIZE
      • Fields inherited from class javafx.scene.Node

        BASELINE_OFFSET_SAME_AS_HEIGHT
    • Constructor Summary

      Constructors 
      Constructor Description
      MapView()
      create a MapView with no initial center coordinate.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      MapView addCoordinateLine​(CoordinateLine coordinateLine)
      add a CoordinateLine to the map.
      MapView addLabel​(MapLabel mapLabel)
      adds a label to the map.
      MapView addMarker​(Marker marker)
      adds a marker to the map.
      javafx.beans.property.SimpleIntegerProperty animationDurationProperty()  
      javafx.beans.property.SimpleObjectProperty<Coordinate> centerProperty()  
      int getAnimationDuration()  
      Coordinate getCenter()  
      boolean getInitialized()  
      MapType getMapType()  
      OfflineCache getOfflineCache()  
      double getZoom()  
      void initialize()
      initializes the MapView.
      javafx.beans.property.ReadOnlyBooleanProperty initializedProperty()  
      javafx.beans.property.SimpleObjectProperty<MapType> mapTypeProperty()  
      MapView removeCoordinateLine​(CoordinateLine coordinateLine)
      removes a CoordinateLine from the map.
      MapView removeLabel​(MapLabel mapLabel)
      removes the given label from the map and deregisters the change listeners.
      MapView removeMarker​(Marker marker)
      removes the given marker from the map and deregisters the change listeners.
      MapView setAnimationDuration​(int animationDuration)
      sets the animation duration in ms.
      MapView setBingMapsApiKey​(java.lang.String apiKey)
      sets the Bing Maps API Key.
      MapView setCenter​(Coordinate center)
      sets the center of the map.
      void setCustomMapviewCssURL​(java.net.URL url)
      sets the URL for the custom mapview css file.
      MapView setExtent​(Extent extent)
      sets the center and zoom of the map so that the given extent is visible.
      MapView setMapType​(MapType mapType)
      sets the current MapType.
      MapView setWMSParam​(WMSParam wmsParam)
      sets the WMS parameters.
      MapView setXYZParam​(XYZParam xyzParam)
      sets the XYZ parameters.
      MapView setZoom​(double zoom)
      sets the zoom level.
      javafx.beans.property.SimpleDoubleProperty zoomProperty()  
      • Methods inherited from class javafx.scene.layout.Region

        backgroundProperty, borderProperty, cacheShapeProperty, centerShapeProperty, computeMaxHeight, computeMaxWidth, computeMinHeight, computeMinWidth, computePrefHeight, computePrefWidth, getBackground, getBorder, getClassCssMetaData, getCssMetaData, getHeight, getInsets, getMaxHeight, getMaxWidth, getMinHeight, getMinWidth, getOpaqueInsets, getPadding, getPrefHeight, getPrefWidth, getShape, getUserAgentStylesheet, getWidth, heightProperty, insetsProperty, isCacheShape, isCenterShape, isResizable, isScaleShape, isSnapToPixel, layoutInArea, layoutInArea, layoutInArea, layoutInArea, maxHeight, maxHeightProperty, maxWidth, maxWidthProperty, minHeight, minHeightProperty, minWidth, minWidthProperty, opaqueInsetsProperty, paddingProperty, positionInArea, positionInArea, prefHeight, prefHeightProperty, prefWidth, prefWidthProperty, resize, scaleShapeProperty, setBackground, setBorder, setCacheShape, setCenterShape, setHeight, setMaxHeight, setMaxSize, setMaxWidth, setMinHeight, setMinSize, setMinWidth, setOpaqueInsets, setPadding, setPrefHeight, setPrefSize, setPrefWidth, setScaleShape, setShape, setSnapToPixel, setWidth, shapeProperty, snappedBottomInset, snappedLeftInset, snappedRightInset, snappedTopInset, snapPosition, snapPositionX, snapPositionY, snapSize, snapSizeX, snapSizeY, snapSpace, snapSpaceX, snapSpaceY, snapToPixelProperty, widthProperty
      • Methods inherited from class javafx.scene.Parent

        getBaselineOffset, getChildren, getChildrenUnmodifiable, getManagedChildren, getStylesheets, isNeedsLayout, layout, layoutChildren, lookup, needsLayoutProperty, queryAccessibleAttribute, requestLayout, requestParentLayout, setNeedsLayout, updateBounds
      • Methods inherited from class javafx.scene.Node

        accessibleHelpProperty, accessibleRoleDescriptionProperty, accessibleRoleProperty, accessibleTextProperty, addEventFilter, addEventHandler, applyCss, autosize, blendModeProperty, boundsInLocalProperty, boundsInParentProperty, buildEventDispatchChain, cacheHintProperty, cacheProperty, clipProperty, computeAreaInScreen, contains, contains, cursorProperty, depthTestProperty, disabledProperty, disableProperty, effectiveNodeOrientationProperty, effectProperty, eventDispatcherProperty, executeAccessibleAction, fireEvent, focusedProperty, focusTraversableProperty, getAccessibleHelp, getAccessibleRole, getAccessibleRoleDescription, getAccessibleText, getBlendMode, getBoundsInLocal, getBoundsInParent, getCacheHint, getClip, getContentBias, getCursor, getDepthTest, getEffect, getEffectiveNodeOrientation, getEventDispatcher, getId, getInitialCursor, getInitialFocusTraversable, getInputMethodRequests, getLayoutBounds, getLayoutX, getLayoutY, getLocalToParentTransform, getLocalToSceneTransform, getNodeOrientation, getOnContextMenuRequested, getOnDragDetected, getOnDragDone, getOnDragDropped, getOnDragEntered, getOnDragExited, getOnDragOver, getOnInputMethodTextChanged, getOnKeyPressed, getOnKeyReleased, getOnKeyTyped, getOnMouseClicked, getOnMouseDragEntered, getOnMouseDragExited, getOnMouseDragged, getOnMouseDragOver, getOnMouseDragReleased, getOnMouseEntered, getOnMouseExited, getOnMouseMoved, getOnMousePressed, getOnMouseReleased, getOnRotate, getOnRotationFinished, getOnRotationStarted, getOnScroll, getOnScrollFinished, getOnScrollStarted, getOnSwipeDown, getOnSwipeLeft, getOnSwipeRight, getOnSwipeUp, getOnTouchMoved, getOnTouchPressed, getOnTouchReleased, getOnTouchStationary, getOnZoom, getOnZoomFinished, getOnZoomStarted, getOpacity, getParent, getProperties, getPseudoClassStates, getRotate, getRotationAxis, getScaleX, getScaleY, getScaleZ, getScene, getStyle, getStyleableParent, getStyleClass, getTransforms, getTranslateX, getTranslateY, getTranslateZ, getTypeSelector, getUserData, getViewOrder, hasProperties, hoverProperty, idProperty, inputMethodRequestsProperty, intersects, intersects, isCache, isDisable, isDisabled, isFocused, isFocusTraversable, isHover, isManaged, isMouseTransparent, isPickOnBounds, isPressed, isVisible, layoutBoundsProperty, layoutXProperty, layoutYProperty, localToParent, localToParent, localToParent, localToParent, localToParent, localToParentTransformProperty, localToScene, localToScene, localToScene, localToScene, localToScene, localToScene, localToScene, localToScene, localToScene, localToScene, localToSceneTransformProperty, localToScreen, localToScreen, localToScreen, localToScreen, localToScreen, lookupAll, managedProperty, mouseTransparentProperty, nodeOrientationProperty, notifyAccessibleAttributeChanged, onContextMenuRequestedProperty, onDragDetectedProperty, onDragDoneProperty, onDragDroppedProperty, onDragEnteredProperty, onDragExitedProperty, onDragOverProperty, onInputMethodTextChangedProperty, onKeyPressedProperty, onKeyReleasedProperty, onKeyTypedProperty, onMouseClickedProperty, onMouseDragEnteredProperty, onMouseDragExitedProperty, onMouseDraggedProperty, onMouseDragOverProperty, onMouseDragReleasedProperty, onMouseEnteredProperty, onMouseExitedProperty, onMouseMovedProperty, onMousePressedProperty, onMouseReleasedProperty, onRotateProperty, onRotationFinishedProperty, onRotationStartedProperty, onScrollFinishedProperty, onScrollProperty, onScrollStartedProperty, onSwipeDownProperty, onSwipeLeftProperty, onSwipeRightProperty, onSwipeUpProperty, onTouchMovedProperty, onTouchPressedProperty, onTouchReleasedProperty, onTouchStationaryProperty, onZoomFinishedProperty, onZoomProperty, onZoomStartedProperty, opacityProperty, parentProperty, parentToLocal, parentToLocal, parentToLocal, parentToLocal, parentToLocal, pickOnBoundsProperty, pressedProperty, pseudoClassStateChanged, relocate, removeEventFilter, removeEventHandler, requestFocus, resizeRelocate, rotateProperty, rotationAxisProperty, scaleXProperty, scaleYProperty, scaleZProperty, sceneProperty, sceneToLocal, sceneToLocal, sceneToLocal, sceneToLocal, sceneToLocal, sceneToLocal, sceneToLocal, sceneToLocal, screenToLocal, screenToLocal, screenToLocal, setAccessibleHelp, setAccessibleRole, setAccessibleRoleDescription, setAccessibleText, setBlendMode, setCache, setCacheHint, setClip, setCursor, setDepthTest, setDisable, setDisabled, setEffect, setEventDispatcher, setEventHandler, setFocused, setFocusTraversable, setHover, setId, setInputMethodRequests, setLayoutX, setLayoutY, setManaged, setMouseTransparent, setNodeOrientation, setOnContextMenuRequested, setOnDragDetected, setOnDragDone, setOnDragDropped, setOnDragEntered, setOnDragExited, setOnDragOver, setOnInputMethodTextChanged, setOnKeyPressed, setOnKeyReleased, setOnKeyTyped, setOnMouseClicked, setOnMouseDragEntered, setOnMouseDragExited, setOnMouseDragged, setOnMouseDragOver, setOnMouseDragReleased, setOnMouseEntered, setOnMouseExited, setOnMouseMoved, setOnMousePressed, setOnMouseReleased, setOnRotate, setOnRotationFinished, setOnRotationStarted, setOnScroll, setOnScrollFinished, setOnScrollStarted, setOnSwipeDown, setOnSwipeLeft, setOnSwipeRight, setOnSwipeUp, setOnTouchMoved, setOnTouchPressed, setOnTouchReleased, setOnTouchStationary, setOnZoom, setOnZoomFinished, setOnZoomStarted, setOpacity, setPickOnBounds, setPressed, setRotate, setRotationAxis, setScaleX, setScaleY, setScaleZ, setStyle, setTranslateX, setTranslateY, setTranslateZ, setUserData, setViewOrder, setVisible, snapshot, snapshot, startDragAndDrop, startFullDrag, styleProperty, toBack, toFront, toString, translateXProperty, translateYProperty, translateZProperty, usesMirroring, viewOrderProperty, visibleProperty
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
      • Methods inherited from interface javafx.css.Styleable

        getStyleableNode
    • Field Detail

      • MIN_ZOOM

        public static final int MIN_ZOOM
        minimal zoom level, OL defines this as 0.
        See Also:
        Constant Field Values
      • MAX_ZOOM

        public static final int MAX_ZOOM
        maximal zoom level, OL defines this as 28.
        See Also:
        Constant Field Values
      • INITIAL_ZOOM

        public static final int INITIAL_ZOOM
        initial zoom value for the map.
        See Also:
        Constant Field Values
    • Constructor Detail

      • MapView

        public MapView()
        create a MapView with no initial center coordinate.
    • Method Detail

      • getCenter

        public Coordinate getCenter()
        Returns:
        the current center of the map.
      • setCenter

        public MapView setCenter​(Coordinate center)
        sets the center of the map. The coordinate must be in EPSG:4326 coordinates (WGS)
        Parameters:
        center - new center
        Returns:
        this object
      • getInitialized

        public boolean getInitialized()
        Returns:
        true if the MapView is initialized.
      • getZoom

        public double getZoom()
        Returns:
        the current zoom value.
      • setZoom

        public MapView setZoom​(double zoom)
        sets the zoom level. the zoom value is rounded to the next whole number using Math.round(double) and then checked to be in the range between MIN_ZOOM and MAX_ZOOM. If the value is not in this range, the call is ignored.
        Parameters:
        zoom - new zoom level
        Returns:
        this object
      • getMapType

        public MapType getMapType()
        Returns:
        the current MapType.
      • setMapType

        public MapView setMapType​(MapType mapType)
        sets the current MapType.
        Parameters:
        mapType - the new MapType
        Returns:
        this object
      • addCoordinateLine

        public MapView addCoordinateLine​(CoordinateLine coordinateLine)
        add a CoordinateLine to the map. If it was already added, nothing happens. The MapView only stores a weak reference to the object, so the caller must keep a reference in order to prevent the line to be removed from the map. This method must only be called after the map is initialized, otherwise a warning is logged and the coordinateLine is not added to the map.
        Parameters:
        coordinateLine - the CoordinateLine to add
        Returns:
        this object
        Throws:
        java.lang.NullPointerException - if argument is null
      • addLabel

        public MapView addLabel​(MapLabel mapLabel)
        adds a label to the map. If it was already added, nothing is changed. If the MapView is not yet initialized, a warning is logged and nothing changes. If the label has no coordinate set, it is not added and a logging entry is written. The MapView only keeps a weak reference to the label, so the caller must keep a reference to prevent the Label object from being garbage collected.
        Parameters:
        mapLabel - the label
        Returns:
        this object
        Throws:
        java.lang.NullPointerException - if marker is null
      • addMarker

        public MapView addMarker​(Marker marker)
        adds a marker to the map. If it was already added, nothing is changed. If the MapView is not yet initialized, a warning is logged and nothing changes. If the marker has no coordinate set, it is not added and a logging entry is written. The MapView only keeps a weak reference to the marker, so the caller must keep a reference to prevent the Marker object from being garbage collected.
        Parameters:
        marker - the marker
        Returns:
        this object
        Throws:
        java.lang.NullPointerException - if marker is null
      • animationDurationProperty

        public javafx.beans.property.SimpleIntegerProperty animationDurationProperty()
      • centerProperty

        public javafx.beans.property.SimpleObjectProperty<Coordinate> centerProperty()
      • getAnimationDuration

        public int getAnimationDuration()
        Returns:
        the current animation duration.
      • setAnimationDuration

        public MapView setAnimationDuration​(int animationDuration)
        sets the animation duration in ms. If a value greater than 1 is set, then panning or zooming the map by setting the center or zoom property will be animated in the given time. Setting this to zero does not switch off the zoom animation shown when clicking the controls in the map.
        Parameters:
        animationDuration - animation duration in ms
        Returns:
        this object
      • initialize

        public void initialize()
        initializes the MapView. The internal HTML file is loaded into the contained WebView and the necessary setup is made for communication between this object and the Javascript elements on the web page.
      • initializedProperty

        public javafx.beans.property.ReadOnlyBooleanProperty initializedProperty()
        Returns:
        the readonly initialized property.
      • mapTypeProperty

        public javafx.beans.property.SimpleObjectProperty<MapType> mapTypeProperty()
        Returns:
        the mapType property.
      • removeCoordinateLine

        public MapView removeCoordinateLine​(CoordinateLine coordinateLine)
        removes a CoordinateLine from the map. If it was not added or the MapView is not yet initialized, nothing happens
        Parameters:
        coordinateLine - the CoordinateLine to add
        Returns:
        this object
        Throws:
        java.lang.NullPointerException - if argument is null
      • removeLabel

        public MapView removeLabel​(MapLabel mapLabel)
        removes the given label from the map and deregisters the change listeners. If the label was not in the map or the MapView is not yet initialized, nothing happens.
        Parameters:
        mapLabel - label to remove
        Returns:
        this object
        Throws:
        java.lang.NullPointerException - if mapLabel is null
      • removeMarker

        public MapView removeMarker​(Marker marker)
        removes the given marker from the map and deregisters the change listeners. If the marker was not in the map or the MapView is not yet initialized, nothing happens.
        Parameters:
        marker - marker to remove
        Returns:
        this object
        Throws:
        java.lang.NullPointerException - if marker is null
      • setBingMapsApiKey

        public MapView setBingMapsApiKey​(java.lang.String apiKey)
        sets the Bing Maps API Key.
        Parameters:
        apiKey - api key
        Returns:
        this object
      • setWMSParam

        public MapView setWMSParam​(WMSParam wmsParam)
        sets the WMS parameters.
        Parameters:
        wmsParam - WMS parameters
        Returns:
        this object
      • setXYZParam

        public MapView setXYZParam​(XYZParam xyzParam)
        sets the XYZ parameters.
        Parameters:
        xyzParam - XYZ parameters
        Returns:
        this object
      • setCustomMapviewCssURL

        public void setCustomMapviewCssURL​(java.net.URL url)
        sets the URL for the custom mapview css file.
        Parameters:
        url - css url
        Throws:
        java.lang.NullPointerException - if url is null
      • setExtent

        public MapView setExtent​(Extent extent)
        sets the center and zoom of the map so that the given extent is visible.
        Parameters:
        extent - extent to show, if null, nothing is changed
        Returns:
        this object
        Throws:
        java.lang.NullPointerException - when extent is null
      • zoomProperty

        public javafx.beans.property.SimpleDoubleProperty zoomProperty()