代码之家  ›  专栏  ›  技术社区  ›  Munerz

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

  •  0
  • Munerz  · 技术社区  · 6 年前

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

    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'.
    

    如果没有条件的话,只需点击鼠标就可以正常工作。

    0 回复  |  直到 6 年前
        1
  •  1
  •   Llorenç Pujol Ferriol    6 年前

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

    因为版本4.x.x上的所有打字都使用 方法,你不能使用 比如:

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

    解决方案:

    你可以做的一个选择是 全部作为变量导入

    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);
    

    这样做的一个副作用是你会 删除进行树摇动的选项 但是,没有这些,你会活下来的。