Mapbox : MGLSymbolStyleLayer 添加我的自定义 "iconImage"
Mapbox : MGLSymbolStyleLayer add my custom "iconImage"
如何为 MGLSymbolStyleLayer
添加自定义图像。下面是我的代码,
let symbolGraphicsLayer = MGLSymbolStyleLayer(identifier: identifier, source: source)
symbolGraphicsLayer.sourceLayerIdentifier = identifier
symbolGraphicsLayer.iconImageName = MGLStyleConstantValue<NSString>(rawValue: "assets/myImage")
symbolGraphicsLayer.iconScale = MGLStyleValue(rawValue: 1)
symbolGraphicsLayer.isVisible = true
self.mapView.style?.addLayer(symbolGraphicsLayer)
谢谢。
您的问题是图片不显示吗?
首先需要将图片添加到样式层,然后就可以使用了。
因此,在该代码之前,您可以执行以下操作:
if let image = UIImage(named: "myImage") {
mapView.style?.setImage(image, forName: "myImage")
}
然后你就可以像你说的那样用了。只需使用您传递给 setImage 方法的名称。
我希望这对其他人有帮助,因为这方面的文档很差
如何为 MGLSymbolStyleLayer
添加自定义图像。下面是我的代码,
let symbolGraphicsLayer = MGLSymbolStyleLayer(identifier: identifier, source: source)
symbolGraphicsLayer.sourceLayerIdentifier = identifier
symbolGraphicsLayer.iconImageName = MGLStyleConstantValue<NSString>(rawValue: "assets/myImage")
symbolGraphicsLayer.iconScale = MGLStyleValue(rawValue: 1)
symbolGraphicsLayer.isVisible = true
self.mapView.style?.addLayer(symbolGraphicsLayer)
谢谢。
您的问题是图片不显示吗? 首先需要将图片添加到样式层,然后就可以使用了。 因此,在该代码之前,您可以执行以下操作:
if let image = UIImage(named: "myImage") {
mapView.style?.setImage(image, forName: "myImage")
}
然后你就可以像你说的那样用了。只需使用您传递给 setImage 方法的名称。
我希望这对其他人有帮助,因为这方面的文档很差