我有一个具有远程GeoJSON源的地图图层。我使用MGLShapeCollectionFeature
将其添加到我的Mabpox映射中,然后使用MGLCircleStyleLayer
和MGLSymbolStyleLayer
来显示数据以及一些文本。
它可以正常工作,并且点显示在地图上:
数据
{
"features": [
{
"geometry": {
"coordinates": [
-120.644,
35.238
],
"type": "Point"
},
"properties": {
"altim": 1019.0,
"cover": "CLR",
"data": "METAR",
"dewp": 12.2,
"fltcat": "VFR",
"id": "KSBP",
"obsTime": "2020-05-03T18:56:00Z",
"prior": "5",
"rawOb": "KSBP 031856Z 31018KT 10SM CLR 22/12 A3009 RMK AO2 SLP187 T02170122",
"site": "San Luis Obispo/Ches",
"slp": 1018.7,
"temp": 21.7,
"visib": 10.00,
"wdir": 310,
"wspd": 18
},
"type": "Feature"
}
],
"type": "FeatureCollection"
}
结果
现在的问题是,是否可以将数据显示为圆角矩形而不是圆形。像这样的东西:
这不是通过使用单个位置,而是使用从位置数组构建为圆形矩形的多边形来完成的。该矩形可以填充有您要显示的文本的图案。
加载模式:
// Set the UIImage to be used for the fill pattern.
let fillPatternImage = UIImage(named: "stripe-pattern")!
// Add the fill pattern image to used by the style layer.
style.setImage(fillPatternImage, forName: "stripe-pattern")
带有来自矢量源的图层(定义圆角矩形的Positions Polygon数组)
// Create a style layer using the vector source.
let layer = MGLFillStyleLayer(identifier: "drone-restrictions-style", source: source)
添加填充图案并设置图案的不透明度:
layer.fillPattern = NSExpression(forConstantValue: "stripe-pattern")
layer.fillOpacity = NSExpression(forConstantValue: 0.5)
使用单独的图层在圆角矩形上绘制文本。
也请参考此Mapbox example