1

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

这就是我在方法内部尝试的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
            ]
         }
      }
   ]
}
4

1 回答 1

0

我看到你也在回购中打开了一个问题。mapbox-gl-native谢谢你。我在那里回应,但也想在这里跟进。

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

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

于 2019-08-26T16:59:25.170 回答