# Module: ol/source/Vector

This documentation is for OpenLayers v10.9.0. The latest is v.

## ol/source/Vector

### Classes

VectorSourceEvent
VectorSource

### Type Definitions

#### LoadingStrategy()

source/Vector.js, line 24

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

#### Options{Object}

  ##### Properties:

  Name | Type | Description
  --- | --- | ---
  `attributions` | AttributionLike | undefined | Attributions.
  `features` | Array.<FeatureType> | Collection<FeatureType> | undefined | Features. If provided as `Collection`, the features in the source and the collection will stay in sync.
  `format` | FeatureFormat<FeatureType> | undefined | The feature format used by the XHR feature loader when `url` is set. Required if `url` is set, otherwise ignored.
  `loader` | FeatureLoader<FeatureType> | undefined | 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 the `success` and `failure` callbacks 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({
        loader: async (extent, resolution, projection) => {
           const url = 'https://ahocevar.com/geoserver/wfs?service=WFS&' +
               'version=1.1.0&request=GetFeature&typename=osm:water_areas&' +
               'outputFormat=application/json' +
               'bbox=' + extent.join(',') + ',' + projection.getCode();
           const response = await fetch(url);
           if (!response.ok) {
             throw new Error('Network response was not ok');
           }
           const json = await response.json();
           const features = new GeoJSON().readFeatures(json, {
             featureProjection: projection,
           });
           return features;
         },
         strategy: bbox,
       });
  When you want to retry a failed request, use
      vectorSource.removeLoadedExtent(extent);
      vectorSource.changed();
  `overlaps` | boolean (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.
  `strategy` | LoadingStrategy | undefined | The loading strategy to use. By default an `all` strategy is used, a one-off strategy which loads all features at once.
  `url` | string | FeatureUrlFunction | undefined | Setting this option instructs the source to load features using an XHR loader (see `xhr`). Use a `string` and an `all` for a one-off download of all features from the given URL. Use a `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 (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 `false` may improve performance. Note that `getFeaturesInExtent`, `getClosestFeatureToCoordinate` and `getExtent` cannot be used when `useSpatialIndex` is set to `false`, and `forEachFeatureInExtent` will loop through all features. When set to `false`, the features will be maintained in an `Collection`, which can be retrieved through `getFeaturesCollection`.
  `wrapX` | boolean (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.