public class MapComponent

  1. Object
  2. Component
  3. Container
  4. MapComponent

ImplementsAnimation, Editable, Iterable<Component>, StyleListener

Deprecated.
All communication with the map and layers should be done in WGS84, it takes care of coordinates transformation.

Constructors

public MapComponent()Empty constructor creates a map with OpenStreetMapProvider on the Last known Location of the LocationManager
public MapComponent(MapProvider provider)Constructor with a given provider
public MapComponent(MapProvider provider, Location centerPosition, int zoomLevel)Constructor
public MapComponent(MapProvider provider, Location centerPosition, int zoomLevel, boolean cacheEnabled)Constructor
public MapComponent(MapProvider provider, Coord centerPosition, int zoomLevel)Constructor
public MapComponent(MapProvider provider, Coord centerPosition, int zoomLevel, boolean cacheEnabled)Constructor

Methods

public static long distance(double latitude1, double longitude1, double latitude2, double longitude2)Returns the distance between 2 points in meters
public void paintBackground(Graphics g)This method paints the Component background, it should be overriden by subclasses to perform custom background drawing.
protected void laidOut()This is a callback method to inform the Component when it’s been laidout on the parent Container
protected boolean shouldBlockSideSwipe()A component that might need side swipe such as the slider could block it from being used for some other purpose when on top of said component.
protected Dimension calcPreferredSize()Calculates the preferred size based on component content.
protected void focusGained()Callback allowing a developer to track when the component gains focus
protected boolean mouseWheel(WheelEvent ev)Handles a scroll wheel or trackpad scroll over this component, before its listeners and before anything above it in the hierarchy.
public void pointerDragged(int x, int y)If this Component is focused, the pointer dragged event will call this method
public void pointerPressed(int x, int y)If this Component is focused, the pointer pressed event will call this method
public void pointerDragged(int[] x, int[] y)If this Component is focused, the pointer dragged event will call this method
protected void pointerTapped(int x, int y, int tapCount)
public void pointerReleased(int x, int y)If this Component is focused, the pointer released event will call this method
public Coord getCoordFromPosition(int x, int y)Gets the Coord location on the map from a x, y position.
public Point getPointFromCoord(Coord coord)Gets the screen coordinates of a specific Coord
public void keyPressed(int keyCode)If this Component is focused, the key pressed event will call this method
public void addLayer(Layer layer)Adds a layer to the map
public void addLayer(Layer layer, int minZoomLevel, int maxZoomLevel)Adds a layer to the map
public void removeLayer(Layer layer)Removes a Layer from the map
public void removeAllLayers()Removes all layers from the map
public int getLayersConut()Returns layers count
public Layer getLayerAt(int index)Returns Layer at index
public MapProvider getProvider()Gets the map provider
public void repaint()Repaint this Component, the repaint call causes a callback of the paint method on the event dispatch thread.
public void moveLeft()move the map 25% left
public void moveRight()move the map 25% right
public void moveUp()move the map 25% up
public void moveDown()move the map 25% down
public void zoomIn()zoom in the map one level if possible
public void zoomOut()zoom out the map one level if possible
public void zoomTo(BoundingBox boundingBox)Zoom the map the the giving bounding box
public void zoomTo(Coord coord, int zoomLevel)Zoom map to the center of the given coordinate with the given zoom level
public void zoomToLayers()zoom map to largest zoom while all Layers are contained
public Coord getCenter()Gets the center location of the map in WGS84 format.
public int getZoomLevel()Returns the current zoom level of the map.
public void setZoomLevel(int zoom)Sets the current zoom level of the map.
public int getMaxZoomLevel()Returns the max zoom level of the map
public int getMinZoomLevel()Returns the min zoom level of the map
public Coord center()Gets the center of the map.
protected boolean isLeftKey(int keyCode)Checks if key code is left keycode.
protected boolean isRightKey(int keyCode)Returns true if this is a right keycode
protected boolean isDownKey(int keyCode)Returns true if this is a down keycode
protected boolean isUpKey(int keyCode)Returns true if this is a up keycode
protected boolean isZoomInKey(int keyCode)Returns true if this is a zoom in keycode
protected boolean isZoomOutKey(int keyCode)Returns true if this is a zoom out keycode
protected boolean isZoomToLayersKey(int keyCode)Returns true if this is a zoom to layers keycode
public void addMapListener(MapListener listener)Adds a listener to map panning/zooming
public void removeMapListener(MapListener listener)Removes the map listener callback
public String[] getPropertyNames()A component may expose mutable property names for a UI designer to manipulate, this API is designed for usage internally by the GUI builder code
public Class[] getPropertyTypes()Matches the property names method (see that method for further details).
public Object getPropertyValue(String name)Returns the current value of the property name, this method is used by the GUI builder
public String setPropertyValue(String name, Object value)Sets a new value to the given property, returns an error message if failed and null if successful.

Inherited fields

Inherited methods

From Container

encloseIn, encloseIn, initLaf, getUIManager, setUIManager, isSurface, add, addAll, add, add, add, add, add, getLeadComponent, setLeadComponent, getLeadParent, keyReleased, getLayout, setLayout, invalidate, setShouldLayout, setShouldCalcPreferredSize, getLayoutWidth, getLayoutHeight, applyRTL, constrainWidthWhenScrollable, constrainHeightWhenScrollable, addComponent, addComponent, addComponent, addComponent, replaceAndWait, replaceAndWait, replace, replaceAndWait, replace, createReplaceTransition, isEnabled, setEnabled, removeComponent, cancelRepaints, flushReplace, removeAll, revalidateWithAnimationSafety, revalidate, revalidateLater, forceRevalidate, clearClientProperties, paint, paintGlass, layoutContainer, isSafeArea, setSafeArea, isSafeAreaRoot, getSafeAreaRoot, setSafeAreaRoot, getComponentCount, getComponentAt, getComponentIndex, contains, scrollComponentToVisible, getClosestComponentTo, getResponderAt, getComponentAt, findDropTargetAt, paramString, refreshTheme, isScrollableX, setScrollableX, isScrollableY, setScrollableY, getSideGap, getBottomGap, setScrollable, setCellRenderer, getScrollIncrement, setScrollIncrement, findFirstFocusable, dragInitiated, fireClicked, isSelectableInteraction, getGridPosY, paintComponentBackground, getGridPosX, animateHierarchyAndWait, createAnimateHierarchy, animateHierarchy, animateHierarchyFadeAndWait, createAnimateHierarchyFade, animateHierarchyFade, animateLayoutFadeAndWait, createAnimateLayoutFadeAndWait, animateLayoutFade, createAnimateLayoutFade, animateLayoutAndWait, animateLayout, updateTabIndices, createAnimateLayout, drop, createAnimateMotion, morph, morphAndWait, animateUnlayout, animateUnlayoutAndWait, createAnimateUnlayout, getChildrenAsList, iterator, iterator

From Component

setSameSize, isSetCursorSupported, parsePreferredSize, getDefaultDragTransparency, setDefaultDragTransparency, getEditingDelegate, setEditingDelegate, getCursor, setCursor, showNativeOverlay, hideNativeOverlay, updateNativeOverlay, getNativeOverlay, getAllStyles, getSameWidth, setSameWidth, getSameHeight, setSameHeight, getX, setX, getOuterX, getInnerX, getY, setY, getOuterY, getInnerY, isVisible, setVisible, getClientProperty, stripMarginAndPadding, putClientProperty, getDirtyRegion, setDirtyRegion, isOpaque, setOpaque, getWidth, setWidth, getOuterWidth, getInnerWidth, getHeight, setHeight, getOuterHeight, getInnerHeight, isDragRegion, getDragRegionStatus, getBaseline, getBaselineResizeBehavior, getPreferredSizeStr, setPreferredSizeStr, getPreferredSize, setPreferredSize, getScrollDimension, calcScrollSize, setScrollSize, getPreferredW, setPreferredW, getPreferredH, setPreferredH, getOuterPreferredH, getInnerPreferredH, getOuterPreferredW, getInnerPreferredW, setSize, getUIID, setUIID, setUIIDFinal, setUIID, getInlineAllStyles, setInlineAllStyles, getInlineSelectedStyles, setInlineSelectedStyles, getInlineUnselectedStyles, setInlineUnselectedStyles, getInlineDisabledStyles, setInlineDisabledStyles, getInlinePressedStyles, setInlinePressedStyles, remove, getParent, getOwner, setOwner, isOwnedBy, containsOrOwns, addFocusListener, removeFocusListener, addScrollListener, removeScrollListener, getSelectCommandText, setSelectCommandText, getLabelForComponent, setLabelForComponent, focusLost, paintBackgrounds, paintShadows, getAbsoluteX, getAbsoluteY, isInClippingRegion, paintIntersectingComponentsAbove, paintScrollbars, paintScrollbarX, getScrollOpacity, getSelectedRect, paintScrollbarY, paintComponent, paintComponent, getBorder, getScrollable, isScrollable, getScrollX, setScrollX, getScrollY, setScrollY, onScrollX, onScrollY, getDraggedx, getDraggedy, contains, visibleBoundsContains, hasFixedPreferredSize, getBounds, getBounds, getVisibleBounds, getVisibleBounds, isFocusable, setFocusable, onSetFocusable, resetFocusable, getTabIndex, setTabIndex, getPreferredTabIndex, setPreferredTabIndex, isTraversable, setTraversable, handlesInput, setHandlesInput, consumesRawTextInput, hasFocus, setFocus, getComponentForm, getTopLevelContainer, repaint, longKeyPress, keyRepeated, registerForAnimation, deregisterFromAnimation, getAnimationManager, getScrollAnimationSpeed, setScrollAnimationSpeed, isBlockLead, setBlockLead, isIgnorePointerEvents, setIgnorePointerEvents, isRippleEffect, setRippleEffect, getInlineStylesTheme, setInlineStylesTheme, shouldRenderComponentSelection, isHideInLandscape, setHideInLandscape, createStyleAnimation, isSmoothScrolling, setSmoothScrolling, pointerHover, stopScrollMomentum, pointerHoverReleased, pointerHoverPressed, pinch, pinchReleased, pinch, rotation, isPinchBlocksDragAndDrop, setPinchBlocksDragAndDrop, getDragImage, getDragTransparency, setDragTransparency, toImage, drawDraggedImage, draggingOver, dragEnter, dragExit, addPullToRefresh, setPullToRefresh, respondsToPointerEvents, isStickyDrag, pointerPressed, isDragAndDropOperation, pointerReleased, longPointerPress, setVerticalScrollBounds, setHorizontalScrollBounds, isVScrollThumbGrabbed, isHScrollThumbGrabbed, isVScrollThumbHover, isHScrollThumbHover, isTensileDragEnabled, setTensileDragEnabled, getTextSelectionSupport, addDropListener, removeDropListener, addDragOverListener, removeDragOverListener, isNativeDragSource, setNativeDragSource, getNativeDragOperation, setNativeDragOperation, createNativeDragOperation, isNativeDropTarget, setNativeDropTarget, getAcceptedDropMimeTypes, setAcceptedDropMimeTypes, getAcceptedDropActions, setAcceptedDropActions, canAcceptNativeDrop, nativeDragEnter, nativeDragOver, nativeDragExit, nativeDrop, addNativeDropListener, removeNativeDropListener, addNativeDragOverListener, removeNativeDragOverListener, dragFinished, addDragFinishedListener, addStateChangeListener, removeStateChangeListener, addPointerPressedListener, addLongPressListener, addContextMenuListener, removeContextMenuListener, addMouseWheelListener, removeMouseWheelListener, addStylusListener, removeStylusListener, paintRippleOverlay, removePointerPressedListener, removeLongPressListener, removeDragFinishedListener, addPointerReleasedListener, removePointerReleasedListener, addPointerDraggedListener, removePointerDraggedListener, getDragSpeed, getStyle, getPressedStyle, setPressedStyle, initUnselectedStyle, initPressedStyle, initDisabledStyle, initSelectedStyle, getUnselectedStyle, setUnselectedStyle, getSelectedStyle, setSelectedStyle, getDisabledStyle, setDisabledStyle, installDefaultPainter, requestFocus, toString, refreshTheme, refreshTheme, isDragActivated, animate, scrollRectToVisible, scrollRectToVisible, paintBorder, paintBorderBackground, isCellRenderer, isScrollVisible, setScrollVisible, setIsScrollVisible, startEditingAsync, stopEditing, isEditing, isEditable, deinitialize, initComponent, isInitialized, setInitialized, styleChanged, getNextFocusDown, setNextFocusDown, getNextFocusUp, setNextFocusUp, getNextFocusLeft, setNextFocusLeft, getNextFocusRight, setNextFocusRight, getName, setName, initCustomStyle, deinitializeCustomStyle, isRTL, setRTL, isTactileTouch, isTactileTouch, setTactileTouch, getPropertyTypeNames, paintLockRelease, paintLock, isSnapToGrid, setSnapToGrid, shouldBlockSideSwipeLeft, shouldBlockSideSwipeRight, blocksSideSwipe, isFlatten, setFlatten, getTensileLength, setTensileLength, isGrabsPointerEvents, setGrabsPointerEvents, getScrollOpacityChangeSpeed, setScrollOpacityChangeSpeed, growShrink, isAlwaysTensile, setAlwaysTensile, isDraggable, setDraggable, isDropTarget, setDropTarget, isChildOf, isHideInPortrait, setHideInPortrait, getBindablePropertyNames, getBindablePropertyTypes, bindProperty, unbindProperty, getBoundPropertyValue, setBoundPropertyValue, getCloudBoundProperty, setCloudBoundProperty, getCloudDestinationProperty, setCloudDestinationProperty, getComponentState, setComponentState, setHidden, isHidden, setHidden, isHidden, announceForAccessibility, getAccessibilityText, setAccessibilityText, getSemantics, getAccessibilityNode, accessibilityChanged, accessibilityChanged, getTooltip, setTooltip

Constructor details

MapComponent

public MapComponent()
Empty constructor creates a map with OpenStreetMapProvider on the Last known Location of the LocationManager

MapComponent

public MapComponent(MapProvider provider)
Constructor with a given provider

Parameters

provider MapProvider
map provider

MapComponent

public MapComponent(MapProvider provider, Location centerPosition, int zoomLevel)
Constructor

Parameters

provider MapProvider
map provider
centerPosition Location
center position
zoomLevel int
zoom level

MapComponent

public MapComponent(MapProvider provider, Location centerPosition, int zoomLevel, boolean cacheEnabled)
Constructor

Parameters

provider MapProvider
map provider
centerPosition Location
center position
zoomLevel int
zoom level
cacheEnabled boolean
is cache enabled

MapComponent

public MapComponent(MapProvider provider, Coord centerPosition, int zoomLevel)
Constructor

Parameters

provider MapProvider
map provider
centerPosition Coord
center position
zoomLevel int
zoom level

MapComponent

public MapComponent(MapProvider provider, Coord centerPosition, int zoomLevel, boolean cacheEnabled)
Constructor

Parameters

provider MapProvider
map provider
centerPosition Coord
center position
zoomLevel int
zoom level
cacheEnabled boolean
is cache enabled

Method details

distance

public static long distance(double latitude1, double longitude1, double latitude2, double longitude2)
Returns the distance between 2 points in meters

Returns

distance in meters

paintBackground

public void paintBackground(Graphics g)
This method paints the Component background, it should be overriden by subclasses to perform custom background drawing.

Parameters

g Graphics
the component graphics

laidOut

protected void laidOut()
This is a callback method to inform the Component when it’s been laidout on the parent Container

shouldBlockSideSwipe

protected boolean shouldBlockSideSwipe()
A component that might need side swipe such as the slider could block it from being used for some other purpose when on top of said component.

calcPreferredSize

protected Dimension calcPreferredSize()
Calculates the preferred size based on component content. This method is invoked lazily by getPreferred size.

Returns

the calculated preferred size based on component content

focusGained

protected void focusGained()
Callback allowing a developer to track when the component gains focus

mouseWheel

protected boolean mouseWheel(WheelEvent ev)

Handles a scroll wheel or trackpad scroll over this component, before its listeners and before anything above it in the hierarchy.

A component that moves its own content – an editor that scrolls itself, a viewer that pans – implements this. Everything else leaves it alone and the wheel scrolls the nearest scrollable ancestor, which is what a wheel means.

This exists because a wheel used to arrive as a synthetic press, drag and release played into the component tree: a component that wanted the wheel got it by handling pointer events, and so did every component that did not want it. The events are gone and this is what replaces them, for the few components that have something of their own to move.

Parameters

ev WheelEvent
the wheel event, carrying the scroll deltas in display pixels

Returns

true when this component handled the wheel and nothing else should act on it

pointerDragged

public void pointerDragged(int x, int y)
If this Component is focused, the pointer dragged event will call this method

Parameters

x int
the pointer x coordinate
y int
the pointer y coordinate

pointerPressed

public void pointerPressed(int x, int y)
If this Component is focused, the pointer pressed event will call this method

Parameters

x int
the pointer x coordinate
y int
the pointer y coordinate

pointerDragged

public void pointerDragged(int[] x, int[] y)
If this Component is focused, the pointer dragged event will call this method

Parameters

x int[]
the pointer x coordinate
y int[]
the pointer y coordinate

pointerTapped

protected void pointerTapped(int x, int y, int tapCount)

pointerReleased

public void pointerReleased(int x, int y)
If this Component is focused, the pointer released event will call this method

Parameters

x int
the pointer x coordinate
y int
the pointer y coordinate

getCoordFromPosition

public Coord getCoordFromPosition(int x, int y)
Gets the Coord location on the map from a x, y position.

Parameters

x int
X-coordinate
y int
Y-coordinate

Returns

a Coord Object.

getPointFromCoord

public Point getPointFromCoord(Coord coord)
Gets the screen coordinates of a specific Coord

Parameters

coord Coord
a lat,lon location

Returns

the Point of the coordinate on the Map

keyPressed

public void keyPressed(int keyCode)
If this Component is focused, the key pressed event will call this method

Parameters

keyCode int
the key code value to indicate a physical key.

addLayer

public void addLayer(Layer layer)
Adds a layer to the map

Parameters

layer Layer
to add

addLayer

public void addLayer(Layer layer, int minZoomLevel, int maxZoomLevel)
Adds a layer to the map

Parameters

layer Layer
to add
minZoomLevel int
min zoom level of this Layer
maxZoomLevel int
max zoom level of this Layer

removeLayer

public void removeLayer(Layer layer)
Removes a Layer from the map

Parameters

layer Layer
to remove

removeAllLayers

public void removeAllLayers()
Removes all layers from the map

getLayersConut

public int getLayersConut()
Returns layers count

Returns

The number of layers.

getLayerAt

public Layer getLayerAt(int index)
Returns Layer at index

Parameters

index int
the index of the layer

Returns

The layer at the given index.

Throws

ArrayIndexOutOfBoundsException
if the index is out of range (index < 0 || index >= size())

getProvider

public MapProvider getProvider()
Gets the map provider

Returns

the map provider

repaint

public void repaint()
Repaint this Component, the repaint call causes a callback of the paint method on the event dispatch thread.

See also

moveLeft

public void moveLeft()
move the map 25% left

moveRight

public void moveRight()
move the map 25% right

moveUp

public void moveUp()
move the map 25% up

moveDown

public void moveDown()
move the map 25% down

zoomIn

public void zoomIn()
zoom in the map one level if possible

zoomOut

public void zoomOut()
zoom out the map one level if possible

zoomTo

public void zoomTo(BoundingBox boundingBox)
Zoom the map the the giving bounding box

Parameters

boundingBox BoundingBox
to zoom to

Throws

IllegalArgumentException
if the boundingBox is not wg84 format

zoomTo

public void zoomTo(Coord coord, int zoomLevel)
Zoom map to the center of the given coordinate with the given zoom level

Parameters

coord Coord
center map to this coordinate, coord should be in wg84 format
zoomLevel int
zoom map to this level;

Throws

IllegalArgumentException
if the coord is not wg84 format

zoomToLayers

public void zoomToLayers()
zoom map to largest zoom while all Layers are contained

getCenter

public Coord getCenter()
Gets the center location of the map in WGS84 format.

Returns

Coordinate of center location of map.

getZoomLevel

public int getZoomLevel()
Returns the current zoom level of the map.

Returns

zoom level

setZoomLevel

public void setZoomLevel(int zoom)
Sets the current zoom level of the map.

Parameters

zoom int
Zoom level

getMaxZoomLevel

public int getMaxZoomLevel()
Returns the max zoom level of the map

Returns

max zoom level

getMinZoomLevel

public int getMinZoomLevel()
Returns the min zoom level of the map

Returns

min zoom level

center

public Coord center()
Gets the center of the map.

Returns

Coord in WGS84

isLeftKey

protected boolean isLeftKey(int keyCode)
Checks if key code is left keycode.

Parameters

keyCode int
The key-code to check.

Returns

true if this is a left keycode

isRightKey

protected boolean isRightKey(int keyCode)
Returns true if this is a right keycode

Parameters

keyCode int
The key code to check

Returns

true if this is a right keycode.

isDownKey

protected boolean isDownKey(int keyCode)
Returns true if this is a down keycode

Parameters

keyCode int
The key code to check.

Returns

True if key code is down key.

isUpKey

protected boolean isUpKey(int keyCode)
Returns true if this is a up keycode

Parameters

keyCode int
The key code to check.

Returns

true if key code is up key.

isZoomInKey

protected boolean isZoomInKey(int keyCode)
Returns true if this is a zoom in keycode

Parameters

keyCode int
The key code to check

Returns

true if key code is zoom-in key.

isZoomOutKey

protected boolean isZoomOutKey(int keyCode)
Returns true if this is a zoom out keycode

Parameters

keyCode int
The key code to check.

Returns

true if the key code for the zoom-out key.

isZoomToLayersKey

protected boolean isZoomToLayersKey(int keyCode)
Returns true if this is a zoom to layers keycode

Parameters

keyCode int
The key-code to check.

Returns

true if the key code is for the zoom to layers key.

addMapListener

public void addMapListener(MapListener listener)
Adds a listener to map panning/zooming

Parameters

listener MapListener
the listener callback

removeMapListener

public void removeMapListener(MapListener listener)
Removes the map listener callback

Parameters

listener MapListener
the listener

getPropertyNames

public String[] getPropertyNames()
A component may expose mutable property names for a UI designer to manipulate, this API is designed for usage internally by the GUI builder code

Returns

the property names allowing mutation

getPropertyTypes

public Class[] getPropertyTypes()
Matches the property names method (see that method for further details).

Returns

the types of the properties

getPropertyValue

public Object getPropertyValue(String name)
Returns the current value of the property name, this method is used by the GUI builder

Parameters

name String
the name of the property

Returns

the value of said property

setPropertyValue

public String setPropertyValue(String name, Object value)
Sets a new value to the given property, returns an error message if failed and null if successful. Notice that some builtin properties such as “$designMode” might be sent to components to indicate application state.

Parameters

name String
the name of the property
value Object
new value for the property

Returns

error message or null