Search code examples
openlayers-3vector-tiles

Is FeatureCollection necessary for ol.layer.VectorTile layer in openlayers?


I am looking to create a ol.layer.VectorTile layer from an array of GeoJSON Point objects in ol3. Right now the data that is being returned to me is an array of objects, with each object being a GeoJSON of type "Point". In examples I have seen, VectorTile layers were created from a "FeatureCollection" which contained all the Point objects as features. I am wondering if the api would need to return the data as a "FeatureCollection" or I would need to create one myself from the data being returned, in order to ultimately be able to create a vectorTile layer?


Solution

  • Your api just needs to return the geometries(ie. point,line, polygon). It could be in any parsable format like GeoJson/WKT.Then create OL3 feature from the geometries returned by your API. Create an instance of ol.Collection. Then add each feature in the newly created collection. And use this featurecollection as a source in a vector layer.