Class VectorMapEngine

java.lang.Object
com.codename1.maps.vector.VectorMapEngine

public final class VectorMapEngine extends Object

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.

  • Constructor Summary

    Constructors
    Constructor
    Description
    Creates an engine over source, styled by style.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    Drops all cached tiles (e.g. on low memory).
    void
    fitBounds(MapBounds bounds, int padding)
    Moves the camera so bounds fits the viewport inset by padding.
    The geographic coordinate at the center of the viewport.
    double
    The largest zoom level the tile source serves.
    double
    The smallest zoom level the tile source serves.
    The active tile source.
    The active style.
    The geographic bounds currently visible, or null before layout.
    double
    The current fractional zoom level.
    Geographic to component-relative pixel.
    void
    paint(Graphics g, int originX, int originY, int width, int height)
    Paints the basemap and labels into g, offset by originX,originY.
    void
    panPixels(double dx, double dy)
    Pans the camera by a pixel delta (used for drag gestures).
    screenToLatLng(int x, int y)
    Component-relative pixel to geographic.
    void
    setCenter(LatLng center)
    Recenters the camera at center, keeping the current zoom.
    void
    Sets the callback invoked (on the EDT) whenever a tile finishes loading and the map needs to repaint.
    void
    Replaces the tile source, clearing cached tiles.
    void
    Replaces the style, clearing rendered tiles so they redraw.
    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).
    void
    setZoom(double zoom)
    Sets the zoom level, clamped to the source's min/max.
    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).

    Methods inherited from class Object

    clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • VectorMapEngine

      public VectorMapEngine(TileSource source, MapStyle style)
      Creates an engine over source, styled by style.
  • Method Details

    • setRepaintCallback

      public void setRepaintCallback(Runnable r)
      Sets the callback invoked (on the EDT) whenever a tile finishes loading and the map needs to repaint.
    • setSource

      public void setSource(TileSource source)
      Replaces the tile source, clearing cached tiles.
    • getSource

      public TileSource getSource()
      The active tile source.
    • setStyle

      public void setStyle(MapStyle style)
      Replaces the style, clearing rendered tiles so they redraw.
    • getStyle

      public MapStyle getStyle()
      The active style.
    • setCenter

      public void setCenter(LatLng center)
      Recenters the camera at center, keeping the current zoom.
    • getCenter

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

      public void setZoom(double zoom)
      Sets the zoom level, clamped to the source's min/max.
    • getZoom

      public double getZoom()
      The current fractional zoom level.
    • getMinZoom

      public double getMinZoom()
      The smallest zoom level the tile source serves.
    • getMaxZoom

      public double getMaxZoom()
      The largest zoom level the tile source serves.
    • setViewport

      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).
    • latLngToScreen

      public Point latLngToScreen(LatLng coord)
      Geographic to component-relative pixel.
    • panPixels

      public void panPixels(double dx, double dy)
      Pans the camera by a pixel delta (used for drag gestures). A positive dx moves the map content to the right.
    • zoomAround

      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).
    • screenToLatLng

      public LatLng screenToLatLng(int x, int y)
      Component-relative pixel to geographic.
    • getVisibleBounds

      public MapBounds getVisibleBounds()
      The geographic bounds currently visible, or null before layout.
    • fitBounds

      public void fitBounds(MapBounds bounds, int padding)
      Moves the camera so 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.
    • clearCache

      public void clearCache()
      Drops all cached tiles (e.g. on low memory).