Class MapView
- All Implemented Interfaces:
MapSurface, Animation, Editable, StyleListener, Iterable<Component>
A pure-vector map component: it renders entirely through the Codename One
Graphics API (the built-in VectorMapEngine) and never embeds a native
peer, so it composes cleanly with the rest of the UI -- dialogs, lists and
overlays draw over it without the clipping limitations of a native view.
MapView works identically on every platform including the simulator and
the web. By default it shows the free, keyless OpenFreeMap vector
basemap (real OpenStreetMap data) so it renders real maps with zero
configuration and no API key; point it at any other
TileSource (a keyed MVT endpoint, a raster
source such as RasterTileSource.openStreetMap(),
or a bundled offline tileset) as needed. For a native-rendered map (Apple
MapKit, Google Maps, ...) use NativeMap, which falls back to this
component when no native provider is wired in.
-
Field Summary
Fields inherited from class Component
BASELINE, BOTTOM, BRB_CENTER_OFFSET, BRB_CONSTANT_ASCENT, BRB_CONSTANT_DESCENT, BRB_OTHER, CENTER, CROSSHAIR_CURSOR, DEFAULT_CURSOR, DRAG_REGION_IMMEDIATELY_DRAG_X, DRAG_REGION_IMMEDIATELY_DRAG_XY, DRAG_REGION_IMMEDIATELY_DRAG_Y, DRAG_REGION_LIKELY_DRAG_X, DRAG_REGION_LIKELY_DRAG_XY, DRAG_REGION_LIKELY_DRAG_Y, DRAG_REGION_NOT_DRAGGABLE, DRAG_REGION_POSSIBLE_DRAG_X, DRAG_REGION_POSSIBLE_DRAG_XY, DRAG_REGION_POSSIBLE_DRAG_Y, E_RESIZE_CURSOR, HAND_CURSOR, LEFT, MOVE_CURSOR, N_RESIZE_CURSOR, NE_RESIZE_CURSOR, NW_RESIZE_CURSOR, RIGHT, S_RESIZE_CURSOR, SE_RESIZE_CURSOR, SW_RESIZE_CURSOR, TEXT_CURSOR, TOP, W_RESIZE_CURSOR, WAIT_CURSOR -
Constructor Summary
ConstructorsConstructorDescriptionMapView()Creates a map showing the free, keyless OpenFreeMap vector basemap (real OpenStreetMap data) centered on the equator at a low zoom.MapView(TileSource source) Creates a map backed bysourcewith the default light style.MapView(TileSource source, MapStyle style) Creates a map backed bysourceand styled bystyle(the style is only consulted for vector sources). -
Method Summary
Modifier and TypeMethodDescriptionvoidRegisters a camera-change listener.Adds a circle and returns it for chaining.voidRegisters a long-press listener.addMarker(MarkerOptions options) Adds a marker described byoptionsand returns its live handle.addPolygon(Polygon polygon) Adds a polygon and returns it for chaining.addPolyline(Polyline polyline) Adds a polyline and returns it for chaining.voidRegisters a tap listener.This surface as a Codename OneComponentfor layout purposes.protected DimensionCalculates the preferred size based on component content.voidRemoves every marker, polyline, polygon and circle.voidMoves and zooms the camera soboundsfits within the viewport, inset bypaddingPixelson every edge.The current camera position (target, zoom, bearing, tilt).The geographic coordinate at the center of the viewport.The underlying vector engine, for advanced configuration (tile cache, source and style swapping).doubleThe largest zoom level the backend permits.doubleThe smallest zoom level the backend permits.The geographic bounds currently visible, ornullbefore layout.doublegetZoom()The current zoom level.booleanTrue when a native provider currently backs this surface; false for a pure-vector map or aNativeMapthat fell back to the vector engine.latLngToScreen(LatLng coord) Converts a geographic coordinate to a pixel relative to this component.voidlongPointerPress(int x, int y) If this Component is focused this method is invoked when the user presses and holds the pointer on the ComponentvoidmoveCamera(LatLng target, double zoom) Convenience to recenter attargetand setzoomin one call.protected voidThis method paints the Component background, it should be overriden by subclasses to perform custom background drawing.protected booleanpinch(float scale) Invoked by subclasses interested in handling pinch to zoom events, if true is returned other drag events will not be broadcastvoidpointerDragged(int x, int y) If this Component is focused, the pointer dragged event will call this methodvoidpointerPressed(int x, int y) If this Component is focused, the pointer pressed event will call this methodvoidpointerReleased(int x, int y) If this Component is focused, the pointer released event will call this methodvoidUnregisters a camera-change listener.voidremoveCircle(Circle circle) Removes a previously added circle.voidUnregisters a long-press listener.voidremoveMarker(Marker marker) Removes a previously added marker.voidremovePolygon(Polygon polygon) Removes a previously added polygon.voidremovePolyline(Polyline polyline) Removes a previously added polyline.voidUnregisters a tap listener.screenToLatLng(int x, int y) Converts a pixel relative to this component to a geographic coordinate.voidsetCameraPosition(CameraPosition position) Moves the camera toposition, animating where the backend supports it.voidRecenters the viewport atcenter, keeping the current zoom.Replaces the style.setTileSource(TileSource source) Replaces the tile source.voidsetZoom(double zoom) Sets the zoom level, keeping the current center.Methods inherited from class Container
add, add, add, add, add, add, addAll, addComponent, addComponent, addComponent, addComponent, animateHierarchy, animateHierarchyAndWait, animateHierarchyFade, animateHierarchyFadeAndWait, animateLayout, animateLayoutAndWait, animateLayoutFade, animateLayoutFadeAndWait, animateUnlayout, animateUnlayoutAndWait, applyRTL, cancelRepaints, clearClientProperties, constrainHeightWhenScrollable, constrainWidthWhenScrollable, contains, createAnimateHierarchy, createAnimateHierarchyFade, createAnimateLayout, createAnimateLayoutFade, createAnimateLayoutFadeAndWait, createAnimateMotion, createAnimateUnlayout, createReplaceTransition, dragInitiated, drop, encloseIn, encloseIn, findDropTargetAt, findFirstFocusable, fireClicked, flushReplace, forceRevalidate, getBottomGap, getChildrenAsList, getClosestComponentTo, getComponentAt, getComponentAt, getComponentCount, getComponentIndex, getGridPosX, getGridPosY, getLayout, getLayoutHeight, getLayoutWidth, getLeadComponent, getLeadParent, getResponderAt, getSafeAreaRoot, getScrollIncrement, getSideGap, getUIManager, initLaf, invalidate, isEnabled, isSafeArea, isSafeAreaRoot, isScrollableX, isScrollableY, isSelectableInteraction, isSurface, iterator, iterator, keyPressed, keyReleased, layoutContainer, morph, morphAndWait, paint, paintComponentBackground, paintGlass, paramString, refreshTheme, removeAll, removeComponent, replace, replace, replaceAndWait, replaceAndWait, replaceAndWait, revalidate, revalidateLater, revalidateWithAnimationSafety, scrollComponentToVisible, setCellRenderer, setEnabled, setLayout, setLeadComponent, setSafeArea, setSafeAreaRoot, setScrollable, setScrollableX, setScrollableY, setScrollIncrement, setShouldCalcPreferredSize, setShouldLayout, setUIManager, updateTabIndicesMethods inherited from class Component
addDragFinishedListener, addDragOverListener, addDropListener, addFocusListener, addLongPressListener, addPointerDraggedListener, addPointerPressedListener, addPointerReleasedListener, addPullToRefresh, addScrollListener, addStateChangeListener, animate, announceForAccessibility, bindProperty, blocksSideSwipe, calcScrollSize, contains, containsOrOwns, createStyleAnimation, deinitialize, deinitializeCustomStyle, dragEnter, dragExit, dragFinished, draggingOver, drawDraggedImage, focusGained, focusLost, getAbsoluteX, getAbsoluteY, getAccessibilityText, getAllStyles, getAnimationManager, getBaseline, getBaselineResizeBehavior, getBindablePropertyNames, getBindablePropertyTypes, getBorder, getBoundPropertyValue, getBounds, getBounds, getClientProperty, getCloudBoundProperty, getCloudDestinationProperty, getComponentForm, getComponentState, getCursor, getDefaultDragTransparency, getDirtyRegion, getDisabledStyle, getDraggedx, getDraggedy, getDragImage, getDragRegionStatus, getDragSpeed, getDragTransparency, getEditingDelegate, getHeight, getInlineAllStyles, getInlineDisabledStyles, getInlinePressedStyles, getInlineSelectedStyles, getInlineStylesTheme, getInlineUnselectedStyles, getInnerHeight, getInnerPreferredH, getInnerPreferredW, getInnerWidth, getInnerX, getInnerY, getLabelForComponent, getName, getNativeOverlay, getNextFocusDown, getNextFocusLeft, getNextFocusRight, getNextFocusUp, getOuterHeight, getOuterPreferredH, getOuterPreferredW, getOuterWidth, getOuterX, getOuterY, getOwner, getParent, getPreferredH, getPreferredSize, getPreferredSizeStr, getPreferredTabIndex, getPreferredW, getPressedStyle, getPropertyNames, getPropertyTypeNames, getPropertyTypes, getPropertyValue, getSameHeight, getSameWidth, getScrollable, getScrollAnimationSpeed, getScrollDimension, getScrollOpacity, getScrollOpacityChangeSpeed, getScrollX, getScrollY, getSelectCommandText, getSelectedRect, getSelectedStyle, getStyle, getTabIndex, getTensileLength, getTextSelectionSupport, getTooltip, getUIID, getUnselectedStyle, getVisibleBounds, getVisibleBounds, getWidth, getX, getY, growShrink, handlesInput, hasFixedPreferredSize, hasFocus, hideNativeOverlay, initComponent, initCustomStyle, initDisabledStyle, initPressedStyle, initSelectedStyle, initUnselectedStyle, installDefaultPainter, isAlwaysTensile, isBlockLead, isCellRenderer, isChildOf, isDragActivated, isDragAndDropOperation, isDraggable, isDragRegion, isDropTarget, isEditable, isEditing, isFlatten, isFocusable, isGrabsPointerEvents, isHidden, isHidden, isHideInLandscape, isHideInPortrait, isHScrollThumbGrabbed, isHScrollThumbHover, isIgnorePointerEvents, isInClippingRegion, isInitialized, isOpaque, isOwnedBy, isPinchBlocksDragAndDrop, isRippleEffect, isRTL, isScrollable, isScrollVisible, isSetCursorSupported, isSmoothScrolling, isSnapToGrid, isStickyDrag, isTactileTouch, isTactileTouch, isTensileDragEnabled, isTraversable, isVisible, isVScrollThumbGrabbed, isVScrollThumbHover, keyRepeated, laidOut, longKeyPress, onScrollX, onScrollY, onSetFocusable, paintBackgrounds, paintBorder, paintBorderBackground, paintComponent, paintComponent, paintIntersectingComponentsAbove, paintLock, paintLockRelease, paintRippleOverlay, paintScrollbars, paintScrollbarX, paintScrollbarY, paintShadows, parsePreferredSize, pinch, pinchReleased, pointerDragged, pointerHover, pointerHoverPressed, pointerHoverReleased, pointerPressed, pointerReleased, putClientProperty, refreshTheme, refreshTheme, remove, removeDragFinishedListener, removeDragOverListener, removeDropListener, removeFocusListener, removeLongPressListener, removePointerDraggedListener, removePointerPressedListener, removePointerReleasedListener, removeScrollListener, removeStateChangeListener, repaint, repaint, requestFocus, resetFocusable, respondsToPointerEvents, scrollRectToVisible, scrollRectToVisible, setAccessibilityText, setAlwaysTensile, setBlockLead, setBoundPropertyValue, setCloudBoundProperty, setCloudDestinationProperty, setComponentState, setCursor, setDefaultDragTransparency, setDirtyRegion, setDisabledStyle, setDraggable, setDragTransparency, setDropTarget, setEditingDelegate, setFlatten, setFocus, setFocusable, setGrabsPointerEvents, setHandlesInput, setHeight, setHidden, setHidden, setHideInLandscape, setHideInPortrait, setHorizontalScrollBounds, setIgnorePointerEvents, setInitialized, setInlineAllStyles, setInlineDisabledStyles, setInlinePressedStyles, setInlineSelectedStyles, setInlineStylesTheme, setInlineUnselectedStyles, setIsScrollVisible, setLabelForComponent, setName, setNextFocusDown, setNextFocusLeft, setNextFocusRight, setNextFocusUp, setOpaque, setOwner, setPinchBlocksDragAndDrop, setPreferredH, setPreferredSize, setPreferredSizeStr, setPreferredTabIndex, setPreferredW, setPressedStyle, setPropertyValue, setPullToRefresh, setRippleEffect, setRTL, setSameHeight, setSameSize, setSameWidth, setScrollAnimationSpeed, setScrollOpacityChangeSpeed, setScrollSize, setScrollVisible, setScrollX, setScrollY, setSelectCommandText, setSelectedStyle, setSize, setSmoothScrolling, setSnapToGrid, setTabIndex, setTactileTouch, setTensileDragEnabled, setTensileLength, setTooltip, setTraversable, setUIID, setUIID, setUIIDFinal, setUnselectedStyle, setVerticalScrollBounds, setVisible, setWidth, setX, setY, shouldBlockSideSwipe, shouldBlockSideSwipeLeft, shouldBlockSideSwipeRight, shouldRenderComponentSelection, showNativeOverlay, startEditingAsync, stopEditing, stripMarginAndPadding, styleChanged, toImage, toString, unbindProperty, updateNativeOverlay, visibleBoundsContains
-
Constructor Details
-
MapView
public MapView()Creates a map showing the free, keyless OpenFreeMap vector basemap (real OpenStreetMap data) centered on the equator at a low zoom. -
MapView
Creates a map backed bysourcewith the default light style. -
MapView
Creates a map backed bysourceand styled bystyle(the style is only consulted for vector sources).
-
-
Method Details
-
getEngine
The underlying vector engine, for advanced configuration (tile cache, source and style swapping). -
setTileSource
Replaces the tile source. -
setStyle
-
getCameraPosition
The current camera position (target, zoom, bearing, tilt).- Specified by:
getCameraPositionin interfaceMapSurface
-
setCameraPosition
Moves the camera toposition, animating where the backend supports it.- Specified by:
setCameraPositionin interfaceMapSurface
-
moveCamera
Convenience to recenter attargetand setzoomin one call.- Specified by:
moveCamerain interfaceMapSurface
-
getZoom
-
setZoom
public void setZoom(double zoom) Sets the zoom level, keeping the current center.- Specified by:
setZoomin interfaceMapSurface
-
getMinZoom
public double getMinZoom()The smallest zoom level the backend permits.- Specified by:
getMinZoomin interfaceMapSurface
-
getMaxZoom
public double getMaxZoom()The largest zoom level the backend permits.- Specified by:
getMaxZoomin interfaceMapSurface
-
getCenter
The geographic coordinate at the center of the viewport.- Specified by:
getCenterin interfaceMapSurface
-
setCenter
Recenters the viewport atcenter, keeping the current zoom.- Specified by:
setCenterin interfaceMapSurface
-
getVisibleRegion
The geographic bounds currently visible, ornullbefore layout. (NamedgetVisibleRegionto avoid clashing withComponent.getVisibleBounds(), which returns a pixel rectangle.)- Specified by:
getVisibleRegionin interfaceMapSurface
-
fitBounds
Moves and zooms the camera soboundsfits within the viewport, inset bypaddingPixelson every edge.- Specified by:
fitBoundsin interfaceMapSurface
-
addMarker
Adds a marker described byoptionsand returns its live handle.- Specified by:
addMarkerin interfaceMapSurface
-
removeMarker
Removes a previously added marker.- Specified by:
removeMarkerin interfaceMapSurface
-
addPolyline
Adds a polyline and returns it for chaining.- Specified by:
addPolylinein interfaceMapSurface
-
removePolyline
Removes a previously added polyline.- Specified by:
removePolylinein interfaceMapSurface
-
addPolygon
Adds a polygon and returns it for chaining.- Specified by:
addPolygonin interfaceMapSurface
-
removePolygon
Removes a previously added polygon.- Specified by:
removePolygonin interfaceMapSurface
-
addCircle
Adds a circle and returns it for chaining.- Specified by:
addCirclein interfaceMapSurface
-
removeCircle
Removes a previously added circle.- Specified by:
removeCirclein interfaceMapSurface
-
clearMapObjects
public void clearMapObjects()Removes every marker, polyline, polygon and circle.- Specified by:
clearMapObjectsin interfaceMapSurface
-
latLngToScreen
Converts a geographic coordinate to a pixel relative to this component.- Specified by:
latLngToScreenin interfaceMapSurface
-
screenToLatLng
Converts a pixel relative to this component to a geographic coordinate.- Specified by:
screenToLatLngin interfaceMapSurface
-
addTapListener
Registers a tap listener.- Specified by:
addTapListenerin interfaceMapSurface
-
removeTapListener
Unregisters a tap listener.- Specified by:
removeTapListenerin interfaceMapSurface
-
addLongPressListener
Registers a long-press listener.- Specified by:
addLongPressListenerin interfaceMapSurface
-
removeLongPressListener
Unregisters a long-press listener.- Specified by:
removeLongPressListenerin interfaceMapSurface
-
addCameraChangeListener
Registers a camera-change listener.- Specified by:
addCameraChangeListenerin interfaceMapSurface
-
removeCameraChangeListener
Unregisters a camera-change listener.- Specified by:
removeCameraChangeListenerin interfaceMapSurface
-
isNativeMap
public boolean isNativeMap()True when a native provider currently backs this surface; false for a pure-vector map or aNativeMapthat fell back to the vector engine.- Specified by:
isNativeMapin interfaceMapSurface
-
asComponent
This surface as a Codename OneComponentfor layout purposes.- Specified by:
asComponentin interfaceMapSurface
-
paintBackground
Description copied from class:ComponentThis method paints the Component background, it should be overriden by subclasses to perform custom background drawing.
Parameters
g: the component graphics
- Overrides:
paintBackgroundin classComponent
-
pointerPressed
public void pointerPressed(int x, int y) If this Component is focused, the pointer pressed event will call this method
Parameters
-
x: the pointer x coordinate -
y: the pointer y coordinate
- Overrides:
pointerPressedin classContainer
-
-
pointerDragged
public void pointerDragged(int x, int y) If this Component is focused, the pointer dragged event will call this method
Parameters
-
x: the pointer x coordinate -
y: the pointer y coordinate
- Overrides:
pointerDraggedin classComponent
-
-
pointerReleased
public void pointerReleased(int x, int y) If this Component is focused, the pointer released event will call this method
Parameters
-
x: the pointer x coordinate -
y: the pointer y coordinate
- Overrides:
pointerReleasedin classComponent
-
-
longPointerPress
public void longPointerPress(int x, int y) If this Component is focused this method is invoked when the user presses and holds the pointer on the Component- Overrides:
longPointerPressin classComponent
-
pinch
protected boolean pinch(float scale) Description copied from class:ComponentInvoked by subclasses interested in handling pinch to zoom events, if true is returned other drag events will not be broadcast
Parameters
scale: @param scale the scaling of the pinch operation a number larger than 1 means scaling up and smaller than 1 means scaling down. It is recommended that code would threshold the number (so a change between 1.0 and 1.02 shouldn't necessarily trigger zoom). Notice that this number is relevant to current zoom levels and unaware of them so you should also enforce limits of maximum/minimum zoom levels.
Returns
false by default
-
calcPreferredSize
Description copied from class:ContainerCalculates the preferred size based on component content. This method is invoked lazily by getPreferred size.
Returns
the calculated preferred size based on component content
- Overrides:
calcPreferredSizein classContainer
-