如何使用NPM安装OpenLayers [英] How to install OpenLayers using NPM

查看:2405
本文介绍了如何使用NPM安装OpenLayers的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

NPM上似乎有两个可用的OpenLayers软件包:

There seem to be two OpenLayers packages available over NPM:

选项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';

为什么要两个包? 正确的方法是什么?

Why two packages? What is the correct way, if any?

第二个对我来说看起来更优雅,但是OL的文档实际上提到了第一个: https://www.npmjs.com/package/openlayers

The second one looks more elegant to me, but OL's documentation actually mentions the first one: https://www.npmjs.com/package/openlayers

推荐答案

NPM页面解释了差异. 不要使用openlayers启动项目,因为它会使用闭包,而您很有可能不会这样做. ol被打包为最新技术" ES2015模块.它使您的编译器(例如,webpack)仅打包您实际使用的东西.

The NPM page explains the difference. Do not start a project with openlayers, it uses closure, which you most likely will not. ol is packaged as'state of art' ES2015 modules. It enables your compiler (eg webpack) to only package things you actually use.

要与webpack,Rollup,Browserify或其他模块捆绑程序一起使用,请安装ol软件包:

For use with webpack, Rollup, Browserify, or other module bundlers, install the ol package:

npm install ol

要与Closure Library(罕见)一起使用,请安装openlayers软件包并阅读教程.

For use with Closure Library (rare), install the openlayers package and read the tutorial.

npm install openlayers

这篇关于如何使用NPM安装OpenLayers的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆