本帖最後由 3ldk 於 2019-10-16 09:44 編輯
我參考依度, 但唔係用npm install, 直接unzip js放係html隔離
https://openlayers.org/en/latest/doc/tutorials/bundle.html- <!DOCTYPE HTML>
- <html>
- <head>
- <style>
- #map {
- width: 1600px;
- height: 1200px;
- }
- </style>
- </head>
- <body>
- <div id="map"></div>
- <script src="app.js"></script>
- </body>
- </html>
複製代碼- import './ol/ol.css';
- import {Map, View} from './ol';
- import TileLayer from './ol/layer/Tile';
- import OSM from './ol/source/OSM';
- // import 'ol/ol.js'
- const map = new ol.Map({
- target: 'map',
- layers: [
- new ol.layer.Tile({
- source: new ol.source.OSM()
- })
- ],
- view: new ol.View({
- center: [0, 0],
- zoom: 0
- })
- });
複製代碼 但依個import用唔到, Uncaught SyntaxError: Cannot use import statement outside a module
google上d人話要build先得, 但我check過chrome一早support import
https://www.zhangxinxu.com/wordp ... port-import-module/
我當唔support import css, 但就算remove第一句, 都係相同error
我又參考左其他教學, 改成咁樣import, 但一樣唔得- // import './ol/ol.css';
- // import {Map, View} from './ol';
- // import TileLayer from './ol/layer/Tile';
- // import OSM from './ol/source/OSM';
- import 'ol/ol.js'
- const map = new ol.Map({
- target: 'map',
- layers: [
- new ol.layer.Tile({
- source: new ol.source.OSM()
- })
- ],
- view: new ol.View({
- center: [0, 0],
- zoom: 0
- })
- });
複製代碼 正確import方法應該係點樣? |