简体   繁体   中英

Openlayers 3 geojson vs vector source

I have just started using OL3 in my application and I see that there is (at least) two ways of drawing features on the map; ol.source.Vector and ol.source.geoJSON.

Except for syntax, what are the advantages/disadvantages using one over the other? What about performance? As far as I can tell, I can draw both lines and points with both, and that is really all I need.

My data is not in geoJSON format, so I would have to convert the data anyway.

Thanks!

You will use an ol.source.GeoJSON if the data you want to display is encoded in GeoJSON. There are also vector sources for other formats, ol.source.KML for example.

If you use a specific format for your vectors or manually create vector features using new ol.Feature(...) then use the base class, namely ol.source.Vector . This is the most flexible, and the one one will use in most cases IMO. Instances of that class expose methods like addFeatures , addFeature , removeFeature , clear that you can use to add/remove vector features to/from the vector source. It also exposes methods to "query" the source. Check out the docs!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM