Class MapView

java.lang.Object
javafx.scene.Node
javafx.scene.Parent
javafx.scene.layout.Region
it.tidalwave.mapviewer.javafx.MapView
All Implemented Interfaces:
javafx.css.Styleable, javafx.event.EventTarget

public class MapView extends javafx.scene.layout.Region
A JavaFX control capable to render a map based on tiles. It must be associated to a TileSource that provides the tile bitmaps; two instances are provided, OpenStreetMapTileSource and OpenTopoMapTileSource. Further sources can be easily implemented by overriding TileSourceSupport. The basic properties of a MapView are:
  • tileSourceProperty(): the tile source (that can be changed during the life of MapView);
  • centerProperty(): the coordinates that are rendered at the center of the screen;
  • zoomProperty(): the detail level for the map, going from 1 (the lowest) to a value depending on the tile source.
Other properties are: The method fitArea(MapArea) can be used to adapt rendering parameters so that the given area is rendered; this is useful e.g. when one wants to render a GPS track. Maps can be scrolled by dragging and re-centered by double-clicking on a point (use
invalid reference
#setRecenterOnDoubleClick(boolean)
to enable this behaviour). It is possible to add and remove overlays that move in solid with the map:
Author:
Fabrizio Giudici
See Also:
  • Property Summary

    Properties
    Type
    Property
    Description
    final javafx.beans.property.ObjectProperty<MapArea>
    Returns the area rendered on the map.
    final javafx.beans.property.ObjectProperty<MapCoordinates>
    Returns the center property.
    final javafx.beans.property.ObjectProperty<MapCoordinates>
    Returns the coordinates corresponding to the point where the mouse is.
    final javafx.beans.property.ReadOnlyDoubleProperty
    Returns the max zoom level property.
    final javafx.beans.property.ReadOnlyDoubleProperty
    Returns the min zoom level property.
    final javafx.beans.property.ObjectProperty<TileSource>
    Returns the tile source property.
    final javafx.beans.property.DoubleProperty
    Returns the zoom level property.

    Properties inherited from class javafx.scene.layout.Region

    background, border, cacheShape, centerShape, height, insets, maxHeight, maxWidth, minHeight, minWidth, opaqueInsets, padding, prefHeight, prefWidth, scaleShape, shape, snapToPixel, width

    Properties inherited from class javafx.scene.Parent

    needsLayout

    Properties inherited from class javafx.scene.Node

    accessibleHelp, accessibleRoleDescription, accessibleRole, accessibleText, blendMode, boundsInLocal, boundsInParent, cacheHint, cache, clip, cursor, depthTest, disabled, disable, effectiveNodeOrientation, effect, eventDispatcher, focused, focusTraversable, focusVisible, focusWithin, hover, id, inputMethodRequests, layoutBounds, layoutX, layoutY, localToParentTransform, localToSceneTransform, managed, mouseTransparent, nodeOrientation, onContextMenuRequested, onDragDetected, onDragDone, onDragDropped, onDragEntered, onDragExited, onDragOver, onInputMethodTextChanged, onKeyPressed, onKeyReleased, onKeyTyped, onMouseClicked, onMouseDragEntered, onMouseDragExited, onMouseDragged, onMouseDragOver, onMouseDragReleased, onMouseEntered, onMouseExited, onMouseMoved, onMousePressed, onMouseReleased, onRotate, onRotationFinished, onRotationStarted, onScrollFinished, onScroll, onScrollStarted, onSwipeDown, onSwipeLeft, onSwipeRight, onSwipeUp, onTouchMoved, onTouchPressed, onTouchReleased, onTouchStationary, onZoomFinished, onZoom, onZoomStarted, opacity, parent, pickOnBounds, pressed, rotate, rotationAxis, scaleX, scaleY, scaleZ, scene, style, translateX, translateY, translateZ, viewOrder, visible
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    static final record 
    Options for creating a MapView.
    static class 
    This helper class provides methods useful for creating map overlays.
  • Field Summary

    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
    Creates a new instance.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    Adds an overlay, passing a callback that will be responsible for rendering the overlay, when needed.
    final javafx.beans.property.ObjectProperty<MapArea>
    Returns the area rendered on the map.
    final javafx.beans.property.ObjectProperty<MapCoordinates>
    Returns the center property.
    Returns a point on the map corresponding to the given coordinates.
    final javafx.beans.property.ObjectProperty<MapCoordinates>
    Returns the coordinates corresponding to the point where the mouse is.
    void
    Fits the zoom level and centers the map so that the two corners are visible.
    final MapArea
    Returns the area rendered on the map.
    Returns the center coordinates.
    final double
    Returns the max zoom level.
    double
    Returns the scale of the map in meters per pixel.
    final double
    Returns the min zoom level.
    Returns the tile source.
    final double
    Returns the zoom level.
    final javafx.beans.property.ReadOnlyDoubleProperty
    Returns the max zoom level property.
    final javafx.beans.property.ReadOnlyDoubleProperty
    Returns the min zoom level property.
    Returns a new set of default options.
    Returns the coordinates corresponding to a given point on the map.
    void
    Removes all overlays.
    void
    Removes an overlay.
    final void
    Sets the coordinates to show at the center of the map.
    final void
    Sets the tile source.
    final void
    setZoom(double zoom)
    Sets the zoom level.
    final javafx.beans.property.ObjectProperty<TileSource>
    Returns the tile source property.
    final javafx.beans.property.DoubleProperty
    Returns the zoom level property.

    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, focusVisibleProperty, focusWithinProperty, 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, isFocusVisible, isFocusWithin, 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
  • Property Details

    • tileSource

      @Nonnull public final javafx.beans.property.ObjectProperty<TileSource> tileSourceProperty
      Returns the tile source property..
      Returns:
      the tile source property
      See Also:
    • center

      @Nonnull public final javafx.beans.property.ObjectProperty<MapCoordinates> centerProperty
      Returns the center property..
      Returns:
      the center property
      See Also:
    • zoom

      @Nonnull public final javafx.beans.property.DoubleProperty zoomProperty
      Returns the zoom level property..
      Returns:
      the zoom level property
      See Also:
    • minZoom

      @Nonnull public final javafx.beans.property.ReadOnlyDoubleProperty minZoomProperty
      Returns the min zoom level property..
      Returns:
      the min zoom level property
      See Also:
    • maxZoom

      @Nonnull public final javafx.beans.property.ReadOnlyDoubleProperty maxZoomProperty
      Returns the max zoom level property..
      Returns:
      the max zoom level property
      See Also:
    • coordinatesUnderMouse

      @Nonnull public final javafx.beans.property.ObjectProperty<MapCoordinates> coordinatesUnderMouseProperty
      Returns the coordinates corresponding to the point where the mouse is..
      Returns:
      the coordinates corresponding to the point where the mouse is
      See Also:
    • area

      @Nonnull public final javafx.beans.property.ObjectProperty<MapArea> areaProperty
      Returns the area rendered on the map..
      Returns:
      the area rendered on the map
      See Also:
  • Constructor Details

    • MapView

      public MapView(@Nonnull MapView.Options options)
      Creates a new instance.
      Parameters:
      options - options for the control
  • Method Details

    • options

      @Nonnull public static MapView.Options options()
      Returns a new set of default options..
      Returns:
      a new set of default options
    • getTileSource

      @Nonnull public final TileSource getTileSource()
      Returns the tile source..
      Returns:
      the tile source
      See Also:
    • setTileSource

      public final void setTileSource(@Nonnull TileSource tileSource)
      Sets the tile source. Changing the tile source might change the zoom level to make sure it is within the limits of the new source.
      Parameters:
      tileSource - the tile source
      See Also:
    • tileSourceProperty

      @Nonnull public final javafx.beans.property.ObjectProperty<TileSource> tileSourceProperty()
      Returns the tile source property..
      Returns:
      the tile source property
      See Also:
    • getCenter

      @Nonnull public final MapCoordinates getCenter()
      Returns the center coordinates..
      Returns:
      the center coordinates
      See Also:
    • setCenter

      public final void setCenter(@Nonnull MapCoordinates center)
      Sets the coordinates to show at the center of the map.
      Parameters:
      center - the center coordinates
      See Also:
    • centerProperty

      @Nonnull public final javafx.beans.property.ObjectProperty<MapCoordinates> centerProperty()
      Returns the center property..
      Returns:
      the center property
      See Also:
    • getZoom

      public final double getZoom()
      Returns the zoom level..
      Returns:
      the zoom level
      See Also:
    • setZoom

      public final void setZoom(double zoom)
      Sets the zoom level.
      Parameters:
      zoom - the zoom level
      See Also:
    • zoomProperty

      @Nonnull public final javafx.beans.property.DoubleProperty zoomProperty()
      Returns the zoom level property..
      Returns:
      the zoom level property
      See Also:
    • getMinZoom

      public final double getMinZoom()
      Returns the min zoom level..
      Returns:
      the min zoom level
      See Also:
    • minZoomProperty

      @Nonnull public final javafx.beans.property.ReadOnlyDoubleProperty minZoomProperty()
      Returns the min zoom level property..
      Returns:
      the min zoom level property
      See Also:
    • getMaxZoom

      public final double getMaxZoom()
      Returns the max zoom level..
      Returns:
      the max zoom level
      See Also:
    • maxZoomProperty

      @Nonnull public final javafx.beans.property.ReadOnlyDoubleProperty maxZoomProperty()
      Returns the max zoom level property..
      Returns:
      the max zoom level property
      See Also:
    • coordinatesUnderMouseProperty

      @Nonnull public final javafx.beans.property.ObjectProperty<MapCoordinates> coordinatesUnderMouseProperty()
      Returns the coordinates corresponding to the point where the mouse is..
      Returns:
      the coordinates corresponding to the point where the mouse is
    • getArea

      @Nonnull public final MapArea getArea()
      Returns the area rendered on the map..
      Returns:
      the area rendered on the map
      See Also:
    • areaProperty

      @Nonnull public final javafx.beans.property.ObjectProperty<MapArea> areaProperty()
      Returns the area rendered on the map..
      Returns:
      the area rendered on the map
      See Also:
    • fitArea

      public void fitArea(@Nonnull MapArea area)
      Fits the zoom level and centers the map so that the two corners are visible.
      Parameters:
      area - the area to fit
      See Also:
    • getMetersPerPixel

      public double getMetersPerPixel()
      Returns the scale of the map in meters per pixel..
      Returns:
      the scale of the map in meters per pixel
    • coordinatesToPoint

      @Nonnull public MapViewPoint coordinatesToPoint(@Nonnull MapCoordinates coordinates)
      Returns a point on the map corresponding to the given coordinates..
      Parameters:
      coordinates - the coordinates
      Returns:
      a point on the map corresponding to the given coordinates
    • pointToCoordinates

      @Nonnull public MapCoordinates pointToCoordinates(@Nonnull MapViewPoint point)
      Returns the coordinates corresponding to a given point on the map..
      Parameters:
      point - the point on the map
      Returns:
      the coordinates corresponding to a given point on the map
    • addOverlay

      public void addOverlay(@Nonnull String name, @Nonnull Consumer<MapView.OverlayHelper> creator)
      Adds an overlay, passing a callback that will be responsible for rendering the overlay, when needed.
      Parameters:
      name - the name of the overlay
      creator - the overlay creator
      See Also:
    • removeOverlay

      public void removeOverlay(@Nonnull String name)
      Removes an overlay.
      Parameters:
      name - the name of the overlay to remove
    • removeAllOverlays

      public void removeAllOverlays()
      Removes all overlays.