[英]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; 我刚刚开始在应用程序中使用OL3,我发现(至少)有两种在地图上绘制要素的方式; ol.source.Vector and ol.source.geoJSON.
ol.source.Vector和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. 我的数据不是geoJSON格式,因此无论如何我都必须转换数据。
Thanks! 谢谢!
You will use an ol.source.GeoJSON
if the data you want to display is encoded in GeoJSON. 如果要显示的数据是用GeoJSON编码的,则将使用
ol.source.GeoJSON
。 There are also vector sources for other formats, ol.source.KML
for example. 也有其他格式的矢量源,例如
ol.source.KML
。
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
. 如果对向量使用特定格式,或者使用
new ol.Feature(...)
手动创建向量特征,则使用基类,即ol.source.Vector
。 This is the most flexible, and the one one will use in most cases IMO. 这是最灵活的,一个将在大多数情况下用于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. 该类的实例揭露类似的方法
addFeatures
, addFeature
, removeFeature
, clear
,您可以使用从矢量源添加/删除载体功能/。 It also exposes methods to "query" the source. 它还向“查询”源公开方法。 Check out the docs!
查看文档!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.