打开第 3 层 - 用 LineString 上的第一个节点初始化绘图交互 [英] Open Layers 3 - Initialize Draw Interaction with first node on LineString

查看:75
本文介绍了打开第 3 层 - 用 LineString 上的第一个节点初始化绘图交互的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一张地图,用户可以在其中选择地图上的某个对象/特征并绘制一条指向另一个对象/特征的线.当用户选择该功能时,我希望添加绘图交互并已将第一个点设置为所选功能,而无需用户再次单击地图.

I have a map where a user can choose some object/feature on the map and draw a line to another object/feature. When the user selects the feature i would like do add a draw interaction and already set the first point to the selected feature without the user having to click again on the map.

这是一个小提琴:示例

按下绘图按钮后,下面的注释代码应以编程方式执行,无需用户交互

The commented code below should be executed programmatically without user interaction, after pressing the draw button

    geometryFunction: function (c, g) {
        if (goog.isDef(g)) {
            g.setCoordinates(c);
        } else {
            // DO THIS AUTOMATICALLY ON PRESSING DRAW
            // TO INITIALIZE AND START THE DRAWING PROCESS
            c[0][0] = 1174072.754460305;
            c[0][1] = 332653.94709708635;
            g = new ol.geom.LineString(c);
        }
        ...
    }

当前的行为是您单击绘制"按钮并可以单击地图开始绘制(但我用我想要的起始位置覆盖了第一个节点——在本例中靠近中非)

The current behaviour is that you click on the Draw button and can click on the map to start drawing (but i overwrite the first node with my desired starting location -- in this example near central africa)

是否可以点击 Draw 并且第一个节点已经以编程方式设置,而不必先点击地图?

Is it possible to click on Draw and the first node is already programmatically set, without having to click on map first?

推荐答案

目前无法手动将点附加到 OpenLayers 3 ol.interaction.Draw,但它是有意义的能够支持它(在我看来).就像用户点击了一样.

It is not not currently possible to do manually append points to the OpenLayers 3 ol.interaction.Draw, but it would make sense to be able to support it (in my mind). It would be "as-if" the user had clicked.

您应该向 OL3-dev 发送邮件询问有关添加此类功能的信息,以了解他们的想法.如果他们同意并且您愿意为此工作,您可以提供拉取请求.请参阅:https://groups.google.com/forum/#!forum/ol3-开发

You should ask the OL3-dev mailing this about adding such a feature to see what they think about it. If they agree and you're willing to work on this, you could provide a pull request. See: https://groups.google.com/forum/#!forum/ol3-dev

这篇关于打开第 3 层 - 用 LineString 上的第一个节点初始化绘图交互的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆