The above sequence results in no new polyline on the map.
Point features added to the map in this way work correctly. Polygons appear to be broken as well.
The code below demonstrates this issue. The temple icon appears on the map, but the red line does not.
[Export("mapView:didFinishLoadingStyle:")]
public void MapViewDidFinishLoadingStyle(MGLMapView mapView, MGLStyle style)
{
var coordinates = new CLLocationCoordinate2D[] {
new CLLocationCoordinate2D(latitude: mapView.CenterCoordinate.Latitude + 0.03, longitude: mapView.CenterCoordinate.Longitude - 0.02),
new CLLocationCoordinate2D(latitude: mapView.CenterCoordinate.Latitude + 0.02, longitude: mapView.CenterCoordinate.Longitude - 0.03),
new CLLocationCoordinate2D(latitude: mapView.CenterCoordinate.Latitude, longitude: mapView.CenterCoordinate.Longitude - 0.02),
new CLLocationCoordinate2D(latitude: mapView.CenterCoordinate.Latitude -0.01, longitude: mapView.CenterCoordinate.Longitude),
new CLLocationCoordinate2D(latitude: mapView.CenterCoordinate.Latitude -0.04, longitude: mapView.CenterCoordinate.Longitude + 0.01),
new CLLocationCoordinate2D(latitude: mapView.CenterCoordinate.Latitude -0.04, longitude: mapView.CenterCoordinate.Longitude + 0.04)
};
var polyline = new MGLPolylineFeature();
polyline.AppendCoordinates(ref coordinates[0], (nuint)coordinates.Length);
var temple = new MGLPointFeature();
temple.Coordinate = new CLLocationCoordinate2D(21.0276, 105.8355);
var shapes = new MGLShape[] { polyline, temple };
var source = new MGLShapeSource("test", new MGLShape[0], null);
style.AddSource(source);
var lineStyleLayer = new MGLLineStyleLayer("test-line", source);
lineStyleLayer.LineColor = NSExpression.FromConstant(UIColor.Red);
lineStyleLayer.LineWidth = NSExpression.FromConstant(NSNumber.FromDouble(5.0));
style.AddLayer(lineStyleLayer);
var templeImage = UIImage.FromBundle("temple");
templeImage = templeImage.ImageWithAlignmentRectInsets(new UIEdgeInsets(0, 0, templeImage.Size.Height / 2, 0));
style.SetImage(templeImage, "temple");
var symbolStyleLayer = new MGLSymbolStyleLayer("test-symbol", source);
symbolStyleLayer.IconImageName = NSExpression.FromConstant(new NSString("temple"));
symbolStyleLayer.IconOpacity = NSExpression.FromConstant(NSNumber.FromDouble(0.7));
style.AddLayer(symbolStyleLayer);
var shapeCollectionFeature = MGLShapeCollectionFeature.ShapeCollectionWithShapes(shapes);
source.Shape = shapeCollectionFeature;
}
func mapView(_ mapView: MGLMapView, didFinishLoading style: MGLStyle) {
var coordinates: [CLLocationCoordinate2D] = [
CLLocationCoordinate2D(latitude: mapView.centerCoordinate.latitude + 0.03, longitude: mapView.centerCoordinate.longitude - 0.02),
CLLocationCoordinate2D(latitude: mapView.centerCoordinate.latitude + 0.02, longitude: mapView.centerCoordinate.longitude - 0.03),
CLLocationCoordinate2D(latitude: mapView.centerCoordinate.latitude, longitude: mapView.centerCoordinate.longitude - 0.02),
CLLocationCoordinate2D(latitude: mapView.centerCoordinate.latitude - 0.01, longitude: mapView.centerCoordinate.longitude),
CLLocationCoordinate2D(latitude: mapView.centerCoordinate.latitude - 0.04, longitude: mapView.centerCoordinate.longitude + 0.01),
CLLocationCoordinate2D(latitude: mapView.centerCoordinate.latitude - 0.04, longitude: mapView.centerCoordinate.longitude + 0.04)
]
let polyline = MGLPolylineFeature(coordinates: &coordinates, count: UInt(coordinates.count))
let temple = MGLPointFeature()
temple.coordinate = CLLocationCoordinate2D(latitude: 21.0276, longitude: 105.8355)
let shapes: [MGLShape] = [ polyline, temple ]
let source = MGLShapeSource(identifier: "test", shapes: [MGLShape](), options: nil)
style.addSource(source)
let lineStyleLayer = MGLLineStyleLayer(identifier: "test-line", source: source)
lineStyleLayer.lineColor = NSExpression.init(forConstantValue: UIColor.red)
lineStyleLayer.lineWidth = NSExpression.init(forConstantValue: 5.0)
style.addLayer(lineStyleLayer)
var templeImage = UIImage.init(named: "temple")
templeImage = templeImage?.withAlignmentRectInsets(UIEdgeInsets(top: 0, left: 0, bottom: templeImage?.size.height ?? 0 / 2, right: 0))
style.setImage(templeImage ?? UIImage(), forName: "temple")
let symbolStyleLayer = MGLSymbolStyleLayer(identifier: "test-symbol", source: source)
symbolStyleLayer.iconImageName = NSExpression.init(forConstantValue: "temple")
symbolStyleLayer.iconOpacity = NSExpression.init(forConstantValue: 0.7)
style.addLayer(symbolStyleLayer);
let shapeCollectionFeature = MGLShapeCollectionFeature.init(shapes: shapes)
source.shape = shapeCollectionFeature;
}