Reputation: 250
How can i add custom image for MGLSymbolStyleLayer
. Below is my code,
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)
Thanks.
Upvotes: 1
Views: 861
Reputation: 185
Is your problem that the image doesn't appear? You first need to add the image to the style layer, and then you can use it. So before that code, you can do:
if let image = UIImage(named: "myImage") {
mapView.style?.setImage(image, forName: "myImage")
}
and you can use it afterwards like you said. Just use the name you passed to the setImage method.
I hope this helps other people since the documentation is quite poor for this
Upvotes: 7