Client API. The Codename One framework your app is built on: this runs on the device, not in a backend.
public final class VectorMapEngine
- Object
- VectorMapEngine
The pure-Codename One map renderer behind MapView (and
the NativeMap fallback).
It maintains the camera (center + fractional zoom), pulls tiles from a
TileSource, rasterizes vector tiles once into 256px buffers (or decodes
raster tiles), caches them in an LRU TileCache, and on each paint blits
the visible buffers scaled to the fractional zoom and places labels with
the LabelEngine. All drawing uses the framework Graphics API – there
is no native peer.
A vector map zooms past the deepest level its source serves: beyond it the deepest tile’s geometry is drawn again for each smaller area on screen (“overzoom”), the way vector map renderers reach street level from data that stops at zoom 14.
Constructors
public VectorMapEngine(TileSource source, MapStyle style) | Creates an engine over source, styled by style. |
Methods
public void setRepaintCallback(Runnable r) | Sets the callback invoked (on the EDT) whenever a tile finishes loading and the map needs to repaint. |
public void setSource(TileSource source) | Replaces the tile source, clearing cached tiles. |
public TileSource getSource() | The active tile source. |
public void setStyle(MapStyle style) | Replaces the style, clearing rendered tiles so they redraw. |
public MapStyle getStyle() | The active style. |
public void setCenter(LatLng center) | Recenters the camera at center, keeping the current zoom. |
public LatLng getCenter() | The geographic coordinate at the center of the viewport. |
public void setZoom(double zoom) | Sets the zoom level, clamped to the source’s min/max. |
public double getZoom() | The current fractional zoom level. |
public double getMinZoom() | The smallest zoom level the tile source serves. |
public double getMaxZoom() | The largest zoom level the camera can reach. |
public void setViewport(int width, int height) | Sets the pixel size of the viewport (called by the host component on layout before painting and coordinate conversion). |
public void setPixelRatio(double ratio) | Sets the device pixel ratio: physical pixels per logical (256px) map pixel. |
public double getPixelRatio() | The current device pixel ratio (see setPixelRatio(double)). |
public boolean hasPendingTiles() | Whether any tile requested for the current view is still loading (i.e. the basemap is not yet fully rendered). |
public boolean hasRenderedVisibleTiles() | True when the currently visible tile set has been requested and every visible tile has finished loading/decoding/rendering into the tile cache. |
public Point latLngToScreen(LatLng coord) | Geographic to component-relative pixel. |
public void panPixels(double dx, double dy) | Pans the camera by a pixel delta (used for drag gestures). |
public void zoomAround(double newZoom, int sx, int sy) | Zooms to newZoom while keeping the geographic point currently under the component pixel sx,sy fixed (used for pinch and double-tap). |
public LatLng screenToLatLng(int x, int y) | Component-relative pixel to geographic. |
public MapBounds getVisibleBounds() | The geographic bounds currently visible, or null before layout. |
public void fitBounds(MapBounds bounds, int padding) | Moves the camera so bounds fits the viewport inset by padding. |
public void paint(Graphics g, int originX, int originY, int width, int height) | Paints the basemap and labels into g, offset by originX,originY. |
public void paintTiles(Graphics g, int originX, int originY, int width, int height) | Paints the basemap without its labels, and remembers the labels in view for the next paintLabels call. |
public void paintLabels(Graphics g) | Draws the labels of the basemap painted by the last paintTiles call. |
public void clearCache() | Drops all cached tiles (e.g. on low memory). |
Inherited methods
Constructor details
VectorMapEngine
public VectorMapEngine(TileSource source, MapStyle style)source, styled by style.Method details
setRepaintCallback
public void setRepaintCallback(Runnable r)setSource
public void setSource(TileSource source)getSource
public TileSource getSource()setStyle
public void setStyle(MapStyle style)getStyle
public MapStyle getStyle()setCenter
public void setCenter(LatLng center)center, keeping the current zoom.getCenter
public LatLng getCenter()setZoom
public void setZoom(double zoom)getZoom
public double getZoom()getMinZoom
public double getMinZoom()getMaxZoom
public double getMaxZoom()setViewport
public void setViewport(int width, int height)setPixelRatio
public void setPixelRatio(double ratio)getPixelRatio
public double getPixelRatio()setPixelRatio(double)).hasPendingTiles
public boolean hasPendingTiles()hasRenderedVisibleTiles
public boolean hasRenderedVisibleTiles()latLngToScreen
public Point latLngToScreen(LatLng coord)panPixels
public void panPixels(double dx, double dy)dx moves the map content to the right.zoomAround
public void zoomAround(double newZoom, int sx, int sy)newZoom while keeping the geographic point currently under
the component pixel sx,sy fixed (used for pinch and double-tap).screenToLatLng
public LatLng screenToLatLng(int x, int y)getVisibleBounds
public MapBounds getVisibleBounds()fitBounds
public void fitBounds(MapBounds bounds, int padding)bounds fits the viewport inset by padding.paint
public void paint(Graphics g, int originX, int originY, int width, int height)Paints the basemap and labels into g, offset by originX,originY.
The caller is responsible for clipping to the component bounds and for
drawing overlays (markers/shapes) afterwards.
This is paintTiles followed by paintLabels; call those two
instead to draw shapes such as a route between them, so the route
does not cover the street names, as on familiar street maps.
paintTiles
public void paintTiles(Graphics g, int originX, int originY, int width, int height)paintLabels call.paintLabels
public void paintLabels(Graphics g)paintTiles
call. Does nothing before one.clearCache
public void clearCache()