Class AbstractMapViewer<T,​U extends Tile<T>>

  • Type Parameters:
    T - image type (BuffredIamge for swing and Image for JavaFX)
    U - Tile type

    public abstract class AbstractMapViewer<T,​U extends Tile<T>>
    extends Object
    AbstractMapViewer was created to provide common functionality for both Swing and JavaFX implementation.
    Author:
    Frantisek Post
    • Field Detail

      • scaleValue

        protected long scaleValue
      • pixelToMeter

        protected float pixelToMeter
    • Constructor Detail

      • AbstractMapViewer

        public AbstractMapViewer()
    • Method Detail

      • setZoom

        public void setZoom​(int zoom)
        Set zoom level
        Parameters:
        zoom -
      • getZoom

        public int getZoom()
        Gets the current zoom level
        Returns:
        the current zoom level
      • getCenter

        public Point2D getCenter()
        Gets center of the map in pixel coordinates
        Returns:
        center of the map in pixel coordinates
      • setCenter

        public void setCenter​(Point2D center)
        Sets the new center of the map in pixel coordinates.
        Parameters:
        center - the new center of the map in pixel coordinates
      • getViewportBounds

        public Rectangle getViewportBounds()
        Gets bounds of component
        Returns:
        bounds of component
      • setCenterPosition

        public void setCenterPosition​(GeoPosition geoPosition)
        Sets center position of the map
        Parameters:
        geoPosition - center position of the map
      • getCenterPosition

        public GeoPosition getCenterPosition()
        A property indicating the center position of the map
        Returns:
        the current center position
      • setTileFactory

        public void setTileFactory​(TileFactory<T,​U> factory)
        Set the current tile factory
        Parameters:
        factory - the new property value
      • getAddressLocation

        public GeoPosition getAddressLocation()
        Gets the current address location of the map. This property does not change when the user pans the map. This property is bound.
        Returns:
        the current map location (address)
      • setAddressLocation

        public void setAddressLocation​(GeoPosition addressLocation)
        Gets the current address location of the map
        Parameters:
        addressLocation - the new address location
        See Also:
        getAddressLocation()
      • recenterToAddressLocation

        public void recenterToAddressLocation()
        Re-centers the map to have the current address location be at the center of the map, accounting for the map's width and height.
        See Also:
        getAddressLocation()
      • calculateZoomFrom

        public void calculateZoomFrom​(Set<GeoPosition> positions)
        Calculates a zoom level so that all points in the specified set will be visible on screen. This is useful if you have a bunch of points in an area like a city and you want to zoom out so that the entire city and it's points are visible without panning.
        Parameters:
        positions - A set of GeoPositions to calculate the new zoom from
      • isPanEnabled

        public boolean isPanEnabled()
        A property indicating if the map should be pannable by the user using the mouse.
        Returns:
        property value
      • setPanEnabled

        public void setPanEnabled​(boolean panEnabled)
        A property indicating if the map should be pannable by the user using the mouse.
        Parameters:
        panEnabled - new property value
      • isZoomEnabled

        public boolean isZoomEnabled()
        A property indicating if the map should be zoomable by the user using the mouse wheel.
        Returns:
        the current property value
      • setZoomEnabled

        public void setZoomEnabled​(boolean zoomEnabled)
        A property indicating if the map should be zoomable by the user using the mouse wheel.
        Parameters:
        zoomEnabled - the new value of the property
      • isRestrictOutsidePanning

        public boolean isRestrictOutsidePanning()
      • setRestrictOutsidePanning

        public void setRestrictOutsidePanning​(boolean restrictOutsidePanning)
      • isHorizontalWrapped

        public boolean isHorizontalWrapped()
      • setHorizontalWrapped

        public void setHorizontalWrapped​(boolean horizontalWrapped)
      • convertGeoPositionToPoint

        public Point2D convertGeoPositionToPoint​(GeoPosition pos)
        Converts the specified GeoPosition to a point in the JXMapViewer's local coordinate space. This method is especially useful when drawing lat/long positions on the map.
        Parameters:
        pos - a GeoPosition on the map
        Returns:
        the point in the local coordinate space of the map
      • convertPointToGeoPosition

        public GeoPosition convertPointToGeoPosition​(Point2D pt)
        Converts the specified Point2D in the JXMapViewer's local coordinate space to a GeoPosition on the map. This method is especially useful for determining the GeoPosition under the mouse cursor.
        Parameters:
        pt - a point in the local coordinate space of the map
        Returns:
        the point converted to a GeoPosition
      • calculateZoom

        public int calculateZoom​(double x,
                                 double y)
        Calculates zoom level from selected areain the map
        Parameters:
        x - width of the selected area
        y - height of the selected area
        Returns:
        zoom level
      • zoomToCoordinates

        public void zoomToCoordinates​(double startX,
                                      double startY,
                                      double endX,
                                      double endY)
        Zoom the map to show selected area in the map
        Parameters:
        startX - x coordinate of area start
        startY - y coordinate of area start
        endX - x coordinate of area end
        endY - x coordinate of area end
      • firePropertyChange

        protected abstract void firePropertyChange​(String name,
                                                   Object oldValue,
                                                   Object newValue)
      • getWidth

        protected abstract int getWidth()
        Gets width of mapViewer component
        Returns:
      • getHeight

        protected abstract int getHeight()
        Gets height of mapViewer component
        Returns:
      • getInsets

        protected abstract Insets getInsets()
        Gets insets of mapViewer component
        Returns:
      • repaint

        protected abstract void repaint()
        Callback method to repaint mapViewer component
      • fireRepaintCallbacks

        public void fireRepaintCallbacks()
        Method to fire all RepaintCallbacks.
      • addRepaintCallback

        public void addRepaintCallback​(RepaintCallback repaintCallback)
        Add RepaintCallback to a list of callbacks, fired when repaint of a component and its subcomponents is needed
        Parameters:
        repaintCallback -
      • removeRepaintCallback

        public void removeRepaintCallback​(RepaintCallback repaintCallback)
        Remove RepaintCallback from a list of callbacks
        Parameters:
        repaintCallback -
      • setZoomFromGeoPosition

        public void setZoomFromGeoPosition​(GeoPosition startPosition,
                                           GeoPosition endPosition)
      • getScaleValue

        public long getScaleValue()
      • getPixelToMeter

        public float getPixelToMeter()