# Class WebMapProvider

java.lang.Object
com.codename1.maps.WebMapProvider

All Implemented Interfaces:
  `MapProvider`

public class WebMapProvider extends Object implements MapProvider

A cross-platform `MapProvider` that hosts a JavaScript map SDK (Google Maps JS, Azure Maps, ...) inside a `BrowserComponent`. Because it relies only on a web view it renders on every platform that has a browser, which makes it the natural `"web"` entry in a provider fallback chain and the only way to surface SDKs that ship no native component (e.g. Azure Maps).

The map's initial camera comes from the host `NativeMap` (its center/zoom), baked straight into the page so the map opens on the right region without a follow-up call. Use `google(String)` for a ready-made Google Maps page, or the constructor with a custom HTML template containing the tokens `{key}`, `{lat}`, `{lon}` and `{zoom}`.

- ## Field Summary

  ### Fields inherited from interface MapProvider

  `MAP_TYPE_HYBRID, MAP_TYPE_SATELLITE, MAP_TYPE_STANDARD, MAP_TYPE_TERRAIN`

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `WebMapProvider(String id, String apiKey, String htmlTemplate)`
  Creates a web provider.

- ## Method Summary

  Modifier and Type
  Method
  Description
  `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.
  `long`
  `addMarker(int mapId, byte[] icon, double lat, double lon, String title, String snippet, float anchorU, float anchorV)`
  Adds a marker.
  `void`
  `addToPath(int mapId, long pathId, double lat, double lon)`
  `long`
  `beginPath(int mapId)`
  Starts accumulating a path; feed it with `MapProvider.addToPath(int, long, double, double)`.
  `void`
  `calcLatLongPosition(int mapId, int x, int y)`
  `void`
  `calcScreenPosition(int mapId, double lat, double lon)`
  `Component`
  `createPeer(NativeMap host, int mapId)`
  Creates the view for the map identified by `mapId`.
  `void`
  `deinitialize(int mapId)`
  Releases native resources for `mapId` when the map is no longer used.
  `long`
  `finishPolygon(int mapId, long pathId, int fillColor, int strokeColor, int strokeWidth)`
  Finishes the path as a filled polygon and returns its element key.
  `long`
  `finishPolyline(int mapId, long pathId, int strokeColor, int strokeWidth)`
  Finishes the path as a stroked polyline and returns its element key.
  `String`
  `getId()`
  A stable identifier for this provider, e.g.
  `double`
  `getLatitude(int mapId)`
  `double`
  `getLongitude(int mapId)`
  `float`
  `getMaxZoom(int mapId)`
  `float`
  `getMinZoom(int mapId)`
  `double`
  `getScreenLat(int mapId)`
  `double`
  `getScreenLon(int mapId)`
  `int`
  `getScreenX(int mapId)`
  `int`
  `getScreenY(int mapId)`
  `float`
  `getZoom(int mapId)`
  `static WebMapProvider`
  `google(String apiKey)`
  A Google Maps JavaScript SDK provider for the given API key (the key must have the Maps JavaScript API enabled).
  `boolean`
  `isAvailable()`
  Whether this provider can render on the current device right now (e.g. Google checks that Play Services is present).
  `void`
  `removeAllElements(int mapId)`
  `void`
  `removeElement(int mapId, long elementId)`
  `void`
  `setCamera(int mapId, double lat, double lon, float zoom, float bearing, float tilt)`
  Moves the camera.
  `void`
  `setMapType(int mapId, int type)`
  `void`
  `setRotateGestureEnabled(int mapId, boolean enabled)`
  `void`
  `setShowMyLocation(int mapId, boolean show)`

  ### Methods inherited from class Object

  `clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- ## Constructor Details

  - ### WebMapProvider

    public WebMapProvider(String id, String apiKey, String htmlTemplate)

    Creates a web provider.

    ###### Parameters

    - `id`: the provider id used in the fallback chain (e.g. `"web"`)

    - `apiKey`: the SDK key substituted for `{key}` (may be empty for keyless SDKs)

    - `htmlTemplate`: a full HTML document with `{key}`/`{lat}`/`{lon}`/`{zoom}` tokens

- ## Method Details

  - ### google

    public static WebMapProvider google(String apiKey)
    A Google Maps JavaScript SDK provider for the given API key (the key must have the Maps JavaScript API enabled). Its id is `"web"` -- not `"google"` -- so it slots in as the cross-platform web fallback after the native `"google"` provider in a chain such as `setProviderOrder("google", "web", "vector")`, rather than colliding with it.

  - ### getId

    public String getId()
    A stable identifier for this provider, e.g. `"apple"` or `"google"`.
    Specified by:
      `getId` in interface `MapProvider`

  - ### isAvailable

    public 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 false `NativeMap` falls back to the vector engine.
    Specified by:
      `isAvailable` in interface `MapProvider`

  - ### createPeer

    public Component createPeer(NativeMap host, int mapId)
    Creates the view for the map identified by `mapId`. Native providers return a `PeerComponent` wrapping the native map view; a web-SDK provider returns a `BrowserComponent`. Either way it is a `Component` the `NativeMap` adds to its layout. Returning `null` triggers the vector fallback.
    Specified by:
      `createPeer` in interface `MapProvider`

  - ### deinitialize

    public void deinitialize(int mapId)
    Releases native resources for `mapId` when the map is no longer used.
    Specified by:
      `deinitialize` in interface `MapProvider`

  - ### setCamera

    public void setCamera(int mapId, double lat, double lon, float zoom, float bearing, float tilt)
    Moves the camera. `bearing` and `tilt` are in degrees; providers that do not support them ignore those arguments.
    Specified by:
      `setCamera` in interface `MapProvider`

  - ### addMarker

    public long addMarker(int mapId, byte[] icon, double lat, double lon, String title, String snippet, float anchorU, float anchorV)
    Adds a marker. `icon` is PNG bytes (or `null` for the default pin); returns an opaque element key. `anchorU`/`anchorV` are normalized.
    Specified by:
      `addMarker` in interface `MapProvider`

  - ### setMapType

    public void setMapType(int mapId, int type)
    Specified by:
      `setMapType` in interface `MapProvider`

  - ### getLatitude

    public double getLatitude(int mapId)
    Specified by:
      `getLatitude` in interface `MapProvider`

  - ### getLongitude

    public double getLongitude(int mapId)
    Specified by:
      `getLongitude` in interface `MapProvider`

  - ### getZoom

    public float getZoom(int mapId)
    Specified by:
      `getZoom` in interface `MapProvider`

  - ### getMaxZoom

    public float getMaxZoom(int mapId)
    Specified by:
      `getMaxZoom` in interface `MapProvider`

  - ### getMinZoom

    public float getMinZoom(int mapId)
    Specified by:
      `getMinZoom` in interface `MapProvider`

  - ### beginPath

    public long beginPath(int mapId)
    Starts accumulating a path; feed it with `MapProvider.addToPath(int, long, double, double)`.
    Specified by:
      `beginPath` in interface `MapProvider`

  - ### addToPath

    public void addToPath(int mapId, long pathId, double lat, double lon)
    Specified by:
      `addToPath` in interface `MapProvider`

  - ### finishPolyline

    public long finishPolyline(int mapId, long pathId, int strokeColor, int strokeWidth)
    Finishes the path as a stroked polyline and returns its element key.
    Specified by:
      `finishPolyline` in interface `MapProvider`

  - ### finishPolygon

    public long finishPolygon(int mapId, long pathId, int fillColor, int strokeColor, int strokeWidth)
    Finishes the path as a filled polygon and returns its element key.
    Specified by:
      `finishPolygon` in interface `MapProvider`

  - ### addCircle

    public 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.
    Specified by:
      `addCircle` in interface `MapProvider`

  - ### removeElement

    public void removeElement(int mapId, long elementId)
    Specified by:
      `removeElement` in interface `MapProvider`

  - ### removeAllElements

    public void removeAllElements(int mapId)
    Specified by:
      `removeAllElements` in interface `MapProvider`

  - ### calcScreenPosition

    public void calcScreenPosition(int mapId, double lat, double lon)
    Specified by:
      `calcScreenPosition` in interface `MapProvider`

  - ### getScreenX

    public int getScreenX(int mapId)
    Specified by:
      `getScreenX` in interface `MapProvider`

  - ### getScreenY

    public int getScreenY(int mapId)
    Specified by:
      `getScreenY` in interface `MapProvider`

  - ### calcLatLongPosition

    public void calcLatLongPosition(int mapId, int x, int y)
    Specified by:
      `calcLatLongPosition` in interface `MapProvider`

  - ### getScreenLat

    public double getScreenLat(int mapId)
    Specified by:
      `getScreenLat` in interface `MapProvider`

  - ### getScreenLon

    public double getScreenLon(int mapId)
    Specified by:
      `getScreenLon` in interface `MapProvider`

  - ### setShowMyLocation

    public void setShowMyLocation(int mapId, boolean show)
    Specified by:
      `setShowMyLocation` in interface `MapProvider`

  - ### setRotateGestureEnabled

    public void setRotateGestureEnabled(int mapId, boolean enabled)
    Specified by:
      `setRotateGestureEnabled` in interface `MapProvider`