-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbd-fence.html
77 lines (68 loc) · 2.32 KB
/
bd-fence.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
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
<!doctype html>
<html>
<head>
<meta charset="utf-8" />
<title>openlayers叠加百度地图</title>
<!-- <script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/ol.js"></script> -->
<script src="https://cdn.bootcdn.net/ajax/libs/openlayers/2.13.1/OpenLayers.debug.js"></script>
<!-- <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/ol.css"> -->
<link href="https://cdn.bootcdn.net/ajax/libs/openlayers/2.13.1/lib/Firebug/firebug.css" rel="stylesheet">
<style type="text/css">
html,
body,
#map {
margin: 0;
height: 100%;
width: 100%;
padding: 0;
}
</style>
</head>
<body>
<div id="map"></div>
<script>
/* 定义百度地图分辨率与瓦片网格 */
var resolutions = [];
for (var i = 0; i < 20; i++) {
resolutions[i] = Math.pow(2, 18 - i);
}
var tilegrid = new ol.tilegrid.TileGrid({
origin: [0, 0],
resolutions: resolutions,
tileSize: [256, 256],
});
var baiduMapLayer = new ol.layer.Tile({
title: '百度地图瓦片图',
source: new ol.source.TileImage({
projection: 'EPSG:3857',
tileGrid: tilegrid,
tilePixelRatio: devicePixelRatio,
tileUrlFunction: function (tileCoord, pixelRatio, proj) {
if (!tileCoord) {
return '';
}
var z = tileCoord[0];
var x = tileCoord[1];
var y = -tileCoord[2] - 1;
if (x < 0) {
x = 'M' + (-x);
}
if (y < 0) {
y = 'M' + (-y);
}
return 'https://maponline0.bdimg.com/tile/?qt=vtile&x=' + x + '&y=' + y + '&z=' + z + '&styles=pl&scaler=1&udt=20210730&from=jsapi3_0';
}
})
});
var map = new ol.Map({
layers: [baiduMapLayer],
view: new ol.View({
center: [12958111.00024869, 4827211.77706951],
projection: 'EPSG:3857',
zoom: 10,
}),
target: 'map'
});
</script>
</body>
</html>