跳到主要内容
版本:9.4.1

人流轨迹线

支持根据实时点位数据,添加客流运动轨迹,可叠加热力图,表达人流密度。

show
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport"
content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0" />
<meta http-equiv="X-UA-Compatible" content="ie=edge" />
<title>人流轨迹线</title>
<style>
* {
margin: 0;
padding: 0;
}

#map {
position: absolute;
top: 0;
bottom: 0;
width: 100%;
}
</style>
<script src="https://delivery.mapmost.com/cdn/sdk/webgl/v9.4.1/mapmost-webgl-min.js"></script>
</head>

<body>
<div id="map"></div>
<script type="module">
let map = new mapmost.Map({
container: 'map',
style: "<your style url>",
doubleClickZoom: false,
center: [120.62038700000, 31.29425900000],
zoom: 17.70172744,
pitch: 49,
bearing: -54.10626584095007,
env3D: {
envMap: '../example_data/hdr/WhiteBG_Ref_1K.hdr',
exposure: 2.1,
},
userId: "***" // 授权码
});

var clearTime; //记录定时器
var updateTrack; // 轨迹线更新函数
let coordinates; // 轨迹线显示范围
map.on('load', () => {
fetch('../example_data/MS_geojson_4326/1.geojson')
.then((response) => response.json())
.then((data) => {
let corrdsArr = data.features.map(item => ([...item.geometry.coordinates[0]])); //轨迹线坐标

coordinates = [
[120.6197603360585, 31.294470027390457, 13.2],
[120.6204842425334, 31.29453587751171, 13.2],
[120.62055679627873, 31.29382247164118, 13.2],
[120.61973629012873, 31.29371477339817, 13.2]
]

let models_obj = ["0F_ENTRANCE", "0F_FLOOR", "B1F_FLOOR", "B1F_OFFICE", "B1F_OTHERS", "B1F_XRAY", "B2F_FLOOR", "B2F_OFFICE", "B2F_OTHERS", "B3F_FLOOR", "B3F_OFFICE", "B3F_OTHERS"].map(item => ({
type: 'glb',
url: "../example_data/szdt/" + item + ".glb",
}));

let modelOptions = {
id: 'model_id',
type: 'model',
models: models_obj,
center: [120.62038700000, 31.29425900000, 0],
};

let lineOptions = {
id: 'line',
type: 'model',
callback: function (group, layer) {
let options = {
resolution: 2048, // 画布分辨率
range: coordinates, // 显示轨迹线区域的坐标
data: corrdsArr, // 轨迹线的位置数据
height: 13.5, // 显示轨迹线区域平面的高度
trackColor: "#63E8FF" // 轨迹线的颜色
}

// 添加轨迹线
layer.addTrackLines(options, function (updateTrackLines) {
updateTrack = updateTrackLines;
})
}
};

map.addLayer(modelOptions);
map.addLayer(lineOptions)
});
})

let count = 1;
map.on('click', function (e) {
if (clearTime) {
window.clearInterval(clearTime);
}
clearTime = setInterval(function () {
let dataUrl = '../example_data/MS_geojson_4326/' + count + '.geojson';
fetch(dataUrl)
.then((response) => response.json())
.then((data) => {
let corrdsArr = data.features.map(item => ([...item.geometry.coordinates[0]]));
let heatPoints = data.features.map(item => ([...item.geometry.coordinates[0][item.geometry.coordinates[0].length - 1], 30]));
updateTrack(corrdsArr);
count++;
if (count >= 263) count = 1;
});
}, 1000 / 1);
})
</script>
</body>
</html>