-
addSource(id, source)
-
向地图样式中添加数据源
Parameters:
| Name |
Type |
Description |
id |
String
|
要添加的数据源ID,不能与现有数据源冲突 |
source |
Object
|
数据源对象,需符合Mapbox样式规范的[数据源定义](http://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
|
|
要添加的样式图层对象 |
before |
string
|
<optional>
|
要插入到的现有图层ID之前 |
options |
Object
|
|
样式设置选项 |
Returns:
返回VectorTileLayer对象以支持链式调用
-
Type
-
VectorTileLayer
-
addTo(map)
-
将图层添加到图层管理器中
Parameters:
- Inherited From:
-
- Overrides:
-
dispatchEvent(event)
-
在此事件派发器上派发事件.
Parameters:
| Name |
Type |
Description |
event |
Object
|
待派发的事件. |
- Inherited From:
-
- Overrides:
-
dispose()
-
释放资源
-
flyTo()
-
摄像机定位到图层
-
getFeatureState(feature)
-
获取要素的状态
要素的`state`是一组用户定义的键值对,在运行时分配给要素。
要素通过其`id`属性标识,可以是任何数字或字符串。
_注意:要访问要素状态对象中的值以用于样式化要素,请使用[`feature-state`表达式](http://docs.mapbox.com/mapbox-gl-js/style-spec/expressions/#feature-state)_。
Parameters:
| Name |
Type |
Description |
feature |
Object
|
要素标识符。从VectorTileLayer#queryRenderedFeatures返回的要素对象或事件处理器可以用作要素标识符。
Properties
| Name |
Type |
Argument |
Description |
id |
number
|
string
|
|
要素的唯一ID。可以是整数或字符串,但仅当数据源应用了[`promoteId`](http://docs.mapbox.com/mapbox-gl-js/style-spec/sources/#vector-promoteId)选项或字符串可以转换为整数时才支持字符串值。 |
source |
string
|
|
要素的矢量或GeoJSON数据源ID |
sourceLayer |
string
|
<optional>
|
(可选)*对于矢量切片数据源,`sourceLayer`是必需的* |
|
Returns:
要素的状态:一组在运行时分配给要素的键值对
-
Type
-
Object
Example
// 获取鼠标下要素的状态
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:
图层的过滤表达式
-
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)
-
获取矢量切片图层样式中指定ID的数据源
此方法常用于使用数据源类型的实例成员来更新数据源,如[数据源](#sources)中定义的那样。
Parameters:
| Name |
Type |
Description |
id |
String
|
要获取的数据源ID |
Returns:
指定ID的样式数据源,如果ID不存在则返回`undefined`。
对象的形状因数据源类型而异。
每种数据源类型的选项列表可在Mapbox样式规范的[数据源](http://docs.mapbox.com/mapbox-gl-js/style-spec/sources/)页面查看。
-
Type
-
Object
Example
const sourceObject = vectorTileLayer.getSource('points');
-
getStyle()
-
获取样式
Returns:
矢量切片图层的样式JSON对象
-
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 |
Returns:
如果指定图层存在则返回true,否则返回false
-
Type
-
boolean
-
moveStyleLayer(id [, before])
-
移动样式图层
Parameters:
| Name |
Type |
Argument |
Description |
id |
string
|
|
要移动的图层ID |
before |
string
|
<optional>
|
要插入到的现有图层ID之前 |
Returns:
返回自身以支持链式调用
-
Type
-
VectorTileLayer
-
queryRenderedFeatures( [geometry] [, options])
-
查询渲染的要素
Parameters:
| Name |
Type |
Argument |
Description |
geometry |
Array
|
<optional>
|
查询区域的几何图形(单位为像素) |
options |
Object
|
<optional>
|
选项对象
Properties
| Name |
Type |
Argument |
Default |
Description |
layers |
Array.<string>
|
<optional>
|
|
要查询的样式图层ID数组 |
filter |
Array
|
<optional>
|
|
用来限制查询结果的过滤表达式 |
validate |
boolean
|
<optional>
|
true
|
是否检查[options.filter]是否符合Mapbox GL样式规范。禁用验证是一种性能优化,仅在您已预先验证将要传递给此函数的值时使用。 |
|
Returns:
查询到的要素对象数组
-
Type
-
Array.<Object>
Example
// 查找静态边界框内的所有要素
const features = layer.queryRenderedFeatures(
[[10, 20], [30, 50]],
{layers: ['my-layer-name']}
);
-
removeDragHandle()
-
在场景中移除操作句柄
- Inherited From:
-
- Overrides:
-
removeFeatureState(feature, key)
-
移除要素的状态,将其重置为默认行为
如果仅指定`feature.source`,将移除该数据源中所有要素的状态。
如果还指定了`feature.id`,将移除该要素状态的所有键。
如果还指定了`key`,则仅移除该要素状态中的该键。
要素通过其`feature.id`属性标识,可以是任何数字或字符串。
Parameters:
| Name |
Type |
Description |
feature |
Object
|
要移除状态的标识符。可以是数据源、要素或要素的特定键。
从VectorTileLayer#queryRenderedFeatures返回的要素对象或事件处理器可以用作要素标识符。
Properties
| Name |
Type |
Argument |
Description |
id |
number
|
string
|
|
要素的唯一ID。可以是整数或字符串,但仅当数据源应用了[`promoteId`](http://docs.mapbox.com/mapbox-gl-js/style-spec/sources/#vector-promoteId)选项或字符串可以转换为整数时才支持字符串值。 |
source |
string
|
|
要素的矢量或GeoJSON数据源ID |
sourceLayer |
string
|
<optional>
|
(可选)对于矢量切片数据源,`sourceLayer`是必需的 |
|
key |
string
|
(可选)要重置的要素状态中的键 |
Returns:
返回自身以支持链式调用
-
Type
-
VectorTileLayer
Examples
// 重置`my-source`数据源中所有要素的整个状态对象
layer.removeFeatureState({
source: 'my-source'
});
// 重置要素的整个状态对象
map.removeFeatureState({
source: 'my-source',
sourceLayer: 'my-source-layer',
id: e.features[0].id
});
// 仅重置要素状态中的`hover`键值对
map.removeFeatureState({
source: 'my-source',
sourceLayer: 'my-source-layer',
id: e.features[0].id
}, 'hover');
-
removeSource(id)
-
从矢量切片图层的样式中移除数据源
Parameters:
| Name |
Type |
Description |
id |
String
|
要移除的数据源ID |
Returns:
返回自身以支持链式调用
-
Type
-
VectorTileLayer
Example
vectorTileLayer.removeSource('bathymetry-data');
-
removeStyleLayer(id)
-
移除样式图层
Parameters:
| Name |
Type |
Description |
id |
string
|
要移除的图层ID |
Returns:
返回自身以支持链式调用
-
Type
-
VectorTileLayer
-
setFeatureState(feature, state)
-
设置要素的状态
要素的`state`是一组用户定义的键值对,在运行时分配给要素。
使用此方法时,`state`对象将与要素状态中的任何现有键值对合并。
要素通过其`id`属性标识,可以是任何数字或字符串。
Parameters:
| Name |
Type |
Description |
feature |
Object
|
要素标识符。从VectorTileLayer#queryRenderedFeatures返回的要素对象或事件处理器可以用作要素标识符。
Properties
| Name |
Type |
Argument |
Description |
id |
number
|
string
|
|
要素的唯一ID。可以是整数或字符串,但仅当数据源应用了[`promoteId`](http://docs.mapbox.com/mapbox-gl-js/style-spec/sources/#vector-promoteId)选项或字符串可以转换为整数时才支持字符串值。 |
source |
string
|
|
要素的矢量或GeoJSON数据源ID |
sourceLayer |
string
|
<optional>
|
(可选)*对于矢量切片数据源,`sourceLayer`是必需的* |
|
state |
Object
|
一组键值对。值应为有效的JSON类型。 |
Returns:
返回自身以支持链式调用
-
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
|
是否检查过滤表达式是否符合Mapbox GL样式规范。禁用验证是一种性能优化,仅在您已预先验证将要传递给此函数的值时使用。 |
|
Returns:
返回自身以支持链式调用
-
Type
-
VectorTileLayer
Example
// 仅显示'name'属性为'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:
返回自身以支持链式调用
-
Type
-
VectorTileLayer
-
<async> setPaintProperty(id, name, value, options)
-
设置指定图层的绘制属性
Parameters:
| Name |
Type |
Description |
id |
String
|
样式图层ID |
name |
String
|
属性名称 |
value |
*
|
属性值 |
options |
Object
|
选项 |
Returns:
返回自身以支持链式调用
-
Type
-
VectorTileLayer