Currently in OpenLayers, I am creating features from a GeoJSON FeatureCollection as follows:
const points = JSON.parse(document.getElementById('points-data').textContent);
const features = new ol.format.GeoJSON().readFeatures(
points,
{featureProjection: "EPSG:3857",}
);
This all works fine normally, but breaks an OpenLayers extension I'm trying to use called GridBin at a step that tries to get the geometry of the feature sources passed to it. This is what a GridBin layer constructor looks like:
var countingGrid = new ol.layer.Vector({
style: gridCount,
source: new ol.source.GridBin({
source: source,
}),
});
From what I can tell in the documentation, objects created via the GeoJSON().readFeatures()
method is slightly different to standard ol.geom.Point
objects, in that the coordinates are not retrievable from a getter function for geojson features unlike geom Point features. I'm sorry if this is confusing, I'm still trying to work out the OpenLayers API. The solution I think would be to somehow add a geometry to, or fetch the geometry from, the features created from GeoJSON, how do I achieve this? Below is the console error trace for reference.
ol.js:8 Uncaught TypeError: Cannot read property 'getCode' of null
at Zr (ol.js:8)
at Kr (ol.js:8)
at Object.Hr [as transform] (ol.js:8)
at ol.source.GridBin.getGridGeomAt (ol-ext.js:19900)
at ol.source.GridBin.ol.source.BinBase.getBinAt (ol-ext.js:18390)
at ol.source.GridBin.ol.source.BinBase._onAddFeature (ol-ext.js:18311)
at ol.source.GridBin.ol.source.BinBase.reset (ol-ext.js:18430)
at ol.source.GridBin.ol.source.BinBase [as constructor] (ol-ext.js:18294)
at new ol.source.GridBin (ol-ext.js:19875)
at displayDateRange (main.js:431)
My suspicion is that it breaks where it tries getGridGeomAt
, since the features I'm using are not geom objects, it returns null
.
transform
andgetCode
suggest a projection is expected but not correctly defined.ol.geom.Point
objects using the coordinates from the geosjon collection but it still returns the same error.