Add tileoverlay to native google maps

9 views
Skip to first unread message

Peter Bell

unread,
Nov 27, 2019, 9:17:48 AM11/27/19
to CodenameOne Discussions
I was wondering if its possible to add  a tile overlay tot the native google maps. I have a xyz layer . 
What do i have to change in the googlemaps cn1lib code 
 
the code for the layer could be,  where GoogleMap = mapInstance.  Do i  need a sperate container on top ? So where do i start?
Import com.google.android.gms.maps.model.TileProvider;
Import com.google.android.gms.maps.model. UrlTileProvider;

import com.google.android.gms.maps.model.TileOverlay;

import com.google.android.gms.maps.model.TileOverlayOptions;

Public void setoverlay {
TileProvider tileProvider = new UrlTileProvider(256, 256) {
  @Override
  public URL getTileUrl(int x, int y, int zoom) {

    /* Define the URL pattern for the tile images */
    String s = String.format("http://tiles.openseamap.org/seamark/%d/%d/%d.png",
        zoom, x, y);

    if (!checkTileExists(x, y, zoom)) {
      return null;
    }

    try {
      return new URL(s);
    } catch (MalformedURLException e) {
        throw new AssertionError(e);
    }
  }

  /*
   * Check that the tile server supports the requested x, y and zoom.
   * Complete this stub according to the tile range you support.
   * If you support a limited range of tiles at different zoom levels, then you
   * need to define the supported x, y range at each zoom level.
   */
  private boolean checkTileExists(int x, int y, int zoom) {
    int minZoom = 12;
    int maxZoom = 20;

 if ((zoom < minZoom || zoom > maxZoom)) {
      return false;
    }

    return true;
  }
};

TileOverlay tileOverlay =
MapInstance.addTileOverlay(new TileOverlayOptions()
    .tileProvider(tileProvider)
.transparency(0.5f));

); }

Shai Almog

unread,
Nov 27, 2019, 9:22:36 PM11/27/19
to CodenameOne Discussions
We don't expose that API because it would be a bit of a pain to manager. You can just add a components into the map and group them accordingly in a map. Then remove/add a group based on its overlay layer.
Reply all
Reply to author
Forward
0 new messages