O'Reilly logo

OpenLayers 3 : Beginner's Guide by Erik Hazzard, Paul Spencer, Thomas Gratier

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Time for action – reprojecting geometries in vector layers

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:

  1. Again, let's copy the previous sample into a new file in the sandbox directory.
  2. 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'
     });
  3. Add a listener on the source that fires once and that sends some console.log statements:
    countriesSource.once('change', ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required