1

In OpenLayers, when you are giving a style to layer, say a WFS layer, we can give stroke width, like this:

var layerWFS = new ol.layer.Vector({
    source: sourceWFS,
    title: 'plot_layer',
    name: 'plot_layer',
    style: new ol.style.Style({
        stroke: new ol.style.Stroke({
            color: 'rgba(255, 0, 255, 1)',
            width: 1
        })
    })
});

Here width is 1 , I would like to know in which dimension that we are giving the stroke width, whether:

  1. millimeter (mm) 1 means 1mm
  2. centimeter (cm) 1 means 1cm
2

Style are based on pixels (the screen unit). They are not related to resolution (related to scale). If you want to tie width with scale on the map, you should use a function instead as it can access resolution

var layerWFS = new ol.layer.Vector({
    source: sourceWFS,
    title: 'plot_layer',
    name: 'plot_layer',
    style: function(feature, resolution) {
      // Resolution = number of meters for a pixel (at least for EPSG 3857)
      console.log(resolution);
      return new ol.style.Style({
        stroke: new ol.style.Stroke({
            color: 'rgba(255, 0, 255, 1)',
            width: 1
        })
      })
    }
});

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.