OpenLayers:绘制多边形和点,然后将其拖动

时间:2018-08-28 13:19:44

标签: javascript openlayers

试图解决开放层问题。

第一个问题:我有一个实体,它具有在地图上绘制的航点和线的集合。我想将多边形线和点一起拖动。

第二个问题:当我有多个实体时,是否还可以为我添加唯一的图层或要素?我不想移动其他实体的航路点或线,因此我可以使用开放层来绘制唯一且只能通过名称访问的线吗?

我是刚接触层的新手,但仍在尝试找出浏览api文档的最佳方法。

1 个答案:

答案 0 :(得分:0)

第一个问题答案::将线和点的特征合并为一个特征“集合”(ol.collection)。

第二个问题答案::对于唯一实体,应将用于实体本身的各种功能附加到实体上。当您选择实体时,请返回您希望操纵所选实体所具有的特征的集合。

    //get the selected entity that had the waypoints appended to the object
    const selectedEntity = this.entities.get(this.selected);
    //combine the points and the polygon line into one array to turn into a collection
    var linesAndPoints = selectedEntity.waypointFeatures.icons.concat(selectedEntity.waypointFeatures.lines);
    //create an ol.collection object to add to the translate interaction
    let featuresCollection = new ol.Collection(linesAndPoints);
    this.myTranslate = new ol.interaction.Translate({
      condition: ol.events.condition.click,
      hitTolerance: 5,
      features: featuresCollection
    });
相关问题