Classes
Type Definitions
-
A function that takes an
Extentand a resolution as arguments, and returns an array ofExtentwith the extents to load. Usually this is one of the standardol/loadingstrategystrategies. -
Options{Object}
-
Properties:
Name Type Description attributionsAttributionLike | undefined Attributions.
featuresArray.<FeatureType> | Collection<FeatureType> | undefined Features. If provided as
Collection, the features in the source and the collection will stay in sync.formatFeatureFormat<FeatureType> | undefined The feature format used by the XHR feature loader when
urlis set. Required ifurlis set, otherwise ignored.loaderFeatureLoader<FeatureType> | undefined The loader function used to load features, from a remote source for example. If this is not set and
urlis set, the source will create and use an XHR feature loader. The'featuresloadend'and'featuresloaderror'events will only fire if thesuccessandfailurecallbacks are used.Example:
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)This source may have overlapping geometries. Setting this to
false(e.g. for sources with polygons that represent administrative boundaries or TopoJSON sources) allows the renderer to optimise fill and stroke operations.strategyLoadingStrategy | undefined The loading strategy to use. By default an
allstrategy is used, a one-off strategy which loads all features at once.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)By default, an RTree is used as spatial index. When features are removed and added frequently, and the total number of features is low, setting this to
falsemay improve performance.Note that
getFeaturesInExtent,getClosestFeatureToCoordinateandgetExtentcannot be used whenuseSpatialIndexis set tofalse, andforEachFeatureInExtentwill loop through all features.When set to
false, the features will be maintained in anCollection, which can be retrieved throughgetFeaturesCollection.wrapXboolean
(defaults to true)Wrap the world horizontally. For vector editing across the -180° and 180° meridians to work properly, this should be set to
false. The resulting geometry coordinates will then exceed the world bounds.