mirror of https://gitee.com/antv-l7/antv-l7
100 lines
2.6 KiB
HTML
100 lines
2.6 KiB
HTML
|
<!DOCTYPE html>
|
||
|
<html lang="en">
|
||
|
<head>
|
||
|
<meta charset="UTF-8">
|
||
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||
|
<meta http-equiv="X-UA-Compatible" content="ie=edge">
|
||
|
<meta name="geometry" content="diagram">
|
||
|
<link rel="stylesheet" href="./assets/common.css">
|
||
|
<link rel="stylesheet" href="./assets/info.css">
|
||
|
<title>animateLine</title>
|
||
|
<style>
|
||
|
#map { position:absolute; top:0; bottom:0; width:100%; }
|
||
|
.amap-maps {
|
||
|
cursor: auto !important
|
||
|
}
|
||
|
</style>
|
||
|
</head>
|
||
|
|
||
|
<body>
|
||
|
<div id="map"></div>
|
||
|
<script src="https://webapi.amap.com/maps?v=1.4.8&key=15cd8a57710d40c9b7c0e3cc120f1200&plugin=Map3D"></script>
|
||
|
<script src="./assets/jquery-3.2.1.min.js"></script>
|
||
|
<script src="./assets/dat.gui.min.js"></script>
|
||
|
<script src="../build/L7.js"></script>
|
||
|
<script>
|
||
|
var geojson = {
|
||
|
"type": "FeatureCollection",
|
||
|
"features": [{
|
||
|
"type": "Feature",
|
||
|
"geometry": {
|
||
|
"type": "LineString",
|
||
|
"coordinates": [
|
||
|
[0, 0],
|
||
|
[0.001, 0.0001]
|
||
|
]
|
||
|
}
|
||
|
} ]
|
||
|
};
|
||
|
var speedFactor = 30; // number of frames per longitude degree
|
||
|
var animation; // to store and cancel the animation
|
||
|
var startTime = 0;
|
||
|
var progress = 0; // progress = timestamp - startTime
|
||
|
var resetTime = false; // indicator of whether time reset is needed for the animation
|
||
|
var pauseButton = document.getElementById('pause');
|
||
|
const scene = new L7.Scene({
|
||
|
id: 'map',
|
||
|
mapStyle: 'light', // 样式URL
|
||
|
center: [ 120.19382669582967, 30.258134 ],
|
||
|
pitch: 0,
|
||
|
zoom: 2,
|
||
|
maxZoom:20,
|
||
|
minZoom:0,
|
||
|
});
|
||
|
scene.on('loaded', () => {
|
||
|
const linelayer = scene.LineLayer({
|
||
|
zIndex: 2
|
||
|
})
|
||
|
.source(geojson)
|
||
|
.size([2,1])
|
||
|
.shape('line')
|
||
|
.color( "#2894E0")
|
||
|
.render();
|
||
|
startTime = performance.now();
|
||
|
animateLine(0);
|
||
|
function animateLine(timestamp) {
|
||
|
if (resetTime) {
|
||
|
// resume previous progress
|
||
|
startTime = performance.now() - progress;
|
||
|
resetTime = false;
|
||
|
} else {
|
||
|
progress = timestamp - startTime;
|
||
|
}
|
||
|
|
||
|
// restart if it finishes a loop
|
||
|
if (progress > speedFactor * 360) {
|
||
|
startTime = timestamp;
|
||
|
geojson.features[0].geometry.coordinates = [
|
||
|
[0, 0],
|
||
|
[0.001, 0.0001]
|
||
|
];
|
||
|
} else {
|
||
|
var x = progress / speedFactor;
|
||
|
// draw a sine wave with some math.
|
||
|
var y = Math.sin(x * Math.PI / 90) * 40;
|
||
|
// append new coordinates to the lineString
|
||
|
|
||
|
geojson.features[0].geometry.coordinates.push([x, y]);
|
||
|
// then update the map
|
||
|
linelayer.setData(geojson);
|
||
|
}
|
||
|
// Request the next frame of the animation.
|
||
|
animation = requestAnimationFrame(animateLine);
|
||
|
}
|
||
|
});
|
||
|
|
||
|
</script>
|
||
|
</body>
|
||
|
</html>
|
||
|
|