mapbox / ios-sdk-examples

Live example code for the Mapbox iOS SDK
https://www.mapbox.com/ios-sdk/examples/
Other
95 stars 35 forks source link

Animate a point #395

Closed amenzone closed 4 years ago

amenzone commented 4 years ago

Animate a point for iOS :https://docs.mapbox.com/mapbox-gl-js/example/animate-point-along-line/

captainbarbosa commented 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!

amenzone commented 4 years ago

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

captainbarbosa commented 4 years ago

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).