MGLSymbolStyleLayer文字未显示 [英] MGLSymbolStyleLayer text not showing

查看:77
本文介绍了MGLSymbolStyleLayer文字未显示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我成功地在我的地图上添加了MGLSymbolStyleLayer图层,并通过来自本地加载的GeoJSON的数据配置了它的外观,但是我无法设置text属性的值.

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.

这就是我试图在 mapView(_ mapView:MGLMapView,didFinishLoading style:MGLStyle)方法中进行的方式:

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

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

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

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

推荐答案

我看到您还打开了问题.谢谢你我在这里回应,但也想在此跟进.

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")

这篇关于MGLSymbolStyleLayer文字未显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆