不同颜色的边框底部在 ol.style.stroke.

Different color border-bottom in ol.style.stroke

本文关键字:ol style stroke 底部 边框 颜色      更新时间:2023-09-26

在OpenLayers 3中,可以更改选择中的边框颜色:

style = new ol.style.Style({
    stroke: new ol.style.Stroke({
      color: 'blue',
      width: 2
    })
  });

但是可以只更改边框底部吗?

像这样:

style = new ol.style.Style({
    stroke: new ol.style.Stroke({
      color: 'blue',
      width: 2,
      border-bottom: 2px dotted #ff9900
    })
  });

当然,由于可用的大量OL 3资源,您可以使用第二种样式来(模拟)边框底部。使用ol.style#GeometryFunction .灵感来自这个例子。

http://jsfiddle.net/jonataswalker/k11bxma2/

有点不同 - http://jsfiddle.net/jonataswalker/n73gm0u9/

var style = [
  new ol.style.Style({
    fill: new ol.style.Fill({
      color: 'rgba(255, 255, 255, 0.2)'
    }),
    stroke: new ol.style.Stroke({
      color: 'red',
      width: 2
    })
  }),
  new ol.style.Style({
    stroke: new ol.style.Stroke({
      color: 'green',
      width: 2
    }),
    geometry: function(feature) {
      var geom = feature.getGeometry();
      var extent = geom.getExtent();
      var bottomLeft = ol.extent.getBottomLeft(extent);
      var bottomRight = ol.extent.getBottomRight(extent);
      // return a linestring with the second style
      return new ol.geom.LineString([bottomLeft, bottomRight]);
    }
  })
];