Atlaslog
Atlaslog / OpenLayers / Tutorial / Vector data sources
OpenLayers · Tutorial

Vector data sources

Quick answer

This tutorial separates data sources from format parsers so a layer can swap GeoJSON, TopoJSON, KML, GML, GPX or MVT without rewriting logic. It configures ol.format.GeoJSON with dataProjection and featureProjection, enables extractStyles and extractAttributes for KML, and implements a bbox loader with ol.loadingstrategy.bbox plus success and failure callbacks. Readers can load remote vector data correctly and page it by view extent.

Last verified 2026-11-03 · OpenLayers 10.3.1 · Cite this page
Key points
Example
var view = new ol.View({
  center: ol.proj.fromLonLat([116.397, 39.908]),
  zoom: 11
});

var source = new ol.source.Vector({
  url: '/data/districts.geojson',
  format: new ol.format.GeoJSON({
    dataProjection: 'EPSG:4326',
    featureProjection: view.getProjection()
  })
});

var layer = new ol.layer.Vector({
  source: source,
  style: new ol.style.Style({
    stroke: new ol.style.Stroke({ color: '#1f5fd0', width: 1.5 }),
    fill: new ol.style.Fill({ color: 'rgba(31, 95, 208, 0.15)' })
  })
});

map.addLayer(layer);
var kmlSource = new ol.source.Vector({
  url: '/data/facilities.kml',
  format: new ol.format.KML({
    extractStyles: true,
    extractAttributes: true
  })
});
var topoSource = new ol.source.Vector({
  url: '/data/province.topo.json',
  format: new ol.format.TopoJSON({
    dataProjection: 'EPSG:4326',
    featureProjection: 'EPSG:3857'
  })
});
Notes
Runnable examplesChinese originalAll Tutorials
English edition written for Atlaslog. Code is taken from the original Chinese page and runs unchanged.
Cite this page

Atlaslog (2026). Vector data sources. https://www.jingweizhi.com/en/openlayers/tutorials/data-sources.html (accessed 2026-11-03).