1

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.

1 Answer 1

7

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

1

Your Answer

Reminder: Answers generated by Artificial Intelligence tools are not allowed on Stack Overflow. Learn more

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.