0

I'm trying to access a WMS endpoint through Openlayers to display the data in a slippy map.

Here's my code:

var basemap = new ol.source.TileWMS( " Layer Name 1", "http://localhost:8080/geoserver/oswgc-india/wms", {layers: 'oswgc-india:india_grouplayer'} );

         var map = new ol.Map({
                layers: [
                        basemap
                        ],
                target: 'map',
                view: new ol.View({
                        center: [312406.33, 6150500.21],
                        zoom: 5
                })
          });

In Geoserver, I have created a grouped layer called india_grouplayer in the workspace oswgc-india. However, my index.html with the embedded JavaScript just returns a blank page. I suspect that I'm missing configuration options in Geoserver, as I'm not exactly very familiar with the software.

  • look in the GeoServer log file to see what the issue is, also check the URL being requested in a browser and make sure it really is a blank image, then check the projections of your map and the request – Ian Turton Jun 24 at 13:55
  • @IanTurton Thank you for your comment. Browsing to the URL directly yields a "no applicable code" exception. – Fang Jun 24 at 14:23
  • please edit to include the url being requested and the exact response you get back – Ian Turton Jun 24 at 15:05
2

What is definitely wrong is that there is no layer definition and source is used as layer.

It should look something like this:

var mapSource = new ol.source.TileWMS( "Layer Name 1", "http://localhost:8080/geoserver/oswgc-india/wms", {layers: 'oswgc-india:india_grouplayer'} );

var mapLayer = new ol.layer.Tile({
  source: mapSource,
  extent: [ ... ]
});

var map = new ol.Map({
  layers: [
    mapLayer
  ],
  target: 'map',
  view: new ol.View({
    center: [312406.33, 6150500.21],
    zoom: 5
  })
});

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.