在页面上 openlayers/en/latest /examples/image-vector-layer.html 我将HTML代码从地图下方复制到/tmp/a.html并运行firefox /tmp/a.html.
On the page openlayers/en/latest/examples/image-vector-layer.html I copied the HTML code from under the map to /tmp/a.html and run firefox /tmp/a.html.
最初,两个问题似乎很容易解决:
At first two problems appeared easy to fix:
要修复它:
但是第三个错误该怎么办?
But what to do with the third error?
TypeError: Error resolving module specifier: ol/Map.js
我有Firefox 60.0.1.
I have Firefox 60.0.1.
那么,示例中的HTML代码是按原样使用还是我误解了?
So, are the HTML codes in the examples meant to be used as I did, or did I misunderstand something?
我在import Map from ol/Map.js的代码中需要什么?
And what do I need in my code to import Map from ol/Map.js?
(我试图重新表述这个问题,但是如果我仍然应该获得负面排名,请解释原因.谢谢)
(I tried to reformulate the question, but if I still deserve a negative ranking, please explain why. Thanks)
推荐答案这是因为由于最新版本的OpenLayers(V5.0)导致了一些更改. 现在,示例基于ES6模块,而以前有另一种方法
It's because there are some changes due to latest release of OpenLayers (V5.0). Now samples are based on ES6 modules whereas there was before another way of doing
您可以将简单" v4.6.5示例与简单"主样本
仅使用<script type="module">是不够的,因为这样做不能解决import Map from ol/Map.js
Using <script type="module"> is not enough as it does not solve dependencies when doing import Map from ol/Map.js
至少有3种方法:
使用5.0.0版创建Openlayers示例的通常方法是使用诸如Webpack或Parcel之类的捆绑器.有有关此问题的教程.
我还使用此示例
您始终可以使用旧的方式,例如在版本4.6.5中使用其他官方教程,而无需使用import.
You can always use the old way of doing, like in version 4.6.5 using this other official tutorial without using import.
对于解决方案1,您可以使用codesandbox.io避免设置本地包裹/webpack环境,如此推文.
For solution 1, you can use codesandbox.io to avoid setting a local parcel/webpack environment like illustrated with this tweet.
我知道有一个正在进行的重构示例代码的工作,并且我还为codeandbox.io提交了一些建议,例如 github/openlayers/openlayers/issues/8324
I know there is a work on progress to refactor the code for samples and I also submitted some suggestions for codesandbox.io e.g github/openlayers/openlayers/issues/8324
更多推荐
为什么示例不起作用? (与进口的斗争)
发布评论