OpenLayers3 offers the
Maybe you, like me, has spent some time trying to understand why your GeoJSON data is not rendering properly: projection is fine, your GeoJSON is well formed and validated but OpenLayers3 doesn’t return any features and so nothing is rendered in the map.
What is the problem?
ol.source.GeoJSON class is a subclass of
ol.source.StaticVector that uses an
ol.format.GeoJSON instance to read content:
A source class, by definition, acts as a source of features for a vector layers, that is, it is like a container of features. Because of this, the
ol.source.GeoJSON source is limited to read GeoJSON features and not geometries. So next GeoJSON will be ignored by OpenLayers3 (really if you use de debug version you will see an assertion message):
While the next is a valid GeoJSON suitable to be read by the source:
That means we can’t read GeoJSON geometries?
Absolutely no, simply means source classes follows the source concept, and that means, work with features.
ol.format.GeoJSON format class allows to read and write features and geometries. To read a GeoJSON file composed of geometries we need to read the geometries and, manually, create a feature for each one. For example: