Closed amenzone closed 4 years ago
Hey @amenzone - this example achieves the same thing as the GL JS example. You could speed up the rate at which timer fires to make the animation more smooth. Hope this helps!
Thank you very much for your help @captainbarbosa `
func mapView(_ mapView: MGLMapView, didFinishLoading style: MGLStyle) {
self.point.coordinate = CLLocationCoordinate2D(latitude: 39.97591419, longitude: 116.3397758)
shapeSource = MGLShapeSource(identifier: "wanderdrone", shape: point, options: nil)
style.addSource(shapeSource)
let droneLayer = MGLSymbolStyleLayer(identifier: "wanderdrone", source: shapeSource)
droneLayer.iconImageName = NSExpression(forConstantValue: "rocket-15")
droneLayer.iconHaloColor = NSExpression(forConstantValue: UIColor.red)
style.addLayer(droneLayer)
}
`
Change coordinates
point.coordinate = coordinate
shapeSource.shape = point
This is currently the best. I want to use my own image, how do I set it up, can I add directions to the movement
Here's how you can use a custom image for the icon: https://docs.mapbox.com/ios/maps/examples/add-marker-symbol/
The movement is up to you - you will need to form a path that the source data can iterate through. This can be calculated (like in the GL JS example), or it can be pre-defined (as in this example, which simulates responses from an external API).
Animate a point for iOS :https://docs.mapbox.com/mapbox-gl-js/example/animate-point-along-line/