Interface MapProvider
- All Known Implementing Classes:
WebMapProvider
The service-provider interface a native map backend implements so the
core NativeMap component can drive it without knowing which provider
(Apple MapKit, Google Maps, Bing, Huawei, ...) is in use.
This is a plain interface, deliberately not a
com.codename1.system.NativeInterface: core neither ships nor references
any concrete implementation. When the developer selects a provider with
the maps.provider build hint, the build pushes a provider implementation
(carrying the platform-native methods) into the com.codename1.maps
package of the app and weaves in a call to
MapProviderRegistry.register(MapProvider). Absent that injection the
registry stays empty and NativeMap falls back to the pure-vector
MapView.
Every method is keyed by a mapId so a single provider implementation can
serve multiple NativeMap instances. Coordinate conversion uses a stateful
"calculate then read" idiom (calcScreenPosition(int, double, double) then getScreenX(int) /
getScreenY(int)) to avoid returning multiple values across the native
boundary. Native code reports user interaction back through the static
callbacks on NativeMap (fireTap, fireLongPress, fireMarkerClick,
fireCameraChange, fireMapReady).
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intMap type: hybrid imagery with labels.static final intMap type: satellite imagery.static final intMap type: standard street map.static final intMap type: terrain relief. -
Method Summary
Modifier and TypeMethodDescriptionlongaddCircle(int mapId, double lat, double lon, double radiusMeters, int fillColor, int strokeColor, int strokeWidth) Adds a geodesic circle and returns its element key.longaddMarker(int mapId, byte[] icon, double lat, double lon, String title, String snippet, float anchorU, float anchorV) Adds a marker.voidaddToPath(int mapId, long pathId, double lat, double lon) longbeginPath(int mapId) Starts accumulating a path; feed it withaddToPath(int, long, double, double).voidcalcLatLongPosition(int mapId, int x, int y) voidcalcScreenPosition(int mapId, double lat, double lon) createPeer(NativeMap host, int mapId) Creates the view for the map identified bymapId.voiddeinitialize(int mapId) Releases native resources formapIdwhen the map is no longer used.longfinishPolygon(int mapId, long pathId, int fillColor, int strokeColor, int strokeWidth) Finishes the path as a filled polygon and returns its element key.longfinishPolyline(int mapId, long pathId, int strokeColor, int strokeWidth) Finishes the path as a stroked polyline and returns its element key.getId()A stable identifier for this provider, e.g.doublegetLatitude(int mapId) doublegetLongitude(int mapId) floatgetMaxZoom(int mapId) floatgetMinZoom(int mapId) doublegetScreenLat(int mapId) doublegetScreenLon(int mapId) intgetScreenX(int mapId) intgetScreenY(int mapId) floatgetZoom(int mapId) booleanWhether this provider can render on the current device right now (e.g. Google checks that Play Services is present).voidremoveAllElements(int mapId) voidremoveElement(int mapId, long elementId) voidsetCamera(int mapId, double lat, double lon, float zoom, float bearing, float tilt) Moves the camera.voidsetMapType(int mapId, int type) voidsetRotateGestureEnabled(int mapId, boolean enabled) voidsetShowMyLocation(int mapId, boolean show)
-
Field Details
-
MAP_TYPE_STANDARD
static final int MAP_TYPE_STANDARDMap type: standard street map.- See Also:
-
MAP_TYPE_SATELLITE
static final int MAP_TYPE_SATELLITEMap type: satellite imagery.- See Also:
-
MAP_TYPE_HYBRID
static final int MAP_TYPE_HYBRIDMap type: hybrid imagery with labels.- See Also:
-
MAP_TYPE_TERRAIN
static final int MAP_TYPE_TERRAINMap type: terrain relief.- See Also:
-
-
Method Details
-
getId
String getId()A stable identifier for this provider, e.g."apple"or"google". -
isAvailable
boolean isAvailable()Whether this provider can render on the current device right now (e.g. Google checks that Play Services is present). When this returns falseNativeMapfalls back to the vector engine. -
createPeer
Creates the view for the map identified bymapId. Native providers return aPeerComponentwrapping the native map view; a web-SDK provider returns aBrowserComponent. Either way it is aComponenttheNativeMapadds to its layout. Returningnulltriggers the vector fallback. -
deinitialize
void deinitialize(int mapId) Releases native resources formapIdwhen the map is no longer used. -
setCamera
void setCamera(int mapId, double lat, double lon, float zoom, float bearing, float tilt) Moves the camera.bearingandtiltare in degrees; providers that do not support them ignore those arguments. -
getLatitude
double getLatitude(int mapId) -
getLongitude
double getLongitude(int mapId) -
getZoom
float getZoom(int mapId) -
getMaxZoom
float getMaxZoom(int mapId) -
getMinZoom
float getMinZoom(int mapId) -
addMarker
-
beginPath
long beginPath(int mapId) Starts accumulating a path; feed it withaddToPath(int, long, double, double). -
addToPath
void addToPath(int mapId, long pathId, double lat, double lon) -
finishPolyline
long finishPolyline(int mapId, long pathId, int strokeColor, int strokeWidth) Finishes the path as a stroked polyline and returns its element key. -
finishPolygon
long finishPolygon(int mapId, long pathId, int fillColor, int strokeColor, int strokeWidth) Finishes the path as a filled polygon and returns its element key. -
addCircle
long addCircle(int mapId, double lat, double lon, double radiusMeters, int fillColor, int strokeColor, int strokeWidth) Adds a geodesic circle and returns its element key. -
removeElement
void removeElement(int mapId, long elementId) -
removeAllElements
void removeAllElements(int mapId) -
calcScreenPosition
void calcScreenPosition(int mapId, double lat, double lon) -
getScreenX
int getScreenX(int mapId) -
getScreenY
int getScreenY(int mapId) -
calcLatLongPosition
void calcLatLongPosition(int mapId, int x, int y) -
getScreenLat
double getScreenLat(int mapId) -
getScreenLon
double getScreenLon(int mapId) -
setShowMyLocation
void setShowMyLocation(int mapId, boolean show) -
setRotateGestureEnabled
void setRotateGestureEnabled(int mapId, boolean enabled) -
setMapType
void setMapType(int mapId, int type)
-