如何使用 NPM 安装 OpenLayers
How to install OpenLayers using NPM
NPM 上似乎有两个可用的 OpenLayers 包:
选项 1
npm install ol
然后可以使用:
import OlMap from 'ol/map';
import OlView from 'ol/view';
import OlTile from 'ol/layer/tile';
import OlLayerVector from 'ol/layer/vector';
import OlSourceVector from 'ol/source/vector';
选项 2
npm install openlayers
import * as ol from 'openlayers';
为什么是两个包?
如果有的话,正确的方法是什么?
第二个我觉得比较优雅,但是OL的文档居然提到了第一个:https://www.npmjs.com/package/openlayers
NPM page 解释了差异。
不要用 openlayers
开始一个项目,它使用闭包,你很可能不会。 ol
被打包为'state of art' ES2015 模块。它使你的编译器(例如 webpack)只打包你实际使用的东西。
For use with webpack, Rollup, Browserify, or other module bundlers, install the ol package:
npm install ol
For use with Closure Library (rare), install the openlayers package and read the tutorial.
npm install openlayers
NPM 上似乎有两个可用的 OpenLayers 包:
选项 1
npm install ol
然后可以使用:
import OlMap from 'ol/map';
import OlView from 'ol/view';
import OlTile from 'ol/layer/tile';
import OlLayerVector from 'ol/layer/vector';
import OlSourceVector from 'ol/source/vector';
选项 2
npm install openlayers
import * as ol from 'openlayers';
为什么是两个包? 如果有的话,正确的方法是什么?
第二个我觉得比较优雅,但是OL的文档居然提到了第一个:https://www.npmjs.com/package/openlayers
NPM page 解释了差异。
不要用 openlayers
开始一个项目,它使用闭包,你很可能不会。 ol
被打包为'state of art' ES2015 模块。它使你的编译器(例如 webpack)只打包你实际使用的东西。
For use with webpack, Rollup, Browserify, or other module bundlers, install the ol package:
npm install ol
For use with Closure Library (rare), install the openlayers package and read the tutorial.
npm install openlayers