I have a layer on my Geoserver that contains a few dozen pipeline alignments in a single layer. My goal is to get those into the map frame as individual layers by iteratively calling WFS layers and applying a CQL filter to only return the specified pipeline based on a 'name' attribute. My reason for doing this is that I only want to maintain one master dataset, but I need to be able to display and toggle visibility of each pipeline individually in the legend box.

Conceptually, I was thinking the following would work:

  1. Put the names of each pipe I want in an array
  2. Loop through the array and construct a WFS GetFeature call for each name, using the name as the CQL filter to return only that pipe segment

However, while the loop appears to succesfully populate the legend box with the names I'm looking for, I only have one pipe geometry being returned. It is always the last pipe specified in the array and can't figure out why.

Also, the code below shows that I'm putting the layers into a layer group and then adding the layer group to the map. I've tried this other ways as well, including omitting the layer group and simply adding each layer to the map (e.g. map.addLayer(layer)), but can't get anything to work; always just displays the last pipe in the array.

Code below:

//array to hold requested pipelines    
var MammCreekLines = ['Hunter CS to Pumba CS','South Grass Mesa','Shideler 12in'];

//loop to construct WFS GetFeature for each layer
for (var i=0; i<MammCreekLines.length; i++) {

var selectStatement = "CQL_FILTER=name='"+MammCreekLines[i]+"'"

MammPipeSource[i] = new ol.source.ServerVector({
    format: new ol.format.WFS({
        featureNS: 'http://www.elev8-ims.com/summit_sw',
        featureType: 'summit_pipes'
    loader: function(extent, resolution, projection) {
        var url = 'http://elev8-ims.com/geoserver/summit_sw/wfs?'+

            url: url

        .done(function(response) {
    strategy: ol.loadingstrategy.createTile(new ol.tilegrid.XYZ({
        maxZoom: 19
    projection: 'EPSG:3857'

MammPipe[i] = new ol.layer.Vector({
  source: MammPipeSource[i],
  name: MammCreekLines[i],
  style: [thickStyle, thinStyle]


//add layer from the array to the legend group
  var MammCreekGroup = new ol.layer.Group({
  layers: MammCreekArray,
  name: 'Mamm Creek Pipelines'

Your Answer

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

Browse other questions tagged or ask your own question.