简体   繁体   中英

Different color border-bottom in ol.style.stroke

In OpenLayers 3 is possible to change border color in a selection:

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

But is possible to change only border-bottom ?

Something like:

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

For sure, thanks to the huge OL 3 resources available, you can use a second style to (simulate) a border bottom. Use a ol.style#GeometryFunction . Inspired on this example .

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

A little bit different - 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]);
    }
  })
];

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM