我正尝试替换为:
<!-- Openlayers -->
<link rel="stylesheet" href="https://openlayers.org/en/latest/css/ol.css" />
<script type="text/javascript" src="https://openlayers.org/en/latest/build/ol.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/proj4js/2.5.0/proj4.js" integrity="sha256-KJI74PS1qv3+hue+yyIWK/l8TxvS9u4WX7QDrtHkHOo=" crossorigin="anonymous"></script>
<!-- ol-ext -->
<link rel="stylesheet" href="https://cdn.rawgit.com/Viglino/ol-ext/master/dist/ol-ext.min.css" />
<script type="text/javascript" src="https://cdn.rawgit.com/Viglino/ol-ext/master/dist/ol-ext.min.js"></script>
使用import
指令:
import * as proj from 'ol/proj'
import * as projProj4 from 'ol/proj/proj4'
import * as geom from 'ol/geom'
import * as layer from 'ol/layer'
import * as format from 'ol/format'
import * as source from 'ol/source'
import * as style from 'ol/style'
import proj4 from 'proj4'
import Placemark from 'ol-ext/overlay/Placemark'
// import 'ol-ext/dist/ol-ext.css'
window.ol = {
proj: proj,
geom: geom,
layer: layer,
format: format,
source: source,
style: style,
Overlay: {}
}
window.ol.Overlay.Placemark = Placemark
window.ol.proj.proj4 = projProj4
window.proj4 = proj4
不幸的是,它不起作用,而且非常麻烦。我无法使用:
import 'ol'
import 'ol-ext'
import 'proj4'
有一种简单的方法吗?
答案 0 :(得分:0)
进入node_modules
,找到pro4j
,打开代码并检查导出的内容。如果导出了某个班级,则可以执行import ThatClass from [nodeModuleFolderName]
。如果仅导出了很多函数,则可以使用import
一次import * as Whatever from [nodeModuleFolderName]
一次全部使用它们。