Openlayers 3选择交互无法添加事件条件

问题描述 投票:6回答:1

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

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”,如果这有任何相关性。

angular typescript openlayers openlayers-3
1个回答
0
投票

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

这意味着您需要对代码进行一些解决方法。

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

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

解:

您可以执行的一个选项是将all作为变量导入。有了这个,你将逃避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);

这样做的一个副作用是你将删除做树震动的选项,但是,如果没有它,你将会生存。

希望这可以帮助!

© www.soinside.com 2019 - 2024. All rights reserved.