Classes
Type Definitions
-
A function that takes an
module:ol/extent~Extentand a resolution as arguments, and returns an array ofmodule:ol/extent~Extentwith the extents to load. Usually this is one of the standardmodule:ol/loadingstrategystrategies. -
Properties:
Name Type Argument Default Description attributionsmodule:ol/source/Source~AttributionLike <optional>
Attributions.
featuresArray.<module:ol/Feature~Feature> | module:ol/Collection~Collection.<module:ol/Feature~Feature> <optional>
Features. If provided as
module:ol/Collection, the features in the source and the collection will stay in sync.formatmodule:ol/format/Feature~FeatureFormat <optional>
The feature format used by the XHR feature loader when
urlis set. Required ifurlis set, otherwise ignored.loadermodule:ol/featureloader~FeatureLoader <optional>
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.Example:
import {Vector} from 'ol/source'; import {GeoJSON} from 'ol/format'; import {bbox} from 'ol/loadingstrategy'; var vectorSource = new Vector({ format: new GeoJSON(), loader: function(extent, resolution, projection) { var proj = projection.getCode(); var 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; var xhr = new XMLHttpRequest(); xhr.open('GET', url); var onError = function() { vectorSource.removeLoadedExtent(extent); } xhr.onerror = onError; xhr.onload = function() { if (xhr.status == 200) { vectorSource.addFeatures( vectorSource.getFormat().readFeatures(xhr.responseText)); } else { onError(); } } xhr.send(); }, strategy: bbox });overlapsboolean <optional>
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.strategymodule:ol/source/Vector~LoadingStrategy <optional>
The loading strategy to use. By default an
module:ol/loadingstrategy~allstrategy is used, a one-off strategy which loads all features at once.urlstring | module:ol/featureloader~FeatureUrlFunction <optional>
Setting this option instructs the source to load features using an XHR loader (see
module:ol/featureloader~xhr). Use astringand anmodule:ol/loadingstrategy~allfor a one-off download of all features from the given URL. Use amodule:ol/featureloader~FeatureUrlFunctionto 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 <optional>
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
module:ol/source/Vector~VectorSource#getFeaturesInExtent,module:ol/source/Vector~VectorSource#getClosestFeatureToCoordinateandmodule:ol/source/Vector~VectorSource#getExtentcannot be used whenuseSpatialIndexis set tofalse, andmodule:ol/source/Vector~VectorSource#forEachFeatureInExtentwill loop through all features.When set to
false, the features will be maintained in anmodule:ol/Collection, which can be retrieved throughmodule:ol/source/Vector~VectorSource#getFeaturesCollection.wrapXboolean <optional>
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.