Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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
    })
  });
like image 391
Toni BCN Avatar asked Sep 25 '22 08:09

Toni BCN


1 Answers

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]);
    }
  })
];
like image 80
Jonatas Walker Avatar answered Oct 11 '22 16:10

Jonatas Walker