javascript - 如何避免 OpenLayers 中的双重选择?
问题描述
我们有使用 OpenLayers 的 Vue.js 应用程序。我们绘制了一些图形对象,但我遇到了选择问题。我们使用 OpenLayers 的 Select 和 Modify 交互来选择和移动点状对象,并使用 ol-ext 的扩展包来移动其他类型的图形对象,例如线、多边形等。问题是当我们选择点状对象时,一切正常是否只有蓝点,我们用它来单击和拖动它们,但是当我们选择非点状对象时,既有 OpenLayers 也有 ol-ext 交互。应该只有ol-ext的交互。它看起来如下:
如您所见,所选多边形具有蓝色 OpenLayers 框架和 ol-ext 红色框架。只有当我们选择多边形时,我们才需要有红色的框架。
代码如下所示:
editGeometry (edit) {
if (!edit) {
this.modifyNonPoint.un('select', this.onModifyNonPoint)
this.selectedFeatures.un('add', this.onSelectPoint)
this.selectedPointFeature.un('change', this.onChangePoint)
this.devDocMap.removeInteraction(this.modifyNonPoint)
this.devDocMap.removeInteraction(this.selectPoint)
this.devDocMap.removeInteraction(this.modifyPoint)
return
}
if (!this.vectorLayer.getSource()) {
return
}
// ol-ext's Transform interaction
this.modifyNonPoint = new Transform({
features: this.vectorLayer.getSource().getFeatures().filter(x => x.get('graphics') && x.get('movable') && !this.isPoint(x))
})
this.modifyNonPoint.on('select', this.onModifyNonPoint)
this.devDocMap.addInteraction(this.modifyNonPoint)
// OpenLayers' Select interaction
this.selectPoint = new Select()
this.selectedFeatures = this.selectPoint.getFeatures()
this.selectedFeatures.on('add', this.onSelectPoint)
this.devDocMap.addInteraction(this.selectPoint)
// OpenLayers' Modify interaction
this.modifyPoint = new Modify({
features: this.selectedFeatures
})
this.devDocMap.addInteraction(this.modifyPoint)
},
onModifyNonPoint (event) {
if (event.feature) {
this.devDocMap.removeInteraction(this.select)
}
developedDocumentsApi.saveDrawingGraphics(this.document.id, this.updateGraphicsObjList())
},
onSelectPoint (event) {
this.selectedPointFeature = event.element
this.selectedPointFeature.on('change', this.onChangePoint)
},
onChangePoint (event) {
developedDocumentsApi.saveDrawingGraphics(this.document.id, this.updateGraphicsObjList())
},
isPoint (feature) {
if (!feature) {
return false
}
const featureGeometry = feature.getGeometry()
const featureGeometryType = featureGeometry.getType()
if (featureGeometryType === 'Point') {
return true
}
return false
},
如何克服这个问题?
解决方案
如果您只想选择积分,请使用
this.selectPoint = new Select({
filter: function(feature) { return feature.getGeometry().getType() == 'Point' }
})
推荐阅读
- python - 使用 Ubuntu 20.4 和 Python Imaplib:我可以覆盖 ssl.SSLError: [SSL: DH_KEY_TOO_SMALL] 吗?
- python - 如何序列化keras模型的类对象
- .net-core - 使用 Azure DevOps 的 Delpoy NetCore 应用程序
- excel - 数字倍数的Excel条件格式
- javascript - 如何更改 Highcharts 上的 DateTime 格式?
- typescript - 页面刷新角9后保留材料徽章值
- html - 对齐两个元素的基线
- python - gzip python 2.7中现有的json文件
- python - 如何在多个文件中将某个标签中的字符串更改为小写
- cross-platform - 如何使用自动填写的凭据从电子邮件中打开应用程序