[英]How to draw dynamic GeoGJSON Point as a rectangle using Mapbox iOS SDK
我有一个具有远程 GeoJSON 源的 map 层。 我使用MGLCircleStyleLayer
MGLShapeCollectionFeature
MGLSymbolStyleLayer
来显示数据以及一些文本。
它按预期工作,并且这些点显示在 map 上:
数据
{
"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"
}
结果
现在的问题是是否可以将数据显示为圆角矩形而不仅仅是圆形。 像这样的东西:
这可以通过使用不是单个 position 而是使用圆角矩形形状的 position 阵列构建的多边形来完成。 这个矩形可以填充您想要显示的文本的图案。
加载填充图案:
// 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")
使用来自矢量源的图层(定义圆角矩形的位置多边形数组)
// 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示例
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.