1.下载官方源码,将data拷贝到(一)中的工程中。
2.找到官方源码中的examples,选其中一个实例。如下图
3.需要对实例进行修改才能运行
将文件拷贝到目录下,改写html文件
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>zsl</title>
<style>
#map {
width: 90%;
height: 90%;
}
</style>
</head>
<body>
<!-- <div id="map"></div> -->
<a class="skiplink" href="#map">Go to map</a>
<div id="map" class="map" tabindex="0"></div>
<button id="zoom-out">Zoom out</button>
<button id="zoom-in">Zoom in</button>
<script src="./1accessible.js"></script>
</body>
</html>
改写js文件(主要改写import)其他不用改
import 'ol/ol.css';
import { Map, View } from 'ol';
import TileLayer from 'ol/layer/Tile';
import OSM from 'ol/source/OSM';
const map = new Map({
layers: [
new TileLayer({
source: new OSM()
})
],
target: 'map',
view: new View({
center: [0, 0],
zoom: 2
})
});
document.getElementById('zoom-out').onclick = function() {
const view = map.getView();
const zoom = view.getZoom();
view.setZoom(zoom - 1);
};
document.getElementById('zoom-in').onclick = function() {
const view = map.getView();
const zoom = view.getZoom();
view.setZoom(zoom + 1);
};
改写package.json文件
然后运行
npm start
源代码:https://download.youkuaiyun.com/download/zhangshuanlai/11200166