原文链接及内容

原文链接:https://openlayers.org/en/latest/examples/mobile-full-screen.html ,这里仅是一个运行结果页面

运行界面

本例的源代码来源于官方源代码。示例仅给出了运行页面。

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
27
28
29
30
31
32
import BingMaps from '../src/ol/source/BingMaps.js';
import Geolocation from '../src/ol/Geolocation.js';
import Map from '../src/ol/Map.js';
import TileLayer from '../src/ol/layer/Tile.js';
import View from '../src/ol/View.js';

const view = new View({
center: [0, 0],
zoom: 2,
});

const map = new Map({
layers: [
new TileLayer({
source: new BingMaps({
key: 'AlEoTLTlzFB6Uf4Sy-ugXcRO21skQO7K8eObA5_L-8d20rjqZJLs2nkO1RMjGSPN',
imagerySet: 'RoadOnDemand',
}),
}),
],
target: 'map',
view: view,
});

const geolocation = new Geolocation({
projection: view.getProjection(),
tracking: true,
});
geolocation.once('change:position', function () {
view.setCenter(geolocation.getPosition());
view.setResolution(2.388657133911758);
});

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

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="initial-scale=1.0, user-scalable=no, width=device-width">
<title>Mobile full screen example</title>
<link rel="stylesheet" type="text/css" href="/theme/ol.css">
<link rel="stylesheet" type="text/css" href="/theme/site.css">
<style>
html, body, .map {
margin: 0;
padding: 0;
width: 100%;
height: 100%;
}
</style>
</head>
<body>
<div id="map" class="map"></div>
<script src="https://cdn.jsdelivr.net/npm/elm-pep@1.0.6/dist/elm-pep.js"></script>
<script src="mobile-full-screen.js"></script>
<script src="common.js"></script>
</body>
</html>