public class NativeMap

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

ImplementsAnimation, Editable, Iterable<Component>, MapSurface, StyleListener

A native-rendered map. When the build wired in a native provider (Apple MapKit, Google Maps, Bing, Huawei, … selected via the maps.provider build hint) and it is available on the device, NativeMap embeds that provider’s native view as a PeerComponent. Otherwise – on the simulator, on devices without the selected provider, or when no provider was wired in at all – it transparently falls back to an embedded pure-vector MapView. Either way it exposes the same MapSurface API, so application code is identical.

The public API never names a provider; which one (if any) backs a given build is decided entirely by build hints through MapProviderRegistry.

Constructors

public NativeMap()Creates a native map centered on the equator at a low zoom.
public NativeMap(LatLng center, double zoom)Creates a native map at the given initial camera.
public NativeMap(LatLng center, double zoom, TileSource fallbackSource, MapStyle fallbackStyle)Creates a native map at the given initial camera, specifying the tile source and style used by the pure-vector MapView when no native provider is available.

Methods

protected void initComponent()Allows subclasses to bind functionality that relies on fully initialized and “ready for action” component state
public void dispose()Releases the native or web view backing this map and detaches it.
public CameraPosition getCameraPosition()The current camera position (target, zoom, bearing, tilt).
public void setCameraPosition(CameraPosition position)Moves the camera to position, animating where the backend supports it.
public void moveCamera(LatLng target, double zoom)Convenience to recenter at target and set zoom in one call.
public double getZoom()The current zoom level.
public void setZoom(double zoom)Sets the zoom level, keeping the current center.
public double getMinZoom()The smallest zoom level the backend permits.
public double getMaxZoom()The largest zoom level the backend permits.
public LatLng getCenter()The geographic coordinate at the center of the viewport.
public void setCenter(LatLng center)Recenters the viewport at center, keeping the current zoom.
public MapBounds getVisibleRegion()The geographic bounds currently visible, or null before layout.
public void fitBounds(MapBounds bounds, int paddingPixels)Moves and zooms the camera so bounds fits within the viewport, inset by paddingPixels on every edge.
public Marker addMarker(MarkerOptions options)Adds a marker described by options and returns its live handle.
public void removeMarker(Marker marker)Removes a previously added marker.
public Polyline addPolyline(Polyline polyline)Adds a polyline and returns it for chaining.
public void removePolyline(Polyline polyline)Removes a previously added polyline.
public Polygon addPolygon(Polygon polygon)Adds a polygon and returns it for chaining.
public void removePolygon(Polygon polygon)Removes a previously added polygon.
public Circle addCircle(Circle circle)Adds a circle and returns it for chaining.
public void removeCircle(Circle circle)Removes a previously added circle.
public void clearMapObjects()Removes every marker, polyline, polygon and circle.
public Point latLngToScreen(LatLng coord)Converts a geographic coordinate to a pixel relative to this component.
public LatLng screenToLatLng(int x, int y)Converts a pixel relative to this component to a geographic coordinate.
public void addTapListener(MapTapListener l)Registers a tap listener.
public void removeTapListener(MapTapListener l)Unregisters a tap listener.
public void addLongPressListener(MapTapListener l)Registers a long-press listener.
public void removeLongPressListener(MapTapListener l)Unregisters a long-press listener.
public void addCameraChangeListener(CameraChangeListener l)Registers a camera-change listener.
public void removeCameraChangeListener(CameraChangeListener l)Unregisters a camera-change listener.
public boolean isNativeMap()True when a native provider currently backs this surface; false for a pure-vector map or a NativeMap that fell back to the vector engine.
public boolean isMapReady()Whether the native map has finished its initial render.
public boolean isLoadingTiles()Whether the vector engine still has tiles in flight for the current view.
public Component asComponent()This surface as a Codename One Component for layout purposes.
public static void fireTap(int mapId, int x, int y)Invoked from native code when the map is tapped.
public static void fireLongPress(int mapId, int x, int y)Invoked from native code when the map is long-pressed.
public static void fireMarkerClick(int mapId, long markerKey)Invoked from native code when a marker is tapped (markerKey is the value returned by MapProvider.addMarker).
public static void fireCameraChange(int mapId)Invoked from native code when the camera settles after movement.

Inherited fields

Inherited methods

From Container

encloseIn, encloseIn, initLaf, getUIManager, setUIManager, isSurface, add, addAll, add, add, add, add, add, getLeadComponent, setLeadComponent, getLeadParent, keyPressed, 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, pointerPressed, calcPreferredSize, 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, focusGained, focusLost, paintBackgrounds, paintShadows, getAbsoluteX, getAbsoluteY, isInClippingRegion, paintIntersectingComponentsAbove, paintScrollbars, paintScrollbarX, getScrollOpacity, getSelectedRect, paintScrollbarY, paintComponent, paintComponent, getBorder, getScrollable, paintBackground, 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, 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, pointerDragged, getDragImage, getDragTransparency, setDragTransparency, toImage, drawDraggedImage, draggingOver, dragEnter, dragExit, addPullToRefresh, setPullToRefresh, respondsToPointerEvents, pointerDragged, isStickyDrag, pointerPressed, isDragAndDropOperation, pointerReleased, longPointerPress, pointerReleased, 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, mouseWheel, 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, laidOut, deinitialize, isInitialized, setInitialized, styleChanged, getNextFocusDown, setNextFocusDown, getNextFocusUp, setNextFocusUp, getNextFocusLeft, setNextFocusLeft, getNextFocusRight, setNextFocusRight, getName, setName, initCustomStyle, deinitializeCustomStyle, isRTL, setRTL, isTactileTouch, isTactileTouch, setTactileTouch, getPropertyNames, getPropertyTypes, getPropertyTypeNames, getPropertyValue, setPropertyValue, paintLockRelease, paintLock, isSnapToGrid, setSnapToGrid, shouldBlockSideSwipe, 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

NativeMap

public NativeMap()
Creates a native map centered on the equator at a low zoom.

NativeMap

public NativeMap(LatLng center, double zoom)
Creates a native map at the given initial camera.

NativeMap

public NativeMap(LatLng center, double zoom, TileSource fallbackSource, MapStyle fallbackStyle)
Creates a native map at the given initial camera, specifying the tile source and style used by the pure-vector MapView when no native provider is available. Useful for an offline or branded fallback basemap (and for deterministic tests).

Method details

initComponent

protected void initComponent()
Allows subclasses to bind functionality that relies on fully initialized and “ready for action” component state

dispose

public void dispose()
Releases the native or web view backing this map and detaches it. Call this when you are finished with a NativeMap you will not show again so a provider that keeps a live view – in particular the web provider’s BrowserComponent, whose map JavaScript runs a continuous animation loop – stops consuming CPU/GPU in the background instead of being left running. After dispose() the map should not be reused.

getCameraPosition

public CameraPosition getCameraPosition()
The current camera position (target, zoom, bearing, tilt).

setCameraPosition

public void setCameraPosition(CameraPosition position)
Moves the camera to position, animating where the backend supports it.

moveCamera

public void moveCamera(LatLng target, double zoom)
Convenience to recenter at target and set zoom in one call.

getZoom

public double getZoom()
The current zoom level.

setZoom

public void setZoom(double zoom)
Sets the zoom level, keeping the current center.

getMinZoom

public double getMinZoom()
The smallest zoom level the backend permits.

getMaxZoom

public double getMaxZoom()
The largest zoom level the backend permits.

getCenter

public LatLng getCenter()
The geographic coordinate at the center of the viewport.

setCenter

public void setCenter(LatLng center)
Recenters the viewport at center, keeping the current zoom.

getVisibleRegion

public MapBounds getVisibleRegion()
The geographic bounds currently visible, or null before layout. (Named getVisibleRegion to avoid clashing with Component.getVisibleBounds(), which returns a pixel rectangle.)

fitBounds

public void fitBounds(MapBounds bounds, int paddingPixels)
Moves and zooms the camera so bounds fits within the viewport, inset by paddingPixels on every edge.

addMarker

public Marker addMarker(MarkerOptions options)
Adds a marker described by options and returns its live handle.

removeMarker

public void removeMarker(Marker marker)
Removes a previously added marker.

addPolyline

public Polyline addPolyline(Polyline polyline)
Adds a polyline and returns it for chaining.

removePolyline

public void removePolyline(Polyline polyline)
Removes a previously added polyline.

addPolygon

public Polygon addPolygon(Polygon polygon)
Adds a polygon and returns it for chaining.

removePolygon

public void removePolygon(Polygon polygon)
Removes a previously added polygon.

addCircle

public Circle addCircle(Circle circle)
Adds a circle and returns it for chaining.

removeCircle

public void removeCircle(Circle circle)
Removes a previously added circle.

clearMapObjects

public void clearMapObjects()
Removes every marker, polyline, polygon and circle.

latLngToScreen

public Point latLngToScreen(LatLng coord)
Converts a geographic coordinate to a pixel relative to this component.

screenToLatLng

public LatLng screenToLatLng(int x, int y)
Converts a pixel relative to this component to a geographic coordinate.

addTapListener

public void addTapListener(MapTapListener l)
Registers a tap listener.

removeTapListener

public void removeTapListener(MapTapListener l)
Unregisters a tap listener.

addLongPressListener

public void addLongPressListener(MapTapListener l)
Registers a long-press listener.

removeLongPressListener

public void removeLongPressListener(MapTapListener l)
Unregisters a long-press listener.

addCameraChangeListener

public void addCameraChangeListener(CameraChangeListener l)
Registers a camera-change listener.

removeCameraChangeListener

public void removeCameraChangeListener(CameraChangeListener l)
Unregisters a camera-change listener.

isNativeMap

public boolean isNativeMap()
True when a native provider currently backs this surface; false for a pure-vector map or a NativeMap that fell back to the vector engine.

isMapReady

public boolean isMapReady()
Whether the native map has finished its initial render. For the web provider this reflects the Google Maps tilesloaded event, so a caller (e.g. a screenshot test) can wait for the real map to paint instead of a fixed delay. Providers without an async-readiness signal report ready once their peer exists.

isLoadingTiles

public boolean isLoadingTiles()
Whether the vector engine still has tiles in flight for the current view. Useful to defer a screenshot (or hide a spinner) until the basemap has finished loading. Always false for a native-provider-backed surface, which loads its own tiles outside the engine’s knowledge. Delegates to the embedded vector map when this NativeMap fell back to it; a real native provider loads its own tiles, so false.

asComponent

public Component asComponent()
This surface as a Codename One Component for layout purposes.

fireTap

public static void fireTap(int mapId, int x, int y)
Invoked from native code when the map is tapped.

fireLongPress

public static void fireLongPress(int mapId, int x, int y)
Invoked from native code when the map is long-pressed.

fireMarkerClick

public static void fireMarkerClick(int mapId, long markerKey)
Invoked from native code when a marker is tapped (markerKey is the value returned by MapProvider.addMarker).

fireCameraChange

public static void fireCameraChange(int mapId)
Invoked from native code when the camera settles after movement.