飞行到位置
使用飞行动画访问位置;
<!DOCTYPE html>
<html lang="en">
<head>
<title>飞行到位置</title>
<meta property="og:description" content="使用飞行动画访问位置" />
<meta charset='utf-8'>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel='stylesheet' href='https://unpkg.com/maplibre-gl@5.5.0/dist/maplibre-gl.css' />
<script src='https://unpkg.com/maplibre-gl@5.5.0/dist/maplibre-gl.js'></script>
<style>
body { margin: 0; padding: 0; }
html, body, #map { height: 100%; }
</style>
</head>
<body>
<style>
#fly {
display: block;
position: relative;
margin: 0px auto;
width: 50%;
height: 40px;
padding: 10px;
border: none;
border-radius: 3px;
font-size: 12px;
text-align: center;
color: #fff;
background: #ee8a65;
}
</style>
<div id="map"></div>
<button id="fly">飞行</button>
<script>
const map = new maplibregl.Map({
container: 'map',
style:
'https://api.maptiler.com/maps/streets/style.json?key=get_your_own_OpIi9ZULNHzrESv6T2vL',
center: [-74.5, 40],
zoom: 9
});
document.getElementById('fly').addEventListener('click', () => {
// 飞到纽约市曼哈顿
map.flyTo({
center: [-74.0066, 40.7135],
essential: true // 此动画被视为对用户导航必不可少的
});
});
</script>
</body>
</html>