OpenLayers 5:笔划宽度缩放?

OpenLayers 5: stroke width scaling?

是否可以使描边宽度取决于缩放级别?

基本上,我将使用 LineStrings/MultiLineStrings 来突出显示一些道路,但我也希望能够缩小并且不会出现大量混乱(每条路径上大约有 8 条相当宽的线) .

您可以使用传递给样式函数的分辨率。我使用这段代码来显示等高线,将线条设置为 50 米宽的倍数,当分辨率大于 2.5 时,两个宽度都会按比例减小。

style: function(feature, resolution) {
    return new ol.style.Style({
        stroke: new ol.style.Stroke({
            color: 'rgba(224,148,94,1)',
            width: (feature.getProperties().value % 50 == 0 ? 3.175 : 1.863) * Math.min(1, 2.5/resolution)
        })
    });
}