This article is a basic integration guide for using WMS tile servers with osmdroid.
It's not perfect and will not work with many use cases.
- Starting with a WMS endpoint, fetch and parse the
GetCapabilities
document WMSEndpoint
contains the bare minimum needed for layer selection and some minor presentation detailsWMSEndpoint
's layers can then be presented to the user for selection- Upon selection, the WMSTileSource is created from the
WMSEndpoint
and theWMSLayer
- Finally, tell osmdroid to use the newly created WMSTileSource
Server's we have tested against
- Geoserver, works in most cases
- NASA's endpoints, most do NOT work.
The following coordinate/spatial reference systems (CRS/SRS) are supported
- WGS84, EPSG:4326, CRS:84, this your standard lat/lon
- EPSG:900913
General WMS server requirements
- The WMS server needs to support producing a tile for a specific bounding box at a specific pixel size.
- Layers that require additional input parameters, such as time offsets, is not supported.
- Layers that require a HTTP post message is not supported.
- Layers that use non-square pixels (i.e. the height and width of the image are not equal) is not supported.
- Only layers that use the supported CRS/SRS can be used
Styling per layer is supported, the first style is auto selected.
Multiple tile layers active at the same time is not currently supported (this would be useful for getting the best tile available as you zoom in and out).
WMS library was added in 6.0 of osmdroid. It may not yet be published, see the osmdroid readme for details.
dependencies {
compile 'org.osmdroid:osmdroid-wms:<VERSION>'
}
Note, error handling is omitted for brievity
HttpURLConnection c = null;
InputStream is = null;
WMSEndpoint wmsEndpoint;
c = (HttpURLConnection) new URL(youEditTextValue).openConnection();
is = c.getInputStream();
wmsEndpoint = WMSParser.parse(is);
is.close();
c.disconnect();
Here is a great spot to prompt the user for some kind of layer selection.
Here we are selecting the first layer and telling osmdroid to use it.
WMSTileSource source = WMSTileSource.createFrom(wmsEndpoint, wmsEndpoint.getLayers().get(0) );
if (layer.getBbox() != null) {
//center map on this location
mMapView.zoomToBoundingBox(layer.getBbox(),true);
}
mMapView.setTileSource(source);