Overview -------- Code Example ^^^^^^^^^^^^ Quick example of module usage (API change): .. code-block:: java MBStyle style = MapBoxStyle.parse( reader ); StyleLayerDescriptor sld = style.transform(); Internally the extension provides greater access to the parsed style: .. code-block:: java MBStyle mbstyle = MapBoxStyleParser.parse( reader ); // pull back all layers for a provided source List layers = mbstyle.layers( "sf:roads" ); // pull back selected layers for a provided source List layers = mbstyle.layers( "sf:roads" ); // Which can be used to Generate a List of FeatureTypeStyles: List fts = layer.transform( style ); Zoom level tuning ^^^^^^^^^^^^^^^^^ The mapping between zoom levels and scale denominators is performed assuming, by default, a 512 pixels root tile at zoom level zero. This matches the usage of vector tiles client side. If a different value is to be used, it's possible to set a system property to change the default. E.g., the following would match "x4" tiles: .. code-block:: java System.setSystemProperty("MBSTYLE_ROOT_TILE_PIXELS", "1024") Example Snippets ^^^^^^^^^^^^^^^^ Before reading the :doc:`specification ` it is helpful to look at some example snippets showing the structure of a MapBox style document. *JSON does not allow for comments within these examples therefore comments will be noted through the placement of the comment between open ``<`` and close ``>`` angle brackets. All properties are optional unless otherwise noted as Requried* MapBox Style document snippet ''''''''''''''''''''''''''''' The root-properties structure of a MapBox Style document captures the document name, data sources uses, graphics (sprites and glyphs) avaialble, before finally documenting the layers to be shown. .. code-block:: text { "version": 8, "name": "Mapbox Streets", "sprite": "mapbox://sprites/mapbox/streets-v8", "glyphs": "mapbox://fonts/mapbox/{fontstack}/{range}.pbf", "sources": {...}, "layers": [...] } layers structure snippet '''''''''''''''''''''''' Layers are drawn in the order they appear in the layer array. Layers have two additional properties that determine how data is rendered: *layout* and *paint*. .. code-block:: text { "layers" : [ { "id": "string", "type": "...", "source": "test-source", "source-layer": "test-source-layer", "layout": {...}, "paint": {...}, } ] } background layer snippet '''''''''''''''''''''''' A `background` layer is used to define the background of map. You can only use one of `background-color` or `background-pattern` at a time. .. code-block:: text { "layers" : [ { "id": "backgroundcolor", "type": "background", "source": "test-source", "source-layer": "test-source-layer", "layout": { "visibility": "visible" }, "paint": { "background-opacity": 0.45, "background-color": "#00FF00" } } ] } fill layer snippet '''''''''''''''''''''''' A `fill` layer is used to draw polygons: .. code-block:: text { "layers": [ { "id": "testid", "type": "fill", "source": "geoserver-states", "source-layer": "states", "layout": { "visibility": "visible" }, "paint": { "fill-antialias": "true", "fill-opacity": 0.84, "fill-color": "#FF595E", "fill-outline-color":"#1982C4", "fill-translate": [20,20], "fill-translate-anchor": "map", "fill-pattern": } } ] } line layer snippet '''''''''''''''''''''''' A `line` layer is used to draw linetrings: .. code-block:: javascript { "layers": [ { "id": "test-id", "type": "line", "source": "test-source", "source-layer": "test-source-layer", "layout": { "line-cap": "square", "line-join": "round", "line-mitre-limit": 2, "line-round-limit": 1.05, "visibility": "visible" }, "paint": { "line-color": "#0099ff", "line-opacity": 0.5, "line-translate": [3,3], "line-translate-anchor": "viewport", "line-width": 10, "line-gap-width": 8, "line-offset": 4, "line-blur": 2, "line-dasharray": [50, 50], "line-pattern": } } ], } symbol layer snippet '''''''''''''''''''' A `symbol` layer is used to draw an icon at each point location. This is by far the most complicated layer type as it is used for two distinct uses, to mark points with icons, and also to generate labels. .. code-block:: text { "layers": [ { "id": "test-id", "type": "symbol", "source": "test-source", "source-layer": "test-source-layer", "layout": { "symbol-placement": "", "symbol-spacing": "", "symbol-avoid-edges": "", "icon-allow-overlap": "", "icon-ignore-placement": "", "icon-optional": "", "icon-rotation-alignment": "", "icon-size": "", "icon-rotation-alignment": "", "icon-text-fit-padding": "", "icon-image": "", "icon-rotate": "", "icon-padding": "", "icon-keep-upright": "", "icon-offset": "", "text-pitch-alignment": "", "text-rotation-alignment": "", "text-field": "", "text-font": "", "text-size": "", "text-max-width": "", "text-line-height": "", "text-letter-spacing": "", "text-justify": "", "text-anchor": "", "text-max-angle": "", "text-rotate": "", "text-padding": "", "text-keep-upright": "", "text-transform": "", "text-offset": "", "text-allow-overlap": "", "text-ignore-placement": "", "text-optional": "", "visibility": "visible" }, "paint": { "icon-opacity": "", "icon-color": "", "icon-halo-color": "", "icon-halo-width": "", "icon-halo-blur": "", "icon-translate": "", "icon-translate-anchor": "", "text-opacity": "", "text-halo-color": "", "text-halo-width": "", "text-halo-blur": "", "text-translate": "", "text-translate-anchor": "" } } ], } raster layer snippet '''''''''''''''''''' A `raster` layer is used for image visualization: .. code-block:: text { "layers": [ { "id": "test-id", "type": "raster", "source": "test-source", "source-layer": "test-source-layer", "layout": { "visibility": "visible" }, "paint": { "raster-opacity": "", "raster-hue-rotate": "", "raster-brightness-min": "", "raster-brightness-max": "", "raster-saturation": "", "raster-contrast": "", "raster-fade-duration": "" } } ], } cricle layer snippet '''''''''''''''''''' A `circle` layer is used to draw a circle at each point location: .. code-block:: text { "layers": [ { "id": "test-id", "type": "raster", "source": "test-source", "source-layer": "test-source-layer", "layout": { "visibility": "visible" }, "paint": { "circle-radius": "", "circle-color": "", "circle-blur": "", "circle-opacity": "", "circle-translate": "", "circle-translate-anchor": "", "circle-pitch-scale": "", "circle-stroke-width": "", "circle-stroke-color": "", "circle-stroke-opacity": "", } } ] } fill-extrusion layer snippet '''''''''''''''''''''''''''' A `fill-extrusion` adds a shadow effect. .. code-block:: text { "layers": [ { "id": "test-id", "type": "fill-extrusion", "source": "test-source", "source-layer": "test-source-layer", "layout": { "visibility": "visible" }, "paint": { "fill-extrusion-opacity": "", "fill-extrusion-color": "", "fill-extrusion-translate": "", "fill-extrusion-translate-anchor": "", "fill-extrusion-pattern": "", "fill-extrusion-height": "", "fill-extrusion-base": "" } } ] }