模块:ol/source/Vector

ol/source/Vector


VectorSourceEvent
VectorSource

类型定义

LoadingStrategy()

该函数以Extent和分辨率为参数,返回一个Extent数组,其中包含要加载的范围。通常这是标准ol/loadingstrategy策略之一。

Options{Object}

属性:
Name Type 描述
attributions AttributionLike | undefined

归属。

features Array.<FeatureType> | Collection<FeatureType> | undefined

要素。如果提供为Collection,源和集合中的要素将保持同步。

format FeatureFormat<FeatureType> | undefined

XHR要素加载器所使用的要素格式url已设置。必需条件:如果...url若已设置则生效,否则忽略。

loader FeatureLoader<FeatureType> | undefined

加载器函数用于加载要素,例如从远程数据源。如果未设置并且url设置后,源将创建并使用XHR要素加载器。该'featuresloadend''featuresloaderror'事件只会在以下情况下触发:successfailure使用回调函数。

示例:

import Vector from 'ol/source/Vector.js';
import GeoJSON from 'ol/format/GeoJSON.js';
import {bbox} from 'ol/loadingstrategy.js';

const vectorSource = new Vector({
  format: new GeoJSON(),
  loader: function(extent, resolution, projection, success, failure) {
     const proj = projection.getCode();
     const url = 'https://ahocevar.com/geoserver/wfs?service=WFS&' +
         'version=1.1.0&request=GetFeature&typename=osm:water_areas&' +
         'outputFormat=application/json&srsname=' + proj + '&' +
         'bbox=' + extent.join(',') + ',' + proj;
     const xhr = new XMLHttpRequest();
     xhr.open('GET', url);
     const onError = function() {
       vectorSource.removeLoadedExtent(extent);
       failure();
     }
     xhr.onerror = onError;
     xhr.onload = function() {
       if (xhr.status == 200) {
         const features = vectorSource.getFormat().readFeatures(xhr.responseText);
         vectorSource.addFeatures(features);
         success(features);
       } else {
         onError();
       }
     }
     xhr.send();
   },
   strategy: bbox,
 });
overlaps boolean
(defaults to true)

该数据源可能存在几何重叠。将其设置为false(例如,对于代表行政边界的多边形数据源或 TopoJSON 数据源)可使渲染器优化填充和描边操作。

strategy LoadingStrategy | undefined

所使用的加载策略。默认情况下all采用一次性策略,该策略一次性加载所有要素。

url string | FeatureUrlFunction | undefined

此选项用于指示源使用XHR加载器加载要素(请参阅xhr)。使用 stringall 从指定 URL 一次性下载所有要素。使用 FeatureUrlFunction 采用其他加载策略生成 URL。format 也需要设置。当使用默认的 XHR 要素加载器时,要素会在解析过程中从数据投影转换为视图投影。如果您的远程数据源未正确声明其投影,则此转换将不准确。对于某些格式,可以通过在格式构造函数中设置 dataProjection 选项来覆盖默认投影(通常为 EPSG:4326)。请注意,如果数据源包含非要素数据(例如 GeoJSON 几何图形或 KML NetworkLink),这些内容将被忽略。如需加载此类数据,请使用自定义加载器。

useSpatialIndex boolean
(defaults to true)

默认情况下,使用 RTree 作为空间索引。当要素被频繁删除和添加,且要素总数较少时,可设置为false可能提升性能。

请注意getFeaturesInExtent, getClosestFeatureToCoordinategetExtent当...时不能使用useSpatialIndex设置为false,和forEachFeatureInExtent将遍历所有要素。

设置为false,这些要素将被维护在Collection,可通过检索getFeaturesCollection.

wrapX boolean
(defaults to true)

水平环绕世界。为使跨-180°和180°经线的矢量编辑正常工作,应将其设置为false生成的几何坐标将超出世界边界。