Search code examples
iosmapboxpolyline

Incompatible pointer types assigning to MGLStyleValue from NSExpression


I have implement MAPBOX in my app. I have problem to customise Polyline color and width. here is the code that i have implement.

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];

enter image description here


Solution

  • Expressions replaced style functions in v4.0, It looks like you are using an earlier version of the Maps SDK.

    The style functions equivalent of your code would be:

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

    You may find this sample code helpful.