-
addSource(id, source)
-
Adds a source to the map's style.
Parameters:
| Name |
Type |
Description |
id |
String
|
The ID of the source to add. Must not conflict with existing sources. |
source |
Object
|
The source object, conforming to the
Mapbox Style Specification's [source definition](https://www.mapbox.com/mapbox-gl-style-spec/#sources) |
Returns:
-
Type
-
VectorTileLayer
Example
vectorTileLayer.addSource('my-data', {
type: 'vector',
url: 'http://myusername.tilesetid'
});
-
addStyleLayer(layerObject [, before], options)
-
添加样式图层
Parameters:
| Name |
Type |
Argument |
Description |
layerObject |
Object
|
|
The style layer to add. |
before |
string
|
<optional>
|
ID of an existing layer to insert before. |
options |
Object
|
|
Style setter options. |
Returns:
The VectorTileLayer object.
-
Type
-
VectorTileLayer
-
addTo(map)
-
将图层添加到图层管理器中
Parameters:
- Inherited From:
-
- Overrides:
-
dispatchEvent(event)
-
在此事件派发器上派发事件.
Parameters:
| Name |
Type |
Description |
event |
Object
|
待派发的事件. |
- Inherited From:
-
- Overrides:
-
dispose()
-
释放资源
-
flyTo()
-
摄像机定位到图层
-
getFeatureState(feature)
-
Gets the `state` of a feature.
A feature's `state` is a set of user-defined key-value pairs that are assigned to a feature at runtime.
Features are identified by their `id` attribute, which can be any number or string.
_Note: To access the values in a feature's state object for the purposes of styling the feature, use the [`feature-state` expression](https://docs.mapbox.com/mapbox-gl-js/style-spec/expressions/#feature-state)_.
Parameters:
| Name |
Type |
Description |
feature |
Object
|
Feature identifier. Feature objects returned from
VectorTileLayer#queryRenderedFeatures or event handlers can be used as feature identifiers.
Properties
| Name |
Type |
Argument |
Description |
id |
number
|
string
|
|
Unique id of the feature. Can be an integer or a string, but supports string values only when the [`promoteId`](https://docs.mapbox.com/mapbox-gl-js/style-spec/sources/#vector-promoteId) option has been applied to the source or the string can be cast to an integer. |
source |
string
|
|
The id of the vector or GeoJSON source for the feature. |
sourceLayer |
string
|
<optional>
|
(optional) *For vector tile sources, `sourceLayer` is required*. |
|
Returns:
The state of the feature: a set of key-value pairs that was assigned to the feature at runtime.
-
Type
-
VectorTileLayer
Example
// get the feature state for the feature under the mouse
if (e.features.length > 0) {
map.getFeatureState({
source: 'my-source',
sourceLayer: 'my-source-layer',
id: e.features[0].id
});
}
-
getFilter(id)
-
获取指定图层的过滤.
Parameters:
| Name |
Type |
Description |
id |
string
|
图层ID. |
Returns:
The layer's filter.
-
Type
-
Array
Example
const filter = vectorTileLayer.getFilter('myLayer');
-
getLayoutProperty(id, name)
-
获取指定图层的布局属性
Parameters:
| Name |
Type |
Description |
id |
String
|
样式图层ID |
name |
String
|
属性名称 |
Returns:
指定的布局属性
-
Type
-
*
-
getPaintProperty(id, name)
-
获取指定图层的绘制属性
Parameters:
| Name |
Type |
Description |
id |
String
|
样式图层ID |
name |
String
|
属性名称 |
Returns:
指定的绘制属性
-
Type
-
*
-
getParentId()
-
获取父节点ID
- Inherited From:
-
- Overrides:
Returns:
父节点ID
-
Type
-
String
-
getSource(id)
-
Returns the source with the specified ID in the vectorTileLayer's style.
This method is often used to update a source using the instance members for the relevant
source type as defined in [Sources](#sources).
Parameters:
| Name |
Type |
Description |
id |
String
|
The ID of the source to get. |
Returns:
The style source with the specified ID or `undefined` if the ID
corresponds to no existing sources.
The shape of the object varies by source type.
A list of options for each source type is available on the Mapbox Style Specification's
[Sources](https://docs.mapbox.com/mapbox-gl-js/style-spec/sources/) page.
-
Type
-
Object
Example
const sourceObject = vectorTileLayer.getSource('points');
-
getStyle()
-
获取样式
Returns:
The vectortilelayer's style JSON object
-
Type
-
Object
Example
vectorTileLayer.on(Glodon.CIMCube.Global.Defines.LayerEventType.LOADED, () => {
const styleJson = vectorTileLayer.getStyle();
});
-
getStyleLayer(id)
-
获取样式图层
Parameters:
| Name |
Type |
Description |
id |
String
|
图层ID |
Returns:
样式图层
-
Type
-
StyleLayer
-
hasStyleLayer(id)
-
是否存在样式图层
Parameters:
| Name |
Type |
Description |
id |
string
|
ID of the desired layer. |
Returns:
A boolean specifying if the given layer is present.
-
Type
-
boolean
-
moveStyleLayer(id [, before])
-
移动样式图层
Parameters:
| Name |
Type |
Argument |
Description |
id |
string
|
|
ID of the layer to move. |
before |
string
|
<optional>
|
ID of an existing layer to insert before. |
-
queryRenderedFeatures( [geometry] [, options])
-
Parameters:
| Name |
Type |
Argument |
Description |
geometry |
Array
|
<optional>
|
查询区域的几何图形(单位为像素) |
options |
Object
|
<optional>
|
选项对象
Properties
| Name |
Type |
Argument |
Default |
Description |
layers |
Array.<string>
|
<optional>
|
|
查询样式图层 |
filter |
Array
|
<optional>
|
|
用来限制查询结果 |
validate |
boolean
|
<optional>
|
true
|
Whether to check if the [options.filter] conforms to the Mapbox GL Style Specification. Disabling validation is a performance optimization that should only be used if you have previously validated the values you will be passing to this function. |
|
Returns:
对象数据
-
Type
-
Array.<Object>
Example
// Find all features within a static bounding box
const features = layer.queryRenderedFeatures(
[[10, 20], [30, 50]],
{layers: ['my-layer-name']}
);
-
removeDragHandle()
-
在场景中移除操作句柄
- Inherited From:
-
- Overrides:
-
removeFeatureState(feature, key)
-
Removes the `state` of a feature, setting it back to the default behavior.
If only a `feature.source` is specified, it will remove the state for all features from that source.
If `feature.id` is also specified, it will remove all keys for that feature's state.
If `key` is also specified, it removes only that key from that feature's state.
Features are identified by their `feature.id` attribute, which can be any number or string.
Parameters:
| Name |
Type |
Description |
feature |
Object
|
Identifier of where to remove state. It can be a source, a feature, or a specific key of feature.
Feature objects returned from VectorTileLayer#queryRenderedFeatures or event handlers can be used as feature identifiers.
Properties
| Name |
Type |
Argument |
Description |
id |
number
|
string
|
|
Unique id of the feature. Can be an integer or a string, but supports string values only when the [`promoteId`](https://docs.mapbox.com/mapbox-gl-js/style-spec/sources/#vector-promoteId) option has been applied to the source or the string can be cast to an integer. |
source |
string
|
|
The id of the vector or GeoJSON source for the feature. |
sourceLayer |
string
|
<optional>
|
(optional) For vector tile sources, `sourceLayer` is required. |
|
key |
string
|
(optional) The key in the feature state to reset. |
Returns:
Returns itself to allow for method chaining.
-
Type
-
VectorTileLayer
Examples
// Reset the entire state object for all features
// in the `my-source` source
layer.removeFeatureState({
source: 'my-source'
});
// reset the entire state object for the feature
map.removeFeatureState({
source: 'my-source',
sourceLayer: 'my-source-layer',
id: e.features[0].id
});
// reset only the `hover` key-value pair in the state for the feature
map.removeFeatureState({
source: 'my-source',
sourceLayer: 'my-source-layer',
id: e.features[0].id
}, 'hover');
-
removeSource(id)
-
Removes a source from the vectorTileLayer's style.
Parameters:
| Name |
Type |
Description |
id |
String
|
The ID of the source to remove. |
Returns:
Returns itself to allow for method chaining.
-
Type
-
VectorTileLayer
Example
vectorTileLayer.removeSource('bathymetry-data');
-
removeStyleLayer(id)
-
移除样式图层
Parameters:
| Name |
Type |
Description |
id |
string
|
ID of the layer to remove. |
-
setFeatureState(feature, state)
-
Sets the `state` of a feature.
A feature's `state` is a set of user-defined key-value pairs that are assigned to a feature at runtime.
When using this method, the `state` object is merged with any existing key-value pairs in the feature's state.
Features are identified by their `id` attribute, which can be any number or string.
Parameters:
| Name |
Type |
Description |
feature |
Object
|
Feature identifier. Feature objects returned from
VectorTileLayer#queryRenderedFeatures or event handlers can be used as feature identifiers.
Properties
| Name |
Type |
Argument |
Description |
id |
number
|
string
|
|
Unique id of the feature. Can be an integer or a string, but supports string values only when the [`promoteId`](https://docs.mapbox.com/mapbox-gl-js/style-spec/sources/#vector-promoteId) option has been applied to the source or the string can be cast to an integer. |
source |
string
|
|
The id of the vector or GeoJSON source for the feature. |
sourceLayer |
string
|
<optional>
|
(optional) *For vector tile sources, `sourceLayer` is required*. |
|
state |
Object
|
A set of key-value pairs. The values should be valid JSON types. |
Returns:
Returns itself to allow for method chaining.
-
Type
-
VectorTileLayer
Example
layer.setFeatureState({
source: 'my-source',
sourceLayer: 'my-source-layer',
id: e.features[0].id,
}, {
hover: true
});
-
setFilter(id, filter [, options])
-
设置过滤
Parameters:
| Name |
Type |
Argument |
Description |
id |
string
|
|
图层ID. |
filter |
Array
|
null
|
undefined
|
|
过滤表达式. |
options |
Object
|
<optional>
|
选项.
Properties
| Name |
Type |
Argument |
Default |
Description |
validate |
boolean
|
<optional>
|
true
|
Whether to check if the filter conforms to the Mapbox GL Style Specification. Disabling validation is a performance optimization that should only be used if you have previously validated the values you will be passing to this function. |
|
Returns:
Returns itself to allow for method chaining.
-
Type
-
VectorTileLayer
Example
// display only features with the 'name' property 'USA'
vectorTileLayer.setFilter('my-layer', ['==', ['get', 'name'], 'USA']);
-
<async> setLayoutProperty(id, name, value, options)
-
设置样式图层的布局属性
Parameters:
| Name |
Type |
Description |
id |
String
|
样式图层ID |
name |
String
|
属性名称 |
value |
*
|
属性值 |
options |
Object
|
选项 |
Returns:
Returns itself to allow for method chaining.
-
Type
-
VectorTileLayer
-
<async> setPaintProperty(id, name, value, options)
-
设置指定图层的绘制属性
Parameters:
| Name |
Type |
Description |
id |
String
|
样式图层ID |
name |
String
|
属性名称 |
value |
*
|
属性值 |
options |
Object
|
选项 |
Returns:
Returns itself to allow for method chaining.
-
Type
-
VectorTileLayer