5

Currently I am working on the adding a WMS source on the map in native android platform. I am using mapbox to show map in the application. I am trying to add a WMS source layer from Geo-server But the WMS source layer getting added multiple times over the map as shown in the picture :

enter image description here

Here is the code snippet which I have used to add WMS source :

@Override public void onMapReady(MapboxMap mapboxMap) {

    RasterSource webMapSource = new RasterSource(
            "web-map-source",
            new TileSet("tileset", "http://geo.skymetweather.com:8081/geoserver/cite/wms/cite:india_district_web?" +
                    "&bbox=68.036003112793,6.60812377929688,97.5504302978516," +
                    "37.2502937316895&format=image/png&service=WMS&version=1.1.1&" +
                    "request=GetMap&srs=EPSG:4326&width=493&height=512&layers=cite:india_district_web"), 256);

    mapboxMap.addSource(webMapSource);

    // Add the web map source to the map.
    RasterLayer webMapLayer = new RasterLayer("web-map-layer", "web-map-source");
    mapboxMap.addLayerBelow(webMapLayer, "aeroway-taxiway");

} 

Please suggest if any thing wrong with the code or does anyone know how to add Raster Source on Map?

Thanks in advance !

Phantômaxx
  • 37,901
  • 21
  • 84
  • 115
amol anerao
  • 257
  • 1
  • 9

1 Answers1

3

Mapbox only supports 'EPSG:3857' for rendering WMS tiles and you should project your source to this SRS. Also, there is no need to set its bounding box statically as you did in second line of TileSet. Use this template to load WMS in your application:

RasterSource webMapSource = new RasterSource(
                       "web-map-source",
                        new TileSet("tileset",
                           'http://a.example.com/wms?bbox={bbox-epsg-3857}&format=image/png&service=WMS&version=1.1.1&request=GetMap&srs=EPSG:3857&width=256&height=256&layers=example')
                           ,256);
Nasser Tahani
  • 725
  • 12
  • 33