When you draw in OpenLayers, you draw in local projections' features. Then, if you need, for example, to exchange data source with a third party, sometimes you need to make reprojections. It's useful to know how to consume data and reproject them or on the contrary, export them. It's what we will see here:
Again, let's copy the previous sample into a new file in the
sandbox
directory.Edit the file, and after the
var
projection declaration, add a new GeoJSON source, a vector source:var countriesSource = new ol.source.GeoJSON({ projection: 'EPSG:2154', url: '../assets/data/nutsv9_lea.geojson' });
Add a listener on the source that fires once and that sends some
console.log
statements:countriesSource.once('change', function(evt) { if (this.getState() == 'ready') { console.log(this.getFeatures()[0].getGeometry().getCoordinates()); console.log(this.getFeatures()[0].getGeometry().clone().transform('EPSG:2154','EPSG:4326'...