-
Name Type Description attributionsAttributionLike | undefined 归属信息。
featuresArray.<要素Type> | Collection<要素Type> | undefined 要素集合。如果作为 Collection 提供,数据源中的要素和集合将保持同步。
format要素Format<要素Type> | undefined 设置
url时 XHR 要素加载器使用的要素格式。如果设置了url则必需,否则忽略。loader要素Loader<要素Type> | undefined 用于加载要素的加载器函数,例如从远程数据源加载。如果未设置且设置了
url,数据源将创建并使用 XHR 要素加载器。'featuresloadend'和'featuresloaderror'事件仅在使用success和failure回调时触发。示例:
import Vector from 'ol/source/Vector.js'; import GeoJSON from 'ol/format/GeoJSON.js'; import {bbox} from 'ol/loadingstrategy.js'; const vectorSource = new Vector({ loader: async (extent, resolution, projection) => { const url = 'https://ahocevar.com/geoserver/wfs?service=WFS&' + 'version=1.1.0&request=Get要素&typename=osm:water_areas&' + 'outputFormat=application/json' + 'bbox=' + extent.join(',') + ',' + projection.getCode(); const response = await fetch(url); if (!response.ok) { throw new Error('Network response was not ok'); } const json = await response.json(); const features = new GeoJSON().read要素s(json, { featureProjection: projection, }); return features; }, strategy: bbox, });当您想要重试失败的请求时,请使用
vector数据源。removeLoadedExtent(extent); vector数据源。changed();overlapsboolean (defaults to true) 此数据源可能有重叠的几何图形。将此设置为
false(例如对于表示行政边界的面数据源或 TopoJSON 数据源)允许渲染器优化填充和描边操作。strategyLoadingStrategy | undefined 要使用的加载策略。默认使用
all策略,即一次性加载所有要素的策略。urlstring | featureUrlFunction | undefined Setting this option instructs the source to load features using an XHR loader (see
xhr). Use astringand anallfor a one-off download of all features from the given URL. Use afeatureUrlFunctionto generate the url with other loading strategies. Requiresformatto be set as well. When default XHR feature loader is provided, the features will be transformed from the data projection to the view projection during parsing. If your remote data source does not advertise its projection properly, this transformation will be incorrect. For some formats, the default projection (usually EPSG:4326) can be overridden by setting the dataProjection constructor option on the format. Note that if a source contains non-feature data, such as a GeoJSON geometry or a KML NetworkLink, these will be ignored. Use a custom loader to load these.useSpatialIndexboolean (defaults to true) 默认情况下,使用 RTree 作为空间索引。当要素频繁添加和移除,且要素总数较少时,将此设置为
false可能会提高性能。Note that
getFeaturesInExtent,getClosestFeatureToCoordinateandgetExtentcannot be used whenuseSpatialIndexis set tofalse, andforEachFeatureInExtentwill loop through all features.设置为
false时,要素将保存在Collection中,可通过getFeaturesCollection获取。wrapXboolean (defaults to true) 水平包裹世界。要使跨越 -180° 和 180° 经线的矢量编辑正常工作,应将其设置为 false。生成的几何坐标将超出世界边界。
触发事件:
-
addfeature(VectorSourceEvent) - 当向数据源添加要素时触发。 -
change(BaseEvent) - 通用更改事件。当修订计数器增加时触发。 -
changefeature(VectorSourceEvent) - 当更新要素时触发。 -
clear(VectorSourceEvent) - 当调用数据源的 clear 方法时触发。 -
error(BaseEvent) - 通用错误事件。 当发生错误时触发。 -
featuresloadend(VectorSourceEvent) - 当features finishes loading. -
featuresloaderror(VectorSourceEvent) - 要素加载出错时触发。 -
featuresloadstart(VectorSourceEvent) - 当features starts loading. -
propertychange(ObjectEvent) - 当属性更改时触发。 -
removefeature(VectorSourceEvent) - 当从数据源移除要素时触发。 Seesource.clear()for exceptions.
-
Subclasses
Extends
Methods
-
向数据源添加单个要素。如果要一次添加一批要素,请改用
#add要素s()。如果具有相同 id 的要素已存在,则不会将该要素添加到数据源。此行为的原因是避免使用 bbox 或瓦片加载策略时要素重复。注意:如果要素使用Collection,这也适用,意味着如果添加了重复 id 的要素到集合中,它将立即被移除。Name Type Description feature要素Type 要添加的要素。
-
向数据源添加一批要素。
Name Type Description featuresArray.<要素Type> 要素s to add.
-
增加修订计数器并分发 'change' 事件。
-
从数据源移除所有要素。
Name Type Description fastboolean | undefined 跳过分发 removefeature 事件。
-
分发事件并调用所有监听此类型事件的监听器。事件参数可以是一个字符串或一个 具有
type属性的对象。Name Type Description eventBaseEvent | string 事件对象。
返回值:
如果有人在事件对象上调用了 preventDefault 或任何监听器返回 false,则返回false。
-
遍历数据源上的所有要素,对每个要素调用提供的回调函数。如果回调返回任何"真值",迭代将停止并返回相同的值。注意:此函数仅遍历具有已定义几何对象的要素。
Name Type Description callbackfunction 对数据源中的每个要素调用。返回真值以停止遍历。
返回值:
The return value from the last call to the callback.
-
遍历所有边界框与提供范围相交的要素(注意要素的几何对象可能不与范围相交),对每个要素调用回调函数。如果回调返回"真值",迭代将停止并返回相同的值。
如果您对几何图形与范围相交的要素感兴趣,请改用
#forEach要素IntersectingExtent()方法。当
useSpatialIndex设置为 false 时,此方法将遍历所有要素,等同于#forEach要素()。Name Type Description extentExtent 范围。
callbackfunction 对边界框与提供的范围相交的每个要素调用。
返回值:
The return value from the last call to the callback.
-
遍历所有几何对象与提供范围相交的要素,对每个要素调用回调函数。如果回调返回"真值",迭代将停止并返回相同的值。
如果您只想测试边界框相交,请改用
#forEachFeatureInExtent()方法。Name Type Description extentExtent 范围。
callbackfunction 对几何图形与提供的范围相交的每个要素调用。
返回值:
The return value from the last call to the callback.
-
获取一个值。
Name Type Description keystring 键名。
返回值:
值。
-
获取数据源的归属函数。
返回值:
Attribution function.
-
返回值:
归属信息是否可折叠。
-
获取距离指定坐标最近的要素。
当数据源配置
useSpatialIndex为false且此数据源中的要素类型为要素时,此方法不可用。Name Type Description coordinateCoordinate 坐标。
filterfunction | undefined 要素过滤函数。过滤函数将接收一个参数
feature,并应返回布尔值。默认不进行过滤。返回值:
Closest feature (ornullif none found).
-
获取当前数据源中要素的范围。
当数据源配置
useSpatialIndex为false时,此方法将返回null。Name Type Description extentExtent | undefined 目标范围。如果提供,将不创建新范围,而是覆盖该范围的坐标。
返回值:
范围。
-
通过标识符获取要素(feature.getId() 返回的值)。当使用
渲染要素时,get要素ById()可以返回渲染要素数组。这允许处理GeometryCollection几何图形,其中格式读取器为每个GeometryCollection成员创建一个渲染要素。注意索引将字符串和数字标识符视为相同。因此source.get要素ById(2)将返回 id 为'2'或2的要素。Name Type Description idstring | number 要素标识符。
返回值:
The feature (ornullif not found).
-
获取数据源上当前要素的随机顺序快照。返回的数组是副本,要素是对数据源中要素的引用。
返回值:
要素集合。
-
获取几何图形与提供的坐标相交的所有要素。
Name Type Description coordinateCoordinate 坐标。
返回值:
要素集合。
-
获取与此数据源关联的要素集合。除非数据源配置时将 useSpatialIndex 设置为 false,或使用 Collection 作为 features,否则将为 null。
返回值:
The collection of features.
-
获取边界框与提供的范围相交的所有要素。注意这将以随机顺序返回与给定范围相交的所有要素的数组(因此可能包含几何图形不与范围相交的要素)。
当
useSpatialIndex设置为 false 时,此方法将返回所有要素。Name Type Description extentExtent 范围。
projectionProjection | undefined 包含范围超出投影 x 轴边界并环绕世界的要素。
返回值:
要素集合。
-
获取与此数据源关联的格式。
返回值:
} The feature format.
-
获取对象属性名列表。
返回值:
属性名列表。
-
获取数据源的投影。
返回值:
投影。
-
获取包含所有属性名和值的对象。
返回值:
对象。
-
获取此对象的版本号。 每次对象被修改时,其版本号将递增。
返回值:
版本号。
-
获取数据源的状态,可能的状态参见 State。
返回值:
状态。
-
获取url associated with this source.
返回值:
The url.
-
返回要素是否包含在数据源中。
Name Type Description feature要素Type 要素。
返回值:
Has feature.
-
监听特定类型的事件。
Name Type Description typestring | Array.<string> 事件类型或事件类型数组。
listenerfunction 监听器函数。
返回值:
监听器的唯一键。如果第一个参数是事件类型数组,则返回键的数组。
-
仅监听一次特定类型的事件。
Name Type Description typestring | Array.<string> 事件类型或事件类型数组。
listenerfunction 监听器函数。
返回值:
监听器的唯一键。如果第一个参数是事件类型数组,则返回键的数组。
-
从数据源移除单个要素。如果要批量移除要素,请改用
#remove要素s()方法。Name Type Description feature要素Type 要移除的要素。
-
从数据源批量移除要素。如果要一次移除所有要素,请改用 #clear() 方法。
Name Type Description featuresArray.<要素Type> 要素s to remove.
-
从已加载范围列表中移除一个范围。
Name Type Description extentExtent 范围。
-
设置一个值。
Name Type Description keystring 键名。
value* 值。
silentboolean | undefined 更新但不触发事件。
-
设置数据源的归属信息。
Name Type Description attributionsAttributionLike | undefined 归属信息。可以作为字符串、Array<string>、Attribution 或 undefined 传入。
-
设置数据源的新加载器。下一个渲染周期将使用新的加载器。
Name Type Description loader要素Loader 要设置的加载器。
-
设置一组键值对。 注意,这会更改任何现有属性并添加新属性(不会移除任何现有属性)。
Name Type Description valuesPartial.<NoInfer.<Properties>> 值。
silentboolean | undefined 更新但不触发事件。
-
将数据源指向新的 URL。下一个渲染周期将使用新的 URL。
Name Type Description urlstring | featureUrlFunction Url.
-
取消监听特定类型的事件。
Name Type Description typestring | Array.<string> 事件类型或事件类型数组。
listenerfunction 监听器函数。
-
取消设置一个属性。
Name Type Description keystring 键名。
silentboolean | undefined 取消设置但不触发事件。