2

I am using the latest version of GeoServer (2.16.2). I am able to fetch the WMS of my layer using the following code,

<img src="http://localhost/geoserver/tajikistan/wms?service=WMS&version=1.1.0&request=GetMap&layers=country%3Ajamoat&bbox=353577.4375%2C4059412.5%2C1023945.625%2C4547171.0&width=768&height=558&srs=EPSG%3A32642&format=application/openlayers">

For now, the img tag producing the image without osm layer. I need to add osm layer as baselayer and display through img tag. The above code will produce the map like following,

enter image description here

But I want to display this map with OSM base layer like below map, enter image description here

I know I can overlay it with osm in leaflet map view (not in <img src=""> tag), by using following code,

//load admin layer data form geoserver
const mywms = L.tileLayer.betterWms(
  "http://localhost/geoserver/tajikistan/wms",
  {
    layers: "country:layer",
    format: "image/png",
    transparent: true,
    version: "1.1.0",
    attribution: "country layer"
  }
).addTo(map);

How can I add the osm base layer in my WMS URL?

4
  • what do you mean 'in WMS'? Leaflet will be using WMS (or WMTS) to produce the map.
    – Ian Turton
    Apr 6 '20 at 7:31
  • 1
    I mean I want to insert the WMS layer as img or png format so that I can add it into img src tag.
    – dhiraj
    Apr 6 '20 at 7:40
  • please edit the question to make it clearer
    – Ian Turton
    Apr 6 '20 at 8:15
  • I just edited my post. Please answer it where it is possible or not?
    – dhiraj
    Apr 6 '20 at 10:24
1

This is not possible, you could create a single WMS image if (and only if) you have an OSM base layer in your WMS server. A WMS request can only request layers that are available on the server you make the request to.

The only (sort of) exception to this is if the server you are using is cascading a layer from another server but since OSM is not generally served using OGC standards it is unlikely that you will be able to do this on your server.

You could use GeoSolutions pre-prepared OSM data directory and then add your own data layer but it seems like a lot of work for this.

2
  • Ohh really! Thank you for the information. Do you know any baselayers that I can add in my map background using this img tag?
    – dhiraj
    Apr 6 '20 at 10:41
  • 1
    No, as I explained you can only add layers that are on your server!
    – Ian Turton
    Apr 6 '20 at 10:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.