Search code examples
mapboxmapbox-ios

Question about mglfillelayer and MGLLineStyleLayer


In mapbox_ios: 1. About MGLFillStyleLayer and MGLLineStyleLayer, how to set different styles (color, width, dotted line) for individual features.

  1. A scene: if it is a separate polyhedron with no connection between the two surfaces in different places, but it is a feature, if I want to add more polyhedron to modify the graph (add a point and connect the two sides), how to modify the graph?

Hope to get help, thank you!


Solution

  • To answer your first question, you can style individual features within a style layer based on feature attributes.

    Get started by adding the layers to your map. You could create your source, then style the layer's color based on the value in the feature attributes. Use the lineColor property for your MGLLineStyleLayer and fillColor to change the color of your MGLFillStyleLayer.

    For example:

            let layer = MGLLineStyleLayer(identifier: "layer", source: source)
            layer.lineColor = NSExpression(forKeyPath: "color")
            style.addLayer(layer)
    

    You can also create a dictionary with possible attribute values and the color you would like to use as values. This example shows that approach by using icon images.