从 NSExpression 分配给 MGLStyleValue 的不兼容指针类型

Incompatible pointer types assigning to MGLStyleValue from NSExpression

我已经在我的应用程序中实现了 MAPBOX。我在自定义多段线颜色和宽度时遇到问题。这是我实现的代码。

MGLPolyline *polylineFirst = [MGLPolyline polylineWithCoordinates:routeCoordinates count:routeFirst.coordinateCount];

MGLShapeSource *source = [[MGLShapeSource alloc] initWithIdentifier:@"polyline" shape:polyline options:nil];
MGLLineStyleLayer *lineStyle = [[MGLLineStyleLayer alloc] initWithIdentifier:@"polyline" source:source];

lineStyle.lineColor = [NSExpression expressionForConstantValue:[UIColor yellowColor]];
lineStyle.lineWidth = [NSExpression expressionForConstantValue:@5];

[self.mapView.style addSource:source];
[self.mapView.style addLayer:lineStyle];

在 v4.0 中替换了表达式 style functions,看来您使用的是早期版本的 Maps SDK。

与您的代码等效的样式函数为:

   lineStyle.lineColor = [MGLStyleValue valueWithRawValue:[UIColor yellowColor]];
   lineStyle.lineWidth = [MGLStyleValue valueWithRawValue:@5];

您可能会发现 this sample code 有帮助。