Classes
Type Definitions
-
A function that takes an
module:ol/extent~Extent
and a resolution as arguments, and returns an array ofmodule:ol/extent~Extent
with the extents to load. Usually this is one of the standardmodule:ol/loadingstrategy
strategies. -
Options{Object}
-
Properties:
Name Type Argument Default Description attributions
module:ol/source/Source~AttributionLike <optional>
Attributions.
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 ifurl
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. The'featuresloadend'
and'featuresloaderror'
events will only fire if thesuccess
andfailure
callbacks are used.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, success, failure) { 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); failure(); } xhr.onerror = onError; xhr.onload = function() { if (xhr.status == 200) { var features = vectorSource.getFormat().readFeatures(xhr.responseText); vectorSource.addFeatures(features); success(features); } else { onError(); } } xhr.send(); }, strategy: bbox });
overlaps
boolean <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.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 astring
and anmodule:ol/loadingstrategy.all
for a one-off download of all features from the given URL. Use amodule:ol/featureloader~FeatureUrlFunction
to generate the url with other loading strategies. Requiresformat
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>
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
false
may improve performance.Note that
module:ol/source/Vector~VectorSource#getFeaturesInExtent
,module:ol/source/Vector~VectorSource#getClosestFeatureToCoordinate
andmodule:ol/source/Vector~VectorSource#getExtent
cannot be used whenuseSpatialIndex
is set tofalse
, andmodule:ol/source/Vector~VectorSource#forEachFeatureInExtent
will 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
.wrapX
boolean <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.