问题
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