1

是否可以使用 MGLSymbolStyleLayer 的 iconRotation 属性为我的标记旋转设置动画?或者有没有其他方法可以平滑地旋转我的标记?我只想平滑地旋转我的标记,到目前为止旋转很好,但它非常活泼。此外,我从服务器获得不同标记的不同方位,有什么方法可以仅使用 MGLPointAnnotation 旋转我的标记?我的用例是我想要不同标记的不同度数旋转(每个相同的图标)

let point = MGLPointAnnotation()
    point.coordinate = CLLocationCoordinate2D(latitude: 30.699335, longitude: 76.836422)
    let shapeSource = MGLShapeSource(identifier: "marker-source", shape: point, options: nil)
    shapeLayer = MGLSymbolStyleLayer(identifier: "marker-style", source: shapeSource)
    if let image = UIImage(named: "auto") {
        mapView.style?.setImage(image, forName: "auto")
    }
    shapeLayer?.iconImageName = NSExpression(forConstantValue: "auto")
        CATransaction.begin()
        CATransaction.setAnimationDuration(3.0)
        self.shapeLayer?.iconRotation = NSExpression(forConstantValue: 120.0)
        CATransaction.commit()
4

1 回答 1

0

您可以使用添加实时数据示例为 MGLSymbolStyleLayer 设置动画。您需要将 @objc 函数设置为 layer.iconRotation 并在每次执行该函数时更改该值。您也可以使用 MGLPointFeature 或 MGLPointAnnotation 作为 MGLSymbolStyleLayer 的源来执行相同操作。请查看此处的 Mapbox 添加标记和形状文档,了解支持的不同功能。

于 2020-07-24T10:52:23.877 回答