Class: MapboxStyles

ol.supermap.MapboxStyles

Mapbox vector tile style class.

Notice

This function depends ol-mapbox-style plugin, please confirm the introduction of the plugin.

<script type="text/javascript" src="https://rawgit.com/boundlessgeo/ol-mapbox-style/v2.11.2/dist/olms.js"></script>

new ol.supermap.MapboxStyles(options)

MapboxStyles.js, line 11
Name Type Description
options Object

Initialization parameters.

Name Type Description
url string | undefined optional

iServer UGCV5(MVT) Map service url, for example: 'http://localhost:8090/iserver/services/map-mvt-test/rest/maps/test', This parameter is mutually exclusive with options.style and has a lower priority than options.style.

style Object | undefined optional

Mapbox style object. Mutually exclusive with options.url, with a higher priority than options.url.

resolutions Array.<number> optional

An array of map resolutions used to map zoom values. Usually the resolution is the same as the resolution of the map's ol.View.
The default is: [78271.51696402048,39135.75848201024, 19567.87924100512,9783.93962050256,4891.96981025128,2445.98490512564, 1222.99245256282,611.49622628141,305.748113140705,152.8740565703525, 76.43702828517625,38.21851414258813,19.109257071294063,9.554628535647032, 4.777314267823516,2.388657133911758,1.194328566955879,0.5971642834779395, 0.29858214173896974,0.14929107086948487,0.07464553543474244]。

source string | Array.<string> optional

The key value of the 'source' or the id array of the 'layer' of the Mapbox Style. When the key value of 'source' is configured, the layer whose source is the value will be loaded. When configured as an 'layer' id array, the specified layer will be loaded, noting that the specified layer needs to have the same source.

map ol.Map optional

The Openlayers map object is only used to fill the background in the Mapbox Style. If no background is configured, you can leave this parameter unset.

selectedStyle ol.StyleFunction optional

The selected style Function.

Example
var mbStyle = new ol.supermap.MapboxStyles({
            url: url,
            source: 'California',
            resolutions: [78271.51696402048,39135.75848201024, 19567.87924100512,9783.93962050256,4891.96981025128,2445.98490512564]
    })
    mbStyle.on('styleLoaded', function () {
           var vectorLayer = new ol.layer.VectorTile({
                //Set avoidance parameters
                declutter: true,
                source: new ol.source.VectorTileSuperMapRest({
                    url: url,
                    format: new ol.format.MVT({
                        featureClass: ol.Feature
                    }),
                    tileType: 'ScaleXY'
                }),
                style: mbStyle.featureStyleFuntion
            });
            map.addLayer(vectorLayer);
        })

Events

styleloaded

MapboxStyles.js, line 200

Triggered after the style is loaded successfully.

Methods

ol.supermap.MapboxStyles.getStyleFunction(){ol.FeatureStyleFunction}

MapboxStyles.js, line 102

Get the ol.FeatureStyleFunction.

Returns:
Type Description
ol.FeatureStyleFunction Return the ol.FeatureStyleFunction.

ol.supermap.MapboxStyles.getStylesBySourceLayer(sourceLayer)

MapboxStyles.js, line 110

Get the style based on the layer name.

Name Type Description
sourceLayer string

The data layer name.

setSelectedId(selectedId, sourceLayer)

MapboxStyles.js, line 129

Sets the selected feature, which will be drawn in the selectedStyle style.

Name Type Description
selectedId number

Feature ID.

sourceLayer string

The layer name of the feature.

setStyle(style)

MapboxStyles.js, line 170

Set the Mapbox style object.

Name Type Description
style Object

Mapbox style object.

Version:
  • 9.1.1

updateStyles(layerStyles)

MapboxStyles.js, line 141

Update the layer style.

Name Type Description
layerStyles Object

An array of layer styles or layer styles.