Class GeoMap

  • All Implemented Interfaces:
    GeoMapHelperListener, GeoMapPositioned, org.eclipse.swt.graphics.Drawable

    public class GeoMap
    extends InternalGeoMap
    GeoMap display tiles from openstreetmap as is. This simple minimal viewer supports zoom around mouse-click center and has a simple api. A number of tiles are cached. If you use this it will create traffic on the tileserver you are using. Please be conscious about this. This class is a JPanel which can be integrated into any swing app just by creating an instance and adding like a JLabel. The map has the size 256*1<. This measure is referred to as map-coordinates. Geometric locations like longitude and latitude can be obtained by helper methods. Note that a point in map-coordinates corresponds to a given geometric position but also depending on the current zoom level. You can zoomIn around current mouse position by left double click. Left right click zooms out.

    Methods of interest are

    • setZoom(int) which sets the map's zoom level. Values between 1 and 18 are allowed.
    • setMapPosition(Point) which sets the map's top left corner. (In map coordinates)
    • setCenterPosition(Point) which sets the map's center position. (In map coordinates)
    • for the given longitude and latitude. If you want to center the map around this geometric location you need to pass the result to the method

    For performance tuning the two crucial parameters are the size of the tile cache and the number of image-loader threads.

    License is EPL (Eclipse Public License) https://www.eclipse.org/legal/epl-2.0/. Contact at stepan.rutz@gmx.de

    Version:
    $Revision$
    • Constructor Summary

      Constructors 
      Constructor Description
      GeoMap​(org.eclipse.swt.widgets.Composite parent, int style)
      Creates a new GeoMap using the default size for its internal cache of tiles.
      GeoMap​(org.eclipse.swt.widgets.Composite parent, int style, org.eclipse.swt.graphics.Point mapPosition, int zoom)
      Creates a new GeoMap using the default size for its internal cache of tiles
      GeoMap​(org.eclipse.swt.widgets.Composite parent, int style, org.eclipse.swt.graphics.Point mapPosition, int zoom, int cacheSize)
      Creates a new GeoMap using the default size for its internal cache of tiles
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void addGeoMapListener​(GeoMapListener listener)
      Adds a GeoMapListener, that will be notified of changes to the position and zoom level
      void addMouseHandler​(java.util.EventListener listener)
      Adds listener to appropriate listener lists depending on the listener interfaces that are implemented.
      org.eclipse.swt.graphics.Point computeSize​(int wHint, int hHint)  
      org.eclipse.swt.graphics.Point computeSize​(int wHint, int hHint, boolean changed)  
      private void fireCenterChanged()  
      private void fireZoomChanged()  
      org.eclipse.swt.graphics.Point getCenterPosition()
      Returns the position of the center of this GeoMap.
      org.eclipse.swt.graphics.Point getCursorPosition()
      Returns the map position of the mouse cursor.
      DefaultMouseHandler getDefaultMouseHandler()
      Returns the default mouse handler, so it may be configured or removed.
      TileServer getTileServer()
      Returns the current TileServer of this GeoMap.
      void removeGeoMapListener​(GeoMapListener listener)
      Removes a GeoMapListener, so it no longer will be notified of changes to the position and zoom level
      void removeMouseHandler​(java.util.EventListener listener)
      Removes listener from appropriate listener lists depending on the listener interfaces that are implemented.
      void setCenterPosition​(org.eclipse.swt.graphics.Point mapPosition)
      Sets the position of the center of this GeoMap, without any panning effect.
      void setMapPosition​(int x, int y)
      Sets the position of the upper left corner of this GeoMap, without any panning effect.
      void setMapPosition​(org.eclipse.swt.graphics.Point mapPosition)
      Sets the position of the upper left corner of this GeoMap, without any panning effect.
      void setTileServer​(TileServer tileServer)
      Sets the current TileServer of this GeoMap.
      void setZoom​(int zoom)
      Sets the zoom level, without any transition effect.
      void translateMapPosition​(int tx, int ty)
      Translates the position of the upper left corner of this GeoMap, without any panning effect.
      void zoomIn​(org.eclipse.swt.graphics.Point pivot)
      Zooms in, while ensuring that the pivot point remains at the same screen location.
      void zoomOut​(org.eclipse.swt.graphics.Point pivot)
      Zooms out, while ensuring that the pivot point remains at the same screen location.
      void zoomTo​(org.eclipse.swt.graphics.Rectangle rect)
      Zooms into and centers on the specified rectangle.
      • Methods inherited from class org.eclipse.swt.widgets.Canvas

        drawBackground, getCaret, getIME, scroll, setCaret, setFont, setIME
      • Methods inherited from class org.eclipse.swt.widgets.Composite

        changed, checkSubclass, drawBackground, getBackgroundMode, getChildren, getLayout, getLayoutDeferred, getTabList, isLayoutDeferred, layout, layout, layout, layout, layout, setBackgroundMode, setFocus, setLayout, setLayoutDeferred, setTabList
      • Methods inherited from class org.eclipse.swt.widgets.Scrollable

        computeTrim, getClientArea, getHorizontalBar, getScrollbarsMode, getVerticalBar
      • Methods inherited from class org.eclipse.swt.widgets.Control

        addControlListener, addDragDetectListener, addFocusListener, addGestureListener, addHelpListener, addKeyListener, addMenuDetectListener, addMouseListener, addMouseMoveListener, addMouseTrackListener, addMouseWheelListener, addPaintListener, addTouchListener, addTraverseListener, dragDetect, dragDetect, forceFocus, getAccessible, getBackground, getBackgroundImage, getBorderWidth, getBounds, getCursor, getDragDetect, getEnabled, getFont, getForeground, getLayoutData, getLocation, getMenu, getMonitor, getOrientation, getParent, getRegion, getShell, getSize, getTextDirection, getToolTipText, getTouchEnabled, getVisible, internal_dispose_GC, internal_new_GC, isAutoScalable, isEnabled, isFocusControl, isReparentable, isVisible, moveAbove, moveBelow, pack, pack, print, redraw, redraw, removeControlListener, removeDragDetectListener, removeFocusListener, removeGestureListener, removeHelpListener, removeKeyListener, removeMenuDetectListener, removeMouseListener, removeMouseMoveListener, removeMouseTrackListener, removeMouseWheelListener, removePaintListener, removeTouchListener, removeTraverseListener, requestLayout, setBackground, setBackgroundImage, setBounds, setBounds, setCapture, setCursor, setDragDetect, setEnabled, setForeground, setLayoutData, setLocation, setLocation, setMenu, setOrientation, setParent, setRedraw, setRegion, setSize, setSize, setTextDirection, setToolTipText, setTouchEnabled, setVisible, toControl, toControl, toDisplay, toDisplay, traverse, traverse, traverse, update
      • Methods inherited from class org.eclipse.swt.widgets.Widget

        addDisposeListener, addListener, checkWidget, dispose, getData, getData, getDisplay, getListeners, getStyle, isAutoDirection, isDisposed, isListening, notifyListeners, removeDisposeListener, removeListener, removeListener, reskin, setData, setData, toString
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
    • Field Detail

      • ABOUT_MSG

        public static final java.lang.String ABOUT_MSG
        About message.
        See Also:
        Constant Field Values
      • mouseCoords

        private org.eclipse.swt.graphics.Point mouseCoords
      • geoMapListeners

        private java.util.List<GeoMapListener> geoMapListeners
    • Constructor Detail

      • GeoMap

        public GeoMap​(org.eclipse.swt.widgets.Composite parent,
                      int style)
        Creates a new GeoMap using the default size for its internal cache of tiles. The map is showing the position (275091, 180145 at zoom level 11. In other words this constructor is best used only in debugging scenarios.
        Parameters:
        parent - SWT parent Composite
        style - SWT style as in Canvas, since this class inherits from it. Double buffering is always enabed.
      • GeoMap

        public GeoMap​(org.eclipse.swt.widgets.Composite parent,
                      int style,
                      org.eclipse.swt.graphics.Point mapPosition,
                      int zoom)
        Creates a new GeoMap using the default size for its internal cache of tiles
        Parameters:
        parent - SWT parent Composite
        style - SWT style as in Canvas, since this class inherits from it. Double buffering is always enabed.
        mapPosition - initial mapPosition.
        zoom - initial map zoom
      • GeoMap

        public GeoMap​(org.eclipse.swt.widgets.Composite parent,
                      int style,
                      org.eclipse.swt.graphics.Point mapPosition,
                      int zoom,
                      int cacheSize)
        Creates a new GeoMap using the default size for its internal cache of tiles
        Parameters:
        parent - SWT parent Composite
        style - SWT style as in Canvas, since this class inherits from it. Double buffering is always enabed.
        mapPosition - initial mapPosition.
        zoom - initial map zoom
        cacheSize - initial cache size, eg number of tile-images that are kept in cache to prevent reloading from the network.
    • Method Detail

      • getDefaultMouseHandler

        public DefaultMouseHandler getDefaultMouseHandler()
        Returns the default mouse handler, so it may be configured or removed.
        Returns:
        the default mouse handler
      • addMouseHandler

        public void addMouseHandler​(java.util.EventListener listener)
        Adds listener to appropriate listener lists depending on the listener interfaces that are implemented.
        Parameters:
        listener - the listener
      • removeMouseHandler

        public void removeMouseHandler​(java.util.EventListener listener)
        Removes listener from appropriate listener lists depending on the listener interfaces that are implemented.
        Parameters:
        listener - the listener
      • getTileServer

        public TileServer getTileServer()
        Returns the current TileServer of this GeoMap.
        Returns:
        the current TileServer
      • setTileServer

        public void setTileServer​(TileServer tileServer)
        Sets the current TileServer of this GeoMap. Note that this will clear the map and reload the tiles using the new TileServer.
        Parameters:
        tileServer - the TileServer
      • addGeoMapListener

        public void addGeoMapListener​(GeoMapListener listener)
        Adds a GeoMapListener, that will be notified of changes to the position and zoom level
        Parameters:
        listener - the GeoMapListener
      • removeGeoMapListener

        public void removeGeoMapListener​(GeoMapListener listener)
        Removes a GeoMapListener, so it no longer will be notified of changes to the position and zoom level
        Parameters:
        listener - the GeoMapListener
      • fireCenterChanged

        private void fireCenterChanged()
      • fireZoomChanged

        private void fireZoomChanged()
      • setMapPosition

        public void setMapPosition​(org.eclipse.swt.graphics.Point mapPosition)
        Sets the position of the upper left corner of this GeoMap, without any panning effect.
        Parameters:
        mapPosition - the new position
      • setMapPosition

        public void setMapPosition​(int x,
                                   int y)
        Sets the position of the upper left corner of this GeoMap, without any panning effect.
        Specified by:
        setMapPosition in interface GeoMapPositioned
        Overrides:
        setMapPosition in class InternalGeoMap
        Parameters:
        x - the x-coordinate of the position
        y - the y-coordinate of the position
      • translateMapPosition

        public void translateMapPosition​(int tx,
                                         int ty)
        Translates the position of the upper left corner of this GeoMap, without any panning effect.
        Parameters:
        tx - the relative distance in x-direction
        ty - the relative distance in y-direction
      • setZoom

        public void setZoom​(int zoom)
        Sets the zoom level, without any transition effect.
        Specified by:
        setZoom in interface GeoMapPositioned
        Overrides:
        setZoom in class InternalGeoMap
        Parameters:
        zoom - the new zoom level
      • zoomIn

        public void zoomIn​(org.eclipse.swt.graphics.Point pivot)
        Zooms in, while ensuring that the pivot point remains at the same screen location.
        Parameters:
        pivot - the point that will remain at the same screen location.
      • zoomOut

        public void zoomOut​(org.eclipse.swt.graphics.Point pivot)
        Zooms out, while ensuring that the pivot point remains at the same screen location.
        Parameters:
        pivot - the point that will remain at the same screen location.
      • zoomTo

        public void zoomTo​(org.eclipse.swt.graphics.Rectangle rect)
        Zooms into and centers on the specified rectangle.
        Parameters:
        rect - the rectangle
      • getCenterPosition

        public org.eclipse.swt.graphics.Point getCenterPosition()
        Returns the position of the center of this GeoMap. The coordinates depend on the zoom level.
        Returns:
        the position of the center of this GeoMap
      • setCenterPosition

        public void setCenterPosition​(org.eclipse.swt.graphics.Point mapPosition)
        Sets the position of the center of this GeoMap, without any panning effect.
        Parameters:
        mapPosition - the new position
      • getCursorPosition

        public org.eclipse.swt.graphics.Point getCursorPosition()
        Returns the map position of the mouse cursor.
        Returns:
        the map position of the mouse cursor
      • computeSize

        public org.eclipse.swt.graphics.Point computeSize​(int wHint,
                                                          int hHint,
                                                          boolean changed)
        Overrides:
        computeSize in class org.eclipse.swt.widgets.Control
      • computeSize

        public org.eclipse.swt.graphics.Point computeSize​(int wHint,
                                                          int hHint)
        Overrides:
        computeSize in class org.eclipse.swt.widgets.Control