Search code examples
openlayersgeojson

Openlayers geojson-vt : Why no features are generated?


I implemented openlayers geojson-vt example. I try to load a genuine geojson... I don't understand why no features are generated: sandbox demo

Where is the issue causing the difference with openlayers website example?

I try to generate features


Solution

  • Your data is in EPSG:2154. geojson-vt only supports data in EPSG:4326 so you must convert it

    fetch(url)
      .then(function (response) {
        return response.json();
      })
      .then(function (json) {
        proj4.defs(
          'EPSG:2154',
          '+proj=lcc +lat_0=46.5 +lon_0=3 +lat_1=49 +lat_2=44 +x_0=700000 +y_0=6600000 +ellps=GRS80 +towgs84=0,0,0,0,0,0,0 +units=m +no_defs +type=crs',
        );
        register(proj4);
        const format = new GeoJSON();
        return format.writeFeaturesObject(format.readFeatures(json), {
          featureProjection: 'EPSG:2154',
          dataProjection: 'EPSG:4326',
        });
      })
      .then(function (json) {
    

    Also your features do not have a COLOR property, so you should use a different style.