Load Multiple WFS layers from array with OpenLayers

المشرف العام

Administrator
طاقم الإدارة
looking for some help here.

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.

Any help is greatly appreciated. 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
 
أعلى