openlayers3 undefined is not a constructor error on ol.source.StaticVector

openlayers3 undefined is not a constructor error on ol.source.StaticVector

我正在使用 ol v3.20.1 学习 openlayers3
我已经到了书中的重点,我可以 read/write GeoJSON with StaticVector,但是下面的代码:

var statVec = new ol.layer.Vector({
 source: new ol.source.StaticVector({
  format: new ol.format.GeoJSON(),
  projection: 'EPSG:3857'
 })
});

错误:

TypeError: undefined is not a constructor (evaluating 'new ol.source.StaticVector({
            format: new ol.format.GeoJSON(),
            projection: 'EPSG:3857'
        })')
    global code

我知道,有一个 API 变化,因为这本书出版了,但我找不到 StaticVector 被什么替换了。

ol.source.StaticVector 以及其他类似的实验性矢量源已在 v3.5.0 中删除。关于你的问题 ol.source.StaticVector 被替换为 ol.source.Vector.

查看此版本详细信息

https://github.com/openlayers/openlayers/releases/tag/v3.5.0