openlayer展示高德瓦片卫星云图
时间: 2023-11-23 18:55:48 浏览: 141
openlayer7使用百度瓦片无偏移解决方案html+js静态
以下是展示高德瓦片卫星云图的OpenLayers代码:
```javascript
<!DOCTYPE html>
<html>
<head>
<title>OpenLayers Example</title>
<link rel="stylesheet" href="https://openlayers.org/en/v4.6.5/css/ol.css" type="text/css">
<style>
.map {
height: 400px;
width: 100%;
}
</style>
<script src="https://openlayers.org/en/v4.6.5/build/ol.js"></script>
</head>
<body>
<h2>OpenLayers Example</h2>
<div id="map" class="map"></div>
<script>
var projection = ol.proj.get('EPSG:3857');
var tileGrid = new ol.tilegrid.TileGrid({
origin: [-20037508.342789244, 20037508.342789244],
resolutions: [
156543.033928041,
78271.51696402048,
39135.75848201024,
19567.87924100512,
9783.93962050256,
4891.96981025128,
2445.98490512564,
1222.99245256282,
611.49622628141,
305.748113140705,
152.8740565703525,
76.43702828517625,
38.21851414258813,
19.109257071294063,
9.554628535647032,
4.777314267823516,
2.388657133911758,
1.194328566955879,
0.5971642834779395,
0.29858214173896974,
0.14929107086948487,
0.07464553543474244,
0.03732276771737122,
0.01866138385868561,
0.009330691929342804,
0.004665345964671402,
0.002332672982335701,
0.0011663364911678506,
0.0005831682455839253,
0.00029158412279196264,
0.00014579206139598132,
7.289603069799066e-05,
3.644801534899533e-05,
1.8224007674497667e-05,
9.112003837248834e-06
]
});
var tileUrlFunction = function(tileCoord) {
var z = tileCoord[0];
var x = tileCoord[1];
var y = -tileCoord[2] - 1;
return 'https://webst0{s}.is.autonavi.com/appmaptile?style=6&x=' + x + '&y=' + y + '&z=' + z;
};
var source = new ol.source.XYZ({
tileGrid: tileGrid,
tileUrlFunction: tileUrlFunction
});
var map = new ol.Map({
target: 'map',
layers: [
new ol.layer.Tile({
source: source
})
],
view: new ol.View({
center: ol.proj.fromLonLat([116.397428, 39.90923]),
zoom: 10
})
});
</script>
</body>
</html>
```
阅读全文