原文链接及内容

运行界面

本例使用来自Stadia Maps高清切片数据,展示了一幅Alidade Smooth Dark主题风格的地图。

注:Stadia Maps的图层不需要API密钥来localhost开发或大多数生产网络部署,详见:https://docs.stadiamaps.com/authentication/

main.js代码如下:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
import Map from 'ol/Map.js';
import StadiaMaps from 'ol/source/StadiaMaps.js';
import TileLayer from 'ol/layer/Tile.js';
import View from 'ol/View.js';
import {fromLonLat} from 'ol/proj.js';

const map = new Map({
layers: [
// NOTE: Layers from Stadia Maps do not require an API key for localhost development or most production
// web deployments. See https://docs.stadiamaps.com/authentication/ for details.
//Stadia Maps的图层不需要API密钥来localhost开发或大多数生产网络部署
//详见:https://docs.stadiamaps.com/authentication/
new TileLayer({
source: new StadiaMaps({
layer: 'alidade_smooth_dark',
retina: true,
// apiKey: 'OPTIONAL'
}),
}),
],
target: 'map',
view: new View({
center: fromLonLat([24.750645, 59.444351]),
zoom: 14,
}),
});

界面布局文件index.html代码如下:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Stadia Maps (Retina Tiles)</title>
<link rel="stylesheet" href="node_modules/ol/ol.css">
<style>
.map {
width: 100%;
height: 400px;
}
</style>
</head>
<body>
<div id="map" class="map"></div>

<script type="module" src="main.js"></script>
</body>
</html>