无法在openlayer中2分之间绘制弧度

发布于 2025-01-31 16:00:58 字数 1482 浏览 2 评论 0原文

我在画布上有2分。 假设点-A [x = 4.1549997,y = 4.005]和point-b [x = 2.77,y = 3.5749998]

现在,我想从 point-a&gt中绘制一个弧箭头;点b point-b> Point-A 使用OpenLayers 3库。

到目前为止,我已经能够使用Linestring成功创建直箭。但是,我找不到OpenLayer给出的任何内置功能,可以在2分之间绘制弧线。

      var me = this;
  var line = new ol.geom.LineString(coordinate);

  var fl = new ol.Feature({
      name: "line",
      geometry: line
    });

     
  fl.setProperties({
      'coordinate': coordinate
    });
    fl.setStyle( function(feature, resolution) {
      return me.getStyles(fl);
    });
  return fl;
  
  
  
  
  
  
  getStyles: function (fObj) {
    var geometry = fObj.getGeometry();

    var styles = [new ol.style.Style({
        stroke: new ol.style.Stroke({
           width: 5,
           color: 'rgb(21,150,18)',
           lineDash: [.2,5]
         })
       })];
    
    geometry.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: '../images/arrow_test.png',
            anchor: [0.75, 0.5],
            rotateWithView: true,
            rotation: -rotation
          })
        }));
      })
    
    return styles;
},

有人可以在这里帮助我吗?

注意 - 此外,我还担心还有一件事。当 apoint-a和point-b 之间绘制多个弧线时,它们不应彼此重叠。

I have 2 points on canvas.
Lets say point-A [x=4.1549997, y=4.005] and Point-B [x=2.77, y=3.5749998]

Now, I want to draw an arc arrow from Point-A > Point-B AND Point-B > Point-A using OpenLayers 3 Library.

So far, I have been able to successfully create Straight Arrows using LineString. But, I could not find any inbuilt functionality given by OpenLayer to draw ARC between 2 points.

      var me = this;
  var line = new ol.geom.LineString(coordinate);

  var fl = new ol.Feature({
      name: "line",
      geometry: line
    });

     
  fl.setProperties({
      'coordinate': coordinate
    });
    fl.setStyle( function(feature, resolution) {
      return me.getStyles(fl);
    });
  return fl;
  
  
  
  
  
  
  getStyles: function (fObj) {
    var geometry = fObj.getGeometry();

    var styles = [new ol.style.Style({
        stroke: new ol.style.Stroke({
           width: 5,
           color: 'rgb(21,150,18)',
           lineDash: [.2,5]
         })
       })];
    
    geometry.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: '../images/arrow_test.png',
            anchor: [0.75, 0.5],
            rotateWithView: true,
            rotation: -rotation
          })
        }));
      })
    
    return styles;
},

Can anyone please help me here regarding this ?

Note - Also, there is one more thing which I am concerned also. When multiple ARCs are drawn between Point-A and Point-B, then they should not overlap on each other.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文