Class NativeMap
java.lang.Object
com.codename1.ui.Component
com.codename1.ui.Container
com.codename1.maps.NativeMap
- All Implemented Interfaces:
MapSurface, Animation, Editable, StyleListener, Iterable<Component>
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.
-
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
ConstructorsConstructorDescriptionCreates a native map centered on the equator at a low zoom.Creates a native map at the given initial camera.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-vectorMapViewwhen no native provider is available. -
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.voidRemoves every marker, polyline, polygon and circle.static voidfireCameraChange(int mapId) Invoked from native code when the camera settles after movement.static voidfireLongPress(int mapId, int x, int y) Invoked from native code when the map is long-pressed.static voidfireMarkerClick(int mapId, long markerKey) Invoked from native code when a marker is tapped (markerKeyis the value returned byMapProvider.addMarker(int, byte[], double, double, String, String, float, float)).static voidfireTap(int mapId, int x, int y) Invoked from native code when the map is tapped.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.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.protected voidAllows subclasses to bind functionality that relies on fully initialized and "ready for action" component statebooleanTrue 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.voidmoveCamera(LatLng target, double zoom) Convenience to recenter attargetand setzoomin one call.voidUnregisters 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.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, calcPreferredSize, 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, pointerPressed, 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, 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, longPointerPress, onScrollX, onScrollY, onSetFocusable, paintBackground, paintBackgrounds, paintBorder, paintBorderBackground, paintComponent, paintComponent, paintIntersectingComponentsAbove, paintLock, paintLockRelease, paintRippleOverlay, paintScrollbars, paintScrollbarX, paintScrollbarY, paintShadows, parsePreferredSize, pinch, pinch, pinchReleased, pointerDragged, pointerDragged, pointerHover, pointerHoverPressed, pointerHoverReleased, pointerPressed, pointerReleased, 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
-
NativeMap
public NativeMap()Creates a native map centered on the equator at a low zoom. -
NativeMap
Creates a native map at the given initial camera. -
NativeMap
Creates a native map at the given initial camera, specifying the tile source and style used by the pure-vectorMapViewwhen 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- Overrides:
initComponentin classComponent
-
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
-
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 (markerKeyis the value returned byMapProvider.addMarker(int, byte[], double, double, String, String, float, float)). -
fireCameraChange
public static void fireCameraChange(int mapId) Invoked from native code when the camera settles after movement.
-