1

I am trying to load WMS layer using leaflet from USGS WMS server but I am getting an empty image. I have gone through Loading WMS layer from external server in Leaflet? link but it doesn't solve my issue.

My code:

var map = L.map('map').setView([47.608013,-122.335167], 5);                    
    L.tileLayer.wms(USGS server link,  
 {  
  layers: '0',  
  format: 'image/png',  
  version: '1.3.0',  
  transparent: true,  
  continuousWorld: true,  
  attribution: "",  
  tiled:true  
 }).addTo(map);

I even tried changing version to 1.1.1, removed continousWorld: true etc.(tried almost everything). latitude and longitude that I used is Seattle's. Other examples of WMS Leaflet are working for me. The URL it is using to get the image is:

<img src="<wms server>?request=GetCapabilities&amp;service=WMS&amp;SERVICE=WMS&amp;REQUEST=GetMap&amp;VERSION=1.3.0&amp;LAYERS=0&amp;STYLES=&amp;FORMAT=image%2Fpng&amp;TRANSPARENT=true&amp;HEIGHT=256&amp;WIDTH=256&amp;CONTINUOUSWORLD=true&amp;TILED=true&amp;CRS=EPSG%3A3857&amp;BBOX=-13775786.985667603,6261721.35712164,-12523442.714243276,7514065.628545966" style="height: 256px; width: 256px; left: 270px; top: 17px;"> 

The USGS WMS server is working fine in QGIS tool.

  • does the url work in your browser directly? – Ian Turton Mar 29 '16 at 9:33
  • You might get more help if you put this in jsFiddle or similar. It is easier for people to play with. – John Powell Mar 29 '16 at 9:33
  • @iant Yes am getting xml content in browser – abi Mar 29 '16 at 9:36
  • that would be an error message then, what does it say? – Ian Turton Mar 29 '16 at 9:45
  • It is not an error message.It has the entire configuration like bounding box,CRS etc.The wms server is working fine QGIS tool(i.e i am able to get the wms layers) – abi Mar 29 '16 at 9:48
3

Just looking at your image src attribute value, I can see that you have a few errors:

<img src="<wms server>?
request=GetCapabilities&amp;
service=WMS&amp;
SERVICE=WMS&amp;
REQUEST=GetMap&amp;
VERSION=1.3.0&amp;
LAYERS=0&amp;
STYLES=&amp;
FORMAT=image%2Fpng&amp;
TRANSPARENT=true&amp;
HEIGHT=256&amp;
WIDTH=256&amp;
CONTINUOUSWORLD=true&amp;
TILED=true&amp;
CRS=EPSG%3A3857&amp;
BBOX=-13775786.985667603,6261721.35712164,-12523442.714243276,7514065.628545966" 
style="height: 256px; width: 256px; left: 270px; top: 17px;"> 

You have two service=WMS& parameters, you have two request=value& parameters, of these two requests the first listed is a GetCapabilities request. Such a GetCapabilities request will never return an image.

You also have some non WMS parameters specified CONTINUOUSWORLD=true&amp; and TILED=true&amp;

So first off I guess that somewhere you have listed the end point for the service (that is the point to which all request parameters should be appended) as:

<wms server>?request=GetCapabilities&amp;service=WMS&amp;

but it needs to be just:

<wms server>?

Then your request will become something like:

<wms server>?
SERVICE=WMS&amp;
REQUEST=GetMap&amp;
VERSION=1.3.0&amp;
LAYERS=0&amp;
STYLES=&amp;
FORMAT=image%2Fpng&amp;
TRANSPARENT=true&amp;
HEIGHT=256&amp;
WIDTH=256&amp;
CRS=EPSG%3A3857&amp;
BBOX=-13775786.985667603,6261721.35712164,-12523442.714243276,7514065.628545966&amp;"

Does this request work in a browser?

| improve this answer | |
  • Thank u so much :)After removing 'request=GetCapabilities&amp;service=WMS&amp' from the url,it worked – abi Mar 29 '16 at 12:01

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.