1

I have been trying to add my WMS vector layers in OpenLayers 3 but it isn't working, I guess there is a problem with my script. Below is my JavaScript code:

<script>
    var osmLayer = new ol.layer.Tile({
      source: new ol.source.OSM()
    });
    var view = new ol.View({
      center: ol.proj.fromLonLat([7.118906, 5.640610]),
      zoom: 8
    });
    var map = new ol.Map({
      target: 'map'
    });

    var vectorLayer = new ol.layer.Tile({
        source: new ol.source.TileWMS({
            preload: Infinity,
            url: 'http://localhost:8090/geoserver/ssterritory/wms',
            serverType:'geoserver',
            params:{
                'LAYERS':"ssterritory:lgas", 'TILED':true
            }
        })
    });

    map.addLayer(osmLayer);
    map.addLayer(lgas);
    map.setView(view);
</script>

I need someone to help me with this

2
  • 2
    it looks like you never add vectorLayer to the map
    – Ian Turton
    Nov 9 '15 at 16:47
  • Note that WMS is not a vector layer
    – nmtoken
    Dec 5 '17 at 8:02
3

As per the @IanTurton comment you are never add your WMS layer to the map, like 'map.addLayer(vectorLayer);' in the below code:

<script>
    var osmLayer = new ol.layer.Tile({
      source: new ol.source.OSM()
    });
    var view = new ol.View({
      center: ol.proj.fromLonLat([7.118906, 5.640610]),
      zoom: 8
    });
    var map = new ol.Map({
      target: 'map'
    });

    var vectorLayer = new ol.layer.Tile({
        source: new ol.source.TileWMS({
            preload: Infinity,
            url: 'http://localhost:8090/geoserver/ssterritory/wms',
            serverType:'geoserver',
            params:{
                'LAYERS':"ssterritory:lgas", 'TILED':true
            }
        })
    });
    map.addLayer(vectorLayer); // --> add this to your code
    map.addLayer(osmLayer);
    map.addLayer(lgas);
    map.setView(view);
</script>

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.