我在尝试创建 map 时遇到此错误:
我目前使用的版本 "datamaps": "^0.5.8",
这直接来 self 的 package.json
。我还检查了实际包中的 package.json
以查看 main 指向的位置:
https://github.com/markmarkoh/datamaps/issues/259
问题是没有人说出答案是什么,有人提到只加载了特定国家/地区的 js 文件,但我检查了一下,datamaps.all.js
正在加载。
最佳答案
这要归功于 D3 v4 的新模块化,这使得有必要 flatten namespaces :
However, there is one unavoidable consequence of adopting ES6 modules: every symbol in D3 4.0 now shares a flat namespace rather than the nested one of D3 3.x.
对于您的代码,这意味着某些使用 d3-geo 模块的引用无效,因为它们引用的属性在 v4 中不再可用:
Geographies (d3-geo)
- d3.geo.albersUsa ↦ d3.geoAlbersUsa
因为数据映射定义了对 D3 的依赖,例如 ^3.5.6
这将包括 D3 v4。但是,由于上面提到的 namespace 更改,您将不得不改用 D3 v3。
关于javascript - Datamaps 给我一个 Cannot read property 'albersUsa' of undefined,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40405692/