MGLSymbolStyleLayer 文本未显示

MGLSymbolStyleLayer text not showing

我已成功将 MGLSymbolStyleLayer 图层添加到我的地图并通过本地加载的 GeoJSON 数据配置其外观,但我无法设置文本值 属性。

这就是我尝试在 mapView(_ mapView: MGLMapView, didFinishLoading style: MGLStyle) 方法中执行此操作的方式:

customLayer.text = NSExpression(forKeyPath: "{name}")

当我 运行 应用程序时,在正确加载图像时从不显示文本。这就是我的 GeoJSON 的格式。

{
   "type":"FeatureCollection",
   "features":[
      {
         "type":"Feature",
         "properties":{
            "name":"First name",
         },
         "geometry":{
            "type":"Point",
            "coordinates":[
               21.3,
               55.5
            ]
         }
      },
      {
         "type":"Feature",
         "properties":{
            "name":"Second name",
         },
         "geometry":{
            "type":"Point",
            "coordinates":[
               20.5,
               50.5
            ]
         }
      }
   ]
}

我看到您还在 mapbox-gl-native 存储库中打开了 an issue。谢谢你。我在那里回复了,但也想在这里跟进。

您似乎正在尝试使用特征插值({})。对于此用例,这不是必需的。如果你去掉花括号,你能看到文字吗?

customLayer.text = NSExpression(forKeyPath: "name")