OpenLayers:绘制多边形和点然后拖动它们
OpenLayers: Drawing polygons and points then dragging them
希望解决我在使用开放层时遇到的问题。
第一个问题: 我有一个实体,它有一个集合 waypoints 和在地图上绘制的线条。我想将多边形线和点一起拖动。
第二个问题:当我有多个实体时,是否还有办法为我添加独特的层或特征?我不想移动 waypoints 或不同实体的线,所以我可以使用开放层来绘制唯一且只能通过名称访问的线吗?
我是打开图层的新手,仍在尝试找出浏览 api 文档的最佳方式。
第一个问题答案:将线和点的特征组合成一个特征"collection"(ol.collection)。
第二个问题答案: 对于独特的实体,您应该将用于实体本身的各种特征附加到实体本身。当您 select 实体 return 您希望操纵的特征集合时,selected 实体具有。
//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
});
希望解决我在使用开放层时遇到的问题。
第一个问题: 我有一个实体,它有一个集合 waypoints 和在地图上绘制的线条。我想将多边形线和点一起拖动。
第二个问题:当我有多个实体时,是否还有办法为我添加独特的层或特征?我不想移动 waypoints 或不同实体的线,所以我可以使用开放层来绘制唯一且只能通过名称访问的线吗?
我是打开图层的新手,仍在尝试找出浏览 api 文档的最佳方式。
第一个问题答案:将线和点的特征组合成一个特征"collection"(ol.collection)。
第二个问题答案: 对于独特的实体,您应该将用于实体本身的各种特征附加到实体本身。当您 select 实体 return 您希望操纵的特征集合时,selected 实体具有。
//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
});