1

With OpenLayers 4 I copy one or more polygons from one layer to another, and since they do not have styles, I would like to assign them one.

I can put a style on the layer but polygons do not have export styles. That's why I try to put a style to the polygons without success.

The following code returns "TypeError: ... is not a function":

    var Polygon= new ol.style.Style({
          fill: new ol.style.Fill({
            color: 'rgba(255, 255, 255, 0.5)',//'#ffffff'
          }),
          stroke: new ol.style.Stroke({
            color: '#ffcc33',
            width: 4
          })
        });
        getDrawingLayer().getSource().addFeatures(select.getFeatures().getArray());//pass the polygons
         //getDrawingLayer().setStyle(Polygon)};//succes
getDrawingLayer().getSource().getFeatures().setStyle(Polygon);//try to set the style of polygons
1

ok I understand, because the layer is an array, I have to assign each feature from it with

getDrawingLayer (). getSource (). forEachFeature (function (feature) {
feature.setStyle (Polygon);});

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.