Skip to content Skip to sidebar Skip to footer

Openlayers 3 : Draw Arrow On Multi Line

I'd like to know if it's possible to draw an arrow icon on a MultiLineString My aim is to show multiline with an arrow on every line of the multiLine. I have seen some examples on

Solution 1:

Yes, it is possible.

var styleFunction = function(feature) {
  var geometry = feature.getGeometry();

    var styles = [
    // linestringnew ol.style.Style({
      stroke: new ol.style.Stroke({
        color: '#ffcc33',
        width: 2
      })
    })
  ];

var lineStringsArray = geometry.getLineStrings();
for(var i=0;i<lineStringsArray.length;i++){

  lineStringsArray[i].forEachSegment(function(start, end) {
    var dx = end[0] - start[0];
    var dy = end[1] - start[1];
    var rotation = Math.atan2(dy, dx);
    styles.push(new ol.style.Style({
      geometry: new ol.geom.Point(end),
      image: new ol.style.Icon({
        src: 'https://openlayers.org/en/v3.19.1/examples/data/arrow.png',
        rotateWithView: false,
        rotation: -rotation
      })
    }));
  });
}

  return styles;
};

Have a look at demo Link https://plnkr.co/edit/UM7bD8Pq55PjWQ6EHmTl?p=preview

Post a Comment for "Openlayers 3 : Draw Arrow On Multi Line"