Class GeoMap
- java.lang.Object
-
- org.eclipse.swt.widgets.Widget
-
- org.eclipse.swt.widgets.Control
-
- org.eclipse.swt.widgets.Scrollable
-
- org.eclipse.swt.widgets.Composite
-
- org.eclipse.swt.widgets.Canvas
-
- org.eclipse.nebula.widgets.geomap.internal.InternalGeoMap
-
- org.eclipse.nebula.widgets.geomap.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 size256*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$
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private class
GeoMap.MouseCoordsHandler
-
Field Summary
Fields Modifier and Type Field Description static java.lang.String
ABOUT_MSG
About message.private static int
DEFAULT_CACHE_SIZE
private DefaultMouseHandler
defaultMouseHandler
private java.util.List<GeoMapListener>
geoMapListeners
private org.eclipse.swt.graphics.Point
mouseCoords
-
Fields inherited from class org.eclipse.nebula.widgets.geomap.internal.InternalGeoMap
geoMapHelper
-
-
Constructor Summary
Constructors Constructor Description GeoMap(org.eclipse.swt.widgets.Composite parent, int style)
Creates a newGeoMap
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 newGeoMap
using the default size for its internal cache of tilesGeoMap(org.eclipse.swt.widgets.Composite parent, int style, org.eclipse.swt.graphics.Point mapPosition, int zoom, int cacheSize)
Creates a newGeoMap
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 levelvoid
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 levelvoid
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.nebula.widgets.geomap.internal.InternalGeoMap
addInternalGeoMapListener, getMapPosition, getMaxZoom, getZoom, removeInternalGeoMapListener, tileUpdated
-
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
-
-
-
-
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
-
defaultMouseHandler
private DefaultMouseHandler defaultMouseHandler
-
DEFAULT_CACHE_SIZE
private static final int DEFAULT_CACHE_SIZE
- See Also:
- Constant Field Values
-
geoMapListeners
private java.util.List<GeoMapListener> geoMapListeners
-
-
Constructor Detail
-
GeoMap
public GeoMap(org.eclipse.swt.widgets.Composite parent, int style)
Creates a newGeoMap
using the default size for its internal cache of tiles. The map is showing the position(275091, 180145
at zoom level11
. In other words this constructor is best used only in debugging scenarios.- Parameters:
parent
- SWT parentComposite
style
- SWT style as inCanvas
, 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 newGeoMap
using the default size for its internal cache of tiles- Parameters:
parent
- SWT parentComposite
style
- SWT style as inCanvas
, 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 newGeoMap
using the default size for its internal cache of tiles- Parameters:
parent
- SWT parentComposite
style
- SWT style as inCanvas
, since this class inherits from it. Double buffering is always enabed.mapPosition
- initial mapPosition.zoom
- initial map zoomcacheSize
- 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 interfaceGeoMapPositioned
- Overrides:
setMapPosition
in classInternalGeoMap
- Parameters:
x
- the x-coordinate of the positiony
- 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-directionty
- the relative distance in y-direction
-
setZoom
public void setZoom(int zoom)
Sets the zoom level, without any transition effect.- Specified by:
setZoom
in interfaceGeoMapPositioned
- Overrides:
setZoom
in classInternalGeoMap
- 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 classorg.eclipse.swt.widgets.Control
-
computeSize
public org.eclipse.swt.graphics.Point computeSize(int wHint, int hHint)
- Overrides:
computeSize
in classorg.eclipse.swt.widgets.Control
-
-