简体   繁体   中英

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 the web, but those are always with a single line.

Do you know if it's possible to do it with a multiLineString?

Yes, it is possible.

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

    var styles = [
    // linestring
    new 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

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