Class: VectorTile

ol/source/VectorTile~VectorTile


import VectorTile from 'ol/source/VectorTile.js';

Class for layer sources providing vector data divided into a tile grid, to be used with VectorTileLayer. Although this source receives tiles with vector features from the server, it is not meant for feature editing. Features are optimized for rendering, their geometries are clipped at or near tile boundaries and simplified for a view resolution. See VectorSource for vector sources that are suitable for feature editing.

new VectorTile(options)

Name Type Description
attributions AttributionLike | undefined

归属信息。

attributionsCollapsible boolean (defaults to true)

归属信息是否可折叠。

cacheSize number | undefined

初始瓦片缓存大小。将自动增长以至少容纳视口中瓦片数量的两倍。

extent Extent | undefined

范围。

format 要素Format<要素Type> | undefined

瓦片的要素格式。默认使用并要求提供。

overlaps boolean (defaults to true)

此数据源可能有重叠的几何图形。将此设置为 false(例如对于表示行政边界多边形的数据源或 TopoJSON 数据源)允许渲染器优化填充和描边操作。

projection ProjectionLike (defaults to 'EPSG:3857')

瓦片数据源的投影。

state State | undefined

数据源状态。

tileClass Class<VectorTile> | undefined

用于实例化瓦片的类。默认为 VectorTile

maxZoom number (defaults to 22)

可选的最大缩放级别。如果提供了 tileGrid 则不使用。

minZoom number | undefined

可选的最小缩放级别。如果提供了 tileGrid 则不使用。

tileSize number | Size (defaults to 512)

可选的瓦片尺寸。如果提供了 tileGrid 则不使用。

maxResolution number | undefined

可选的零级别瓦片网格分辨率。如果提供了 tileGrid 则不使用。

tileGrid TileGrid | undefined

瓦片网格。

tileLoad函数 Load函数 | undefined

给定 URL 加载瓦片的可选函数。对于 pbf 瓦片可能如下:

function(tile, url) {
  tile.setLoader(function(extent, resolution, projection) {
    fetch(url).then(function(response) {
      response.arrayBuffer().then(function(data) {
        const format = tile.getFormat() // ol/format/MVT configured as source format
        const features = format.read要素s(data, {
          extent: extent,
          featureProjection: projection
        });
        tile.set要素s(features);
      });
    });
  });
}

如果您不需要范围、分辨率和投影来获取瓦片的要素(例如 GeoJSON 瓦片),您的 tileLoad函数 不需要调用 setLoader()。只需确保在瓦片上调用 set要素s()

const format = new GeoJSON({featureProjection: map.getView().getProjection()});
async function tileLoad函数(tile, url) {
  const response = await fetch(url);
  const data = await response.json();
  tile.set要素s(format.read要素s(data));
}
tileUrl函数 Url函数 | undefined

给定瓦片坐标和投影获取瓦片 URL 的可选函数。

url string | undefined

URL 模板。必须包含 {x}{y}{-y},以及 {z} 占位符。可以使用 {?-?} 模板模式(例如 subdomain{a-f}.domain.com)来代替在 urls 选项中逐个定义。

transition number | undefined

瓦片不透明度过渡的持续时间(毫秒)。持续时间为 0 将禁用不透明度过渡。

urls Array.<string> | undefined

URL 模板数组。

wrapX boolean (defaults to true)

是否水平环绕世界。设置为 false 时,仅渲染一个世界。设置为 true 时,瓦片将水平包裹以渲染多个世界。

zDirection number | NearestDirection函数 (defaults to 1)

选择在整数缩放级别之间使用更高还是更低缩放级别的瓦片。参见 getZForResolution

触发事件:

Subclasses

Extends

Methods

增加修订计数器并分发 'change' 事件。

移除数据源中所有缓存的重投影瓦片。下一个渲染周期将创建新的瓦片。

dispatchEvent(event){boolean | undefined} inherited

分发事件并调用所有监听此类型事件的监听器。事件参数可以是一个字符串或一个 具有 type 属性的对象。

Name Type Description
event BaseEvent | string

事件对象。

返回值:
如果有人在事件对象上调用了 preventDefault 或任何监听器返回 false,则返回 false

获取一个值。

Name Type Description
key string

键名。

返回值:
值。

获取数据源的归属函数。

返回值:
Attribution function.

getAttributionsCollapsible(){boolean} inherited

返回值:
归属信息是否可折叠。

getKeys(){Array.<string>} inherited

获取对象属性名列表。

返回值:
属性名列表。

getProjection(){Projection | null} inherited

获取数据源的投影。

返回值:
投影。

getProperties(){NoInfer.<Properties>} inherited

获取包含所有属性名和值的对象。

返回值:
对象。

getRevision(){number} inherited

获取此对象的版本号。 每次对象被修改时,其版本号将递增。

返回值:
版本号。

获取数据源的状态,可能的状态参见 State。

返回值:
状态。

getTileGrid(){TileGrid | null} inherited

返回瓦片数据源的瓦片网格。

返回值:
瓦片网格。

已弃用。 请改用 ImageTile 数据源。 返回数据源的瓦片加载函数。

返回值:
TileLoad函数

已弃用。 请改用 ImageTile 数据源。 返回数据源的瓦片 URL 函数。

返回值:
TileUrl函数

getUrls(){!Array.<string> | null} inherited

已弃用。 请改用 ImageTile 数据源。 返回此数据源使用的 URL。 当使用 tileUrl函数 时ad of url or urls, null will be returned.

返回值:
URL 列表。

on(type, listener){EventsKey | Array<EventsKey>} inherited

监听特定类型的事件。

Name Type Description
type string | Array.<string>

事件类型或事件类型数组。

listener function

监听器函数。

返回值:
监听器的唯一键。如果第一个参数是事件类型数组,则返回键的数组。

once(type, listener){EventsKey | Array<EventsKey>} inherited

仅监听一次特定类型的事件。

Name Type Description
type string | Array.<string>

事件类型或事件类型数组。

listener function

监听器函数。

返回值:
监听器的唯一键。如果第一个参数是事件类型数组,则返回键的数组。

set(key, value, silent) inherited

设置一个值。

Name Type Description
key string

键名。

value *

值。

silent boolean | undefined

更新但不触发事件。

setAttributions(attributions) inherited

设置数据源的归属信息。

Name Type Description
attributions AttributionLike | undefined

归属信息。可以作为字符串、Array<string>、Attribution 或 undefined 传入。

setProperties(values, silent) inherited

设置一组键值对。 注意,这会更改任何现有属性并添加新属性(不会移除任何现有属性)。

Name Type Description
values Partial.<NoInfer.<Properties>>

值。

silent boolean | undefined

更新但不触发事件。

setTileLoad函数(tileLoad函数) inherited

已弃用。 请改用 ImageTile 数据源。 设置数据源的瓦片加载函数。

Name Type Description
tileLoad函数 Load函数

瓦片加载函数。

setTileUrl函数(tileUrl函数, key) inherited

已弃用。 请改用 ImageTile 数据源。 设置数据源的瓦片 URL 函数。

Name Type Description
tileUrl函数 Url函数

瓦片 URL 函数。

key string | undefined

数据源的可选新瓦片键。

设置用于请求的 URL。

Name Type Description
url string

URL.

已弃用。 请改用 ImageTile 数据源。 设置用于请求的 URL。

Name Type Description
urls Array.<string>

URL 列表。

un(type, listener) inherited

取消监听特定类型的事件。

Name Type Description
type string | Array.<string>

事件类型或事件类型数组。

listener function

监听器函数。

unset(key, silent) inherited

取消设置一个属性。

Name Type Description
key string

键名。

silent boolean | undefined

取消设置但不触发事件。