0

I'm new to OpenLayers and GeoServer and I have a problem (of course :P). I must retrieve a layer from a GeoServer WMS service, and I want to construct the URL to request it. If I try to make this:

map.addLayer(new OpenLayers.Layer.WMS("test", 
    "http://192.168.0.30:8080/geoserver/dsn/wms?service=WMS&version=1.1.1&request=GetMap&BBOX="+map.getExtent().toBBOX()+"&srs=EPSG:900913",
    { layers: "area", transparent: true, format: 'image/png' })
);

all the tiles of the grid of the WMS are the same (I see a sort of periodic repetition of the image) but if I do

map.addLayer(new OpenLayers.Layer.WMS("test", 
    "http://192.168.0.30:8080/geoserver/dsn/wms?service=WMS&version=1.1.1&request=GetMap",
    { bbox:map.getExtent().toBBOX(), srs:"EPSG:900913", layers: "area", transparent: true, format: 'image/png' })
);

everything is working as expected.

What am I doing wrong in constructing the URL?

2
  • Use firebug or a similar tool (eg. chrome's web inspector) to view the network requests being made and compare the URLs being requested. Jun 9, 2014 at 21:52
  • In firebugs I can see that the use of the second method fire 24 wms request (with different bbox, one for each tile), but using the direct URL, only one request has been fired. How is it possible? Jun 9, 2014 at 22:11

2 Answers 2

2

The first code example you supply is not the correct way to request a WMS layer in OpenLayers - you are providing unnecessary WMS parameters. The url should only be

http://192.168.0.30:8080/geoserver/dsn/wms

The rest of the parameters you are including are redundant because they are created by OpenLayers in the process of generating the WMS request. The bounding box in particular should not be specified. Openlayers will calculate the correct bounding box for each tile. I suspect the second code example is working only because OpenLayers is ignoring your bounding box parameter. (I assume you want a tiled layer. If not, there is a singleTile:true parameter you can add.)

-1

I would also write the URL as "http://192.168.0.30:8080/geoserver/dsn/wms?" and give other useful parameters like shown in this post.

I didn't test it in OpenLayers but I wrote this way in Leaflet and it worked.

1
  • This doesn't add anything to the existing answer
    – nmtoken
    Feb 20, 2020 at 11:31

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.