Module: ol/source/Vector




Type Definitions


source/Vector.js, line 24

A function that takes an module:ol/extent~Extent and a resolution as arguments, and returns an array of module:ol/extent~Extent with the extents to load. Usually this is one of the standard module:ol/loadingstrategy strategies.


Name Type Argument Default Description
attributions module:ol/source/Source~AttributionLike <optional>


features Array.<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.

format module:ol/format/Feature~FeatureFormat <optional>

The feature format used by the XHR feature loader when url is set. Required if url is set, otherwise ignored.

loader module:ol/featureloader~FeatureLoader <optional>

The loader function used to load features, from a remote source for example. If this is not set and url is set, the source will create and use an XHR feature loader.


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 = '' +
         'version=1.1.0&request=GetFeature&typename=osm:water_areas&' +
         'outputFormat=application/json&srsname=' + proj + '&' +
         'bbox=' + extent.join(',') + ',' + proj;
     var xhr = new XMLHttpRequest();'GET', url);
     var onError = function() {
     xhr.onerror = onError;
     xhr.onload = function() {
       if (xhr.status == 200) {
       } else {
   strategy: bbox
overlaps boolean <optional>

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.

strategy module:ol/source/Vector~LoadingStrategy <optional>

The loading strategy to use. By default an module:ol/loadingstrategy~all strategy is used, a one-off strategy which loads all features at once.

url string | module:ol/featureloader~FeatureUrlFunction <optional>

Setting this option instructs the source to load features using an XHR loader (see module:ol/featureloader~xhr). Use a string and an module:ol/loadingstrategy~all for a one-off download of all features from the given URL. Use a module:ol/featureloader~FeatureUrlFunction to generate the url with other loading strategies. Requires format to 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.

useSpatialIndex boolean <optional>

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 false may improve performance.

Note that module:ol/source/Vector~VectorSource#getFeaturesInExtent, module:ol/source/Vector~VectorSource#getClosestFeatureToCoordinate and module:ol/source/Vector~VectorSource#getExtent cannot be used when useSpatialIndex is set to false, and module:ol/source/Vector~VectorSource#forEachFeatureInExtent will loop through all features.

When set to false, the features will be maintained in an module:ol/Collection, which can be retrieved through module:ol/source/Vector~VectorSource#getFeaturesCollection.

wrapX boolean <optional>

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.