How to add Geoserver WMS layer to vtm

20 views
Skip to first unread message

Ali Mahdian

unread,
May 15, 2021, 6:05:56 AMMay 15
to Mapsforge & VTM
Hi,
I am using VTM 0.15.0 and want to add a WMS layer to my map. This is my code:

MyUrlTileSource class:

public abstract class MyUrlTileSource extends TileSource {

    ...
...
...

    private static class DefaultTileUrlFormatter implements TileUrlFormatter {
        @Override
        public String formatTilePath(MyUrlTileSource tileSource, Tile tile) {

            int x =tile.tileX;
            int y = tile.tileY;
            int zoom = tile.zoomLevel;

            double minLon   = tile2lon(x, zoom);
            double minLat   = tile2lat(y, zoom);
            PointXY minPointStr = ConvertCoordinate.wgs2webMercator(minLat,minLon);
            double minX = minPointStr.getX();
            double minY = minPointStr.getY();

            double maxLon   = tile2lon(x + 1, zoom);
            double maxLat   = tile2lat(y + 1, zoom);
            PointXY  maxPointStr = ConvertCoordinate.wgs2webMercator(maxLat,maxLon);
            double maxX = maxPointStr.getX();
            double maxY = maxPointStr.getY();

            String url = "/GeoServer/sdi/wms?service=WMS&version=1.1.0&request=GetMap&layers=sdi%3Adehestan&bbox="+minX+","+maxY+","+maxX+","+minY;


            return url;
            
        }
    }
}

###############################################################
MainActivity class:

 @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        mMyBitmapTileSource geoserverLayer = MyBitmapTileSource.builder()
                .url("http://IP_ADDRESS:8082")
                .tilePath("/{Z}/{X}/{Y}.png")
                .build();

        geoserverLayer.setApiKey(null);

        mMap.layers().add(new BitmapTileLayer(mMap, geoserverLayer));
    }


Emux

unread,
May 17, 2021, 3:28:56 AMMay 17
to mapsfo...@googlegroups.com
You may need a custom tile source to translate the GeoServer into valid tiles to be rendered with this map library.

osmdroid-wms has an implementation, you can study and customize it.

--
Emux

HILEM Youcef

unread,
May 17, 2021, 7:28:52 AMMay 17
to Mapsforge & VTM
The Geoserver produce a valid mapbox tile : https://docs.geoserver.org/latest/en/user/extensions/vectortiles/tutorial.html
" GeoServer can also produce vector tiles in three formats: GeoJSON, TopoJSON, and MapBox Vector (MVT). These are also supported by OpenLayers and other clients."
url: '/geoserver/gwc/service/tms/1.0.0/' + layer + '@EPSG%3A'+projection_epsg_no+'@pbf/{z}/{x}/{-y}.pbf'


Emux

unread,
May 17, 2021, 7:36:34 AMMay 17
to mapsfo...@googlegroups.com
VTM can decode and render online vector tiles, e.g. OpenMapTilesMvtActivity, MapilionMvtActivity.

You may need a new tile source for this tile provider.

--
Emux
Reply all
Reply to author
Forward
0 new messages