效果图:
*
[![20200508_183147.mp4 (447.42KB)](https://gw.alipayobjects.com/mdn/prod_resou/afts/img/ANNs6TKOR3isAAAAAAAAAAABkARQnAQ)](https://www.yuque.com/blueheart/blog/hlckeg?_lake_card=%7B%22status%22%3A%22done%22%2C%22name%22%3A%2220200508_183147.mp4%22%2C%22size%22%3A458163%2C%22percent%22%3A100%2C%22taskId%22%3A%222NVucy2b3K0o%22%2C%22margin%22%3Atrue%2C%22id%22%3A%22hB5dr%22%2C%22videoId%22%3A%22inputs%2Fprod%2Fyuque%2F2020%2F726433%2Fmp4%2F1588934122691-c09f232d-a7ea-4082-ac13-010540d9a07d.mp4%22%2C%22card%22%3A%22video%22%7D#hB5dr)> 上代码,方便以后查阅!
1、html 文件
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>个人轨迹图</title>
<meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
<meta name="apple-mobile-web-app-capable" content="yes"> <!-- Fullscreen Landscape on iOS -->
<link rel="stylesheet" href="../css/common.css">
</head>
<body>
<div id="main"></div>
<script src="../js/echarts.js"></script>
<script src="../js/echarts-gl.min.js"></script>
<script src="../js/jquery.min.js"></script>
<script src="../js/bmap.min.js"></script>
<script src="../data/data.js"></script>
<script src="../set/settings.js"></script>
<script type="text/javascript" src="http://api.map.baidu.com/api?v=2.0&ak=yPCSLTLWeViz91a5GxkPcn5d2OzQlkcY"></script>
<script>
var myChart = echarts.init(document.getElementById('main'));
console.log(data);
if(colorOrWidth == 0){
var lines2 = data.features.map(function(theD){
return{
coords:theD.geometry.coordinates
}
})
};
if(colorOrWidth == 1){
var lines2 = data.features.map(function(theD){
return{
coords:theD.geometry.coordinates,
lineStyle:{
normal:{
color: theColorRamp[theD.properties.value-1],
}
}
}
})
}
if(colorOrWidth == 2){
var lines2 = data.features.map(function(theD){
return{
coords:theD.geometry.coordinates,
lineStyle:{
normal:{
width: theD.properties.value * theWidthRatio,
}
}
}
})
}
if(colorOrWidth == 3){
var lines2 = data.features.map(function(theD){
return{
coords:theD.geometry.coordinates,
lineStyle:{
normal:{
color: theColorRamp[theD.properties.value-1],
width: theD.properties.value * theWidthRatio
}
}
}
})
}
myChart.setOption(option = {
bmap: {
center: theCenter,
zoom: theZoom,
roam: true,
mapStyle: {
'styleJson': mapStyle
}
},
series: [{
type: 'lines',
coordinateSystem: 'bmap',
polyline: true,
data: lines2,
silent: true,
lineStyle: {
normal: {
// color: '#c23531',
color: theColor,
opacity: theOpac,
width: theWidth
}
},
progressiveThreshold: 500,
progressive: 200
}, {
type: 'lines',
coordinateSystem: 'bmap',
polyline: true,
data: lines2,
lineStyle: {
normal: {
width: 0
}
},
effect: {
period: thePeriod,
constantSpeed: theSpeed,
show: effectShow,
trailLength: theEffLength,
symbolSize: theEffWidth
},
zlevel: 1
}]
});
</script>
</body>
</html>
2、setting 文件
// 此脚本用于修改图表的参数
// 路线属性
var colorOrWidth = 3; // 0代表既不用色彩也不用宽度来表示值,1代表用色彩,2代表用宽度,3代表二者皆用
var theColorRamp = ['#49FF94', '#FFFD2A', '#FF2594', '#ff2a36', '#e0f3f8', '#ffffbf', '#fee090', '#fdae61', '#f46d43', '#d73027']; // 路线颜色
var theWidthRatio = 0.2 // 宽度与值的比值
// 固定属性,当该属性没有和值相关,会自动设成如下值
var theColor = 'rgb(200, 35, 45)'; // 线的颜色
var theWidth = 3; // 线的宽度
var theOpac = 0.3; // 线的透明度
// 地图相关
var theCenter = [114.066239, 22.531889]; // 中心点坐标
var theZoom = 18; //视角远近 数字
// 动画效果
var effectShow = true;// 是否展示动画
var theSpeed = 0; // 尾迹速度,当尾迹速度不等于 0 时,使用单次循环时间作为速度依据
var thePeriod = 2; // 单次循环时间,只有当尾迹速度为 0 时才能生效
var theEffWidth = 6; // 尾迹宽度
var theEffLength = 0.5; // 尾迹长度
// 百度地图
// 百度地图的accesstoken需要到 html 的第18行 自行进行替换
var mapStyle = [
{
"featureType": "water",
"elementType": "all",
"stylers": {
"color": "#021019"
}
},
{
"featureType": "highway",
"elementType": "geometry.fill",
"stylers": {
"color": "#000000"
}
},
{
"featureType": "highway",
"elementType": "geometry.stroke",
"stylers": {
"color": "#147a92"
}
},
{
"featureType": "arterial",
"elementType": "geometry.fill",
"stylers": {
"color": "#000000"
}
},
{
"featureType": "arterial",
"elementType": "geometry.stroke",
"stylers": {
"color": "#0b3d51"
}
},
{
"featureType": "local",
"elementType": "geometry",
"stylers": {
"color": "#000000"
}
},
{
"featureType": "land",
"elementType": "all",
"stylers": {
"color": "#08304b"
}
},
{
"featureType": "railway",
"elementType": "geometry.fill",
"stylers": {
"color": "#000000"
}
},
{
"featureType": "railway",
"elementType": "geometry.stroke",
"stylers": {
"color": "#08304b"
}
},
{
"featureType": "subway",
"elementType": "geometry",
"stylers": {
"lightness": -70
}
},
{
"featureType": "building",
"elementType": "geometry.fill",
"stylers": {
"color": "#000000"
}
},
{
"featureType": "all",
"elementType": "labels.text.fill",
"stylers": {
"color": "#857f7f"
}
},
{
"featureType": "all",
"elementType": "labels.text.stroke",
"stylers": {
"color": "#000000"
}
},
{
"featureType": "building",
"elementType": "geometry",
"stylers": {
"color": "#022338"
}
},
{
"featureType": "green",
"elementType": "geometry",
"stylers": {
"color": "#062032"
}
},
{
"featureType": "boundary",
"elementType": "all",
"stylers": {
"color": "#1e1c1c"
}
},
{
"featureType": "manmade",
"elementType": "geometry",
"stylers": {
"color": "#022338"
}
},
{
"featureType": "poi",
"elementType": "all",
"stylers": {
"visibility": "off"
}
},
{
"featureType": "all",
"elementType": "labels.icon",
"stylers": {
"visibility": "off"
}
},
{
"featureType": "all",
"elementType": "labels.text.fill",
"stylers": {
"color": "#2da0c6",
"visibility": "on"
}
}
]
3、数据格式:
将shp文件转换成geojson,替换到 data.js 文件中
data.js
相关代码:
var data = {geojson 数据}