openlayers 3 : draw arrow on multi line

南楼画角 提交于 2019-12-25 09:18:11

问题


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?


回答1:


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



来源:https://stackoverflow.com/questions/40787691/openlayers-3-draw-arrow-on-multi-line

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!