【问题标题】:open layers & typescript : Event.map.forEachFeatureAtPixel Argument of type is not assignable to parameter of type打开图层和打字稿:Event.map.forEachFeatureAtPixel 类型的参数不可分配给类型的参数
【发布时间】:2023-02-05 19:00:02
【问题描述】:

我正在尝试将 open layers v7.2.2 与 typescript 一起使用。 {没有打字稿,代码按预期工作}

function OnMapClick(Event : MapBrowserEvent<UIEvent>)
{
  Event.map.forEachFeatureAtPixel(Event.pixel, function(CurrentFeature : Feature) 
  {
  ...
  }
}

错误 : 类型错误:“(CurrentFeature: Feature) => void”类型的参数不可分配给“(arg0: FeatureLike, arg1: Layer<Source, LayerRenderer>, arg2: SimpleGeometry) => void”类型的参数。 参数类型“CurrentFeature”和“arg0”不兼容。 类型“FeatureLike”不可分配给类型“Feature”。 类型“RenderFeature”缺少类型“Feature”中的以下属性:on、once、un、geometryName_ 等 40 个。

任何帮助将非常感激。 :-)

【问题讨论】:

  • 该方法可以处理来自矢量图层的 Feature 和来自矢量切片层的 RenderFeatureFeatureLike 是正确的声明。

标签: javascript typescript openlayers


【解决方案1】:

你不需要声明内联函数的类型使用这个:

function OnMapClick(Event : MapBrowserEvent<UIEvent>)
{
  Event.map.forEachFeatureAtPixel(Event.pixel, function(CurrentFeature) 
  {
  ...
  }
}

【讨论】:

    猜你喜欢
    • 2021-03-02
    • 2016-09-26
    • 1970-01-01
    • 2021-10-18
    • 2018-06-13
    • 2017-12-08
    • 2022-01-21
    • 2017-04-23
    • 2021-04-09
    相关资源
    最近更新 更多