MGLSymbolStyleLayer text not showing

天涯浪子 提交于 2021-01-29 12:56:23

问题


I successfully added an MGLSymbolStyleLayer layer to my map and configured its look by data from GeoJSON that's loaded locally, but I'm unable to set the value for text property.

This is how I'm trying to do it inside mapView(_ mapView: MGLMapView, didFinishLoading style: MGLStyle) method:

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

When I run the app, the text is never shown while the image is loaded correctly. This is how my GeoJSON is formated.

{
   "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
            ]
         }
      }
   ]
}

回答1:


I see that you also opened an issue in the mapbox-gl-native repo. Thank you for that. I responded there, but want to follow-up here as well.

It looks like you are trying to use feature interpolation (the {}). That should not be necessary for this use case. If you remove the curly braces, do you see the text?

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



来源:https://stackoverflow.com/questions/57639722/mglsymbolstylelayer-text-not-showing

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!