Skip to content Skip to sidebar Skip to footer

Openlayers: Unsupported Geojson Type: Undefined

In case anyone remembers or have seen my earlier post, I was trying to parse a GeoJSON string with limited success. That issue has been resolved, however I have a geojson file with

Solution 1:

You are asking GeoJSON to readFeatures on an object that is not in GeoJSON form. geojsonObject has no type so you get the "Unsupported GeoJSON type: undefined" error.

...readFeatures({ url: ..., format: ... /* there's no type! */})

Have a look at this reproduction for an example of the type of object readFeatures expects.

I suspect what you actually want is something like:

var vectorSource = newVectorSource({
    url: './locality.json',
    format: newGeoJSON({ featureProjection: "EPSG:3857" })
});

You'd usually use either url & format or features & readFeatures depending on what suits.

Solution 2:

You can store all your data into 'data.json' file instead of .geojson. require the file in your js then you can read it using readFeatures

const data = require('./data.json')
var geojsonObject = data;

var vectorSource = newVectorSource({
    features: (newGeoJSON()).readFeatures(geojsonObject,
            {
            dataProjection: 'EPSG:4326',
            featureProjection: 'EPSG:3857'
            })
    });

Post a Comment for "Openlayers: Unsupported Geojson Type: Undefined"