类
类型定义
-
该函数以
Extent和分辨率为参数,返回一个Extent数组,其中包含要加载的范围。通常这是标准ol/loadingstrategy策略之一。 -
Options{Object}
-
属性:
Name Type 描述 attributionsAttributionLike | undefined 归属。
featuresArray.<FeatureType> | Collection<FeatureType> | undefined 要素。如果提供为
Collection,源和集合中的要素将保持同步。formatFeatureFormat<FeatureType> | undefined XHR要素加载器所使用的要素格式
url已设置。必需条件:如果...url若已设置则生效,否则忽略。loaderFeatureLoader<FeatureType> | 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({ 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, });overlapsboolean
(defaults to true)该数据源可能存在几何重叠。将其设置为
false(例如,对于代表行政边界的多边形数据源或 TopoJSON 数据源)可使渲染器优化填充和描边操作。strategyLoadingStrategy | undefined 所使用的加载策略。默认情况下
all采用一次性策略,该策略一次性加载所有要素。urlstring | FeatureUrlFunction | undefined 此选项用于指示源使用XHR加载器加载要素(请参阅
xhr)。使用string和all从指定 URL 一次性下载所有要素。使用FeatureUrlFunction采用其他加载策略生成 URL。format也需要设置。当使用默认的 XHR 要素加载器时,要素会在解析过程中从数据投影转换为视图投影。如果您的远程数据源未正确声明其投影,则此转换将不准确。对于某些格式,可以通过在格式构造函数中设置 dataProjection 选项来覆盖默认投影(通常为 EPSG:4326)。请注意,如果数据源包含非要素数据(例如 GeoJSON 几何图形或 KML NetworkLink),这些内容将被忽略。如需加载此类数据,请使用自定义加载器。useSpatialIndexboolean
(defaults to true)默认情况下,使用 RTree 作为空间索引。当要素被频繁删除和添加,且要素总数较少时,可设置为
false可能提升性能。请注意
getFeaturesInExtent,getClosestFeatureToCoordinate和getExtent当...时不能使用useSpatialIndex设置为false,和forEachFeatureInExtent将遍历所有要素。设置为
false,这些要素将被维护在Collection,可通过检索getFeaturesCollection.wrapXboolean
(defaults to true)水平环绕世界。为使跨-180°和180°经线的矢量编辑正常工作,应将其设置为
false生成的几何坐标将超出世界边界。