【问题标题】:Openlayers 3 select interaction unable to add event conditionOpenlayers 3 选择交互无法添加事件条件
【发布时间】:2019-03-05 16:28:41
【问题描述】:

因此,当我将鼠标悬停在任何明显突出显示的功能上时,我正在尝试将选择交互添加到我的地图中。

import Select from 'ol/interaction/select';
import pointerMove from 'ol/events/condition.js'

this.selectPointerMove = new Select({
   condition: pointerMove
});
this.coreMapComponent.map.addInteraction(this.selectPointerMove);

条件字段抛出错误-

 Type 'typeof events' is not assignable to type 'EventsConditionType'.
 Type 'typeof events' provides no match for the signature '(event: MapBrowserEvent): boolean'.

如果没有条件,它可以在鼠标单击时正常工作。

如果相关的话,应该在 Angular 6 项目中使用“@types/ol”:“^4.6.2”来提及这一点。

【问题讨论】:

  • 试试import {pointerMove} from 'ol/events/condition';
  • 是的,很抱歉应该提到我已经尝试过了,不幸的是同样的结果。
  • 尝试删除.js之后的condition => import pointerMove from 'ol/events/condition'
  • 我也试过了,不幸的是没有运气。

标签: angular typescript openlayers openlayers-3


【解决方案1】:

当前的 Openlayers 版本 5.x.x 需要一些打字更新。由于即使您使用的是 Openlayers 5.x.x,所以安装的类型来自版本 4.x.x。

这意味着您需要对代码进行一些变通。

由于版本 4.x.x 上的所有类型都使用 DefaultExports 方法,因此您不能像这样使用 NamedExports

import {pointerMove} from 'ol/events/condition';

解决方案:

您可以做的一个选择是将所有内容作为变量导入。有了这个,您将逃脱 TS 错误:

import Select from 'ol/interaction/select';
import * as condition from 'ol/events/condition';

this.selectPointerMove = new Select({
   condition: (condition as any).pointerMove
});
this.coreMapComponent.map.addInteraction(this.selectPointerMove);

这样做的一个副作用是您将删除进行树木砍伐的选项,但是,如果没有它,您将继续生存。

希望这会有所帮助!

【讨论】:

  • 确实删除了 ts lint 错误并防止控制台中出现任何错误,但不幸的是,仅在鼠标单击时才突出显示 pointerMove 上的功能。
  • 据我所知,添加交互仅说明您可以使用(收听/订阅)此交互的地图。我不认为 pointermove 会自动突出显示该功能。你应该监听事件: this.coreMapComponent.on("pointermove", function() { /* highlight feature*/ }) 并在回调函数上执行hihglight
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多