当前位置:网站首页>Web technology sharing | [Gaode map] to realize customized track playback
Web technology sharing | [Gaode map] to realize customized track playback
2022-06-23 13:57:00 【anyRTC】

Realization ( Track playback ) There are two ways :
- The first is to use
JS APIandAMap.PolyLine( Broken line ) And so on . - The second is to use
JS APIandAMapUI Component libraryIn combination with , utilizePathSimplifier( Trajectory display Components ) Draw the trajectory of action .
Options
We can implement the above two methods according to two factors To decide which one is more suitable for you : Number of nodes The amount of 、 The density of the arrangement .
The former is suitable for less nodes , The arrangement is sparse , for example , Taxi track playback , Taxis are fast , The periodic reporting time will also be relatively long . The latter is more specific to the large number of nodes 、 Arrange dense paths , Record the aircraft track of the position in seconds , Fine geographical boundaries, etc .
Implementation process
Either way , We all need to collect the information reported by the client first , This information can be customized , Usually we will include : Longitude and latitude 、 Speed 、 The geographical location after inverse coding 、 Direction 、 At an altitude of And other basic geographic information , We can also add some Customize Information about , for example : Personnel information ( Avatar nickname, etc )、 Travel information ( Orders, etc ).
The process of implementation :
- The client presses ( Time ) Periodically report geographic information and customized information .
- The server stores the information reported by the customer according to the time axis .
- Press ( Time and so on ) Query the user's track by conditions , And some nodes are removed by simplified algorithm ( for example , The node distance is very small 、 Or multiple points are in the same straight line 、3 Between points , There is a slight deviation in one point, which can not be drawn into a straight line, etc ), Finally, the path suitable for drawing ( Array ).
- Draw the user's action track according to the path .
Path simplification algorithm ( Optional )
The data reported by the client is reported according to the time cycle , That is to say, each time corresponds to a longitude and latitude , Longitude and latitude are one point after another on the map , When connecting these points , We will get N Multiple broken lines , In order to draw a more beautiful trajectory , The course of action is clearer and smoother , Usually we need an algorithm to simplify the polyline .
for example :
APoint andBspot , The distance between the two is less than1Pixels , You can get rid ofBspot , Just stayAspot .A,B,CThree points in a straight line , perhaps ,BThe point deviates only slightlyAPoint andCA line segment composed of points , thatBPoint can be removed .
An algorithm library is also recommended here simplify.js For your reference , I don't want to elaborate too much here .
Implementation example
Vehicle track playback
Here we use the first method to realize - utilize JS API and AMap.PolyLine.

Realization principle :
- Draw... On a map Vehicle markings (
AMap.Marker). - utilize
AMap.PolyLineDraw two tracks : The track of history and Track of driving path , Distinguish by color . - Drive the vehicle forward at a certain speed , And monitor
MakerMobile Events , In event callback , Put the vehicle (Marker) The location is set as the center point of the map , Give the user a subjective visual sense that the vehicle is moving forward , At the same time, extend Track of driving path . - For complex implementation scenarios , For example :
- View the data of each node , We can plot each node , When a node is clicked, the data of the node will be displayed .
- Mobile multipliers , First, play according to the reported time interval , After selecting double speed , change
MarKerThe mobileduration. - Other customizations .
Customize API
We can make the vehicle :
- Start moving
- Pause move
- Resume move
- Stop moving
Code example
AMap.plugin('AMap.MoveAnimation', function(){
var marker, lineArr = [[116.478935,39.997761],[116.478939,39.997825],[116.478912,39.998549],[116.478912,39.998549],[116.478998,39.998555],[116.478998,39.998555],[116.479282,39.99856],[116.479658,39.998528],[116.480151,39.998453],[116.480784,39.998302],[116.480784,39.998302],[116.481149,39.998184],[116.481573,39.997997],[116.481863,39.997846],[116.482072,39.997718],[116.482362,39.997718],[116.483633,39.998935],[116.48367,39.998968],[116.484648,39.999861]];
var map = new AMap.Map("container", {
resizeEnable: true,
center: [116.397428, 39.90923],
zoom: 17
});
marker = new AMap.Marker({
map: map,
position: [116.478935,39.997761],
icon: "https://a.amap.com/jsapi_demos/static/demo-center-v2/car.png",
offset: new AMap.Pixel(-13, -26),
});
// Draw historical tracks
var polyline = new AMap.Polyline({
map: map,
path: lineArr,
showDir:true,
strokeColor: "#28F", // Line color
// strokeOpacity: 1, // Line transparency
strokeWeight: 6, // Line width
// strokeStyle: "solid" // Line style
});
// Track of driving path
var passedPolyline = new AMap.Polyline({
map: map,
strokeColor: "#AF5", // Line color
strokeWeight: 6, // Line width
});
// Listen for vehicle movement events
marker.on('moving', function (e) {
// Extend the track of the driving path
passedPolyline.setPath(e.passedPath);
// Set the vehicle position as the center point of the map
map.setCenter(e.target.getPosition(),true)
});
map.setFitView();
// Start moving
window.startAnimation = function startAnimation () {
marker.moveAlong(lineArr, {
// The length of each segment
duration: 500,// It can be set according to the actual acquisition time interval
// JSAPI2.0 Whether to automatically set the angle along the road moveAlong Set in the
autoRotation: true,
});
};
// Pause move
window.pauseAnimation = function () {
marker.pauseMove();
};
// Resume move
window.resumeAnimation = function () {
marker.resumeMove();
};
// Stop moving
window.stopAnimation = function () {
marker.stopMove();
};
});
Reference link :https://lbs.amap.com/demo/jsapi-v2/example/marker/replaying-historical-running-data
Playback of flight track
Use JS API and AMapUI Component library In combination with , utilize PathSimplifier( Trajectory display Components ) Draw the trajectory of action , This scheme is relatively simple , Only some configuration is required , For example, the double speed playback in scheme 1 needs to be calculated , At the same time, it also has the disadvantage of not dynamically changing the multiple speed , But scheme two will not exist .
Realization principle :
- Draw... On a map Aircraft marking (
AMap.Marker). - utilize
AMap.PolyLineDraw two tracks : The track of history and Track of driving path , Distinguish by color . - Configure the color of the track , Animation speed and so on .
- For complex implementation scenarios , Which need to be customized , Can be in
PathSimplifierConfiguration and processing in the callback provided .
Sample code
// load PathSimplifier,loadUI The path parameter of is in the module name 'ui/' The next part
AMapUI.load(['ui/misc/PathSimplifier'], function(PathSimplifier) {
if (!PathSimplifier.supportCanvas) {
alert(' The current environment does not support Canvas!');
return;
}
// Launch page
initPage(PathSimplifier);
});
function initPage(PathSimplifier) {
// Create a component instance
var pathSimplifierIns = new PathSimplifier({
zIndex: 100,
map: map, // The map instance to which it belongs
getPath: function(pathData, pathIndex) {
// Returns the node coordinate information in the track data ,[AMap.LngLat, AMap.LngLat...] perhaps [[lng|number,lat|number],...]
return pathData.path;
},
getHoverTitle: function(pathData, pathIndex, pointIndex) {
// Returns the information displayed when the mouse hovers
if (pointIndex >= 0) {
// Hover over a track node
return pathData.name + ', spot :' + pointIndex + '/' + pathData.path.length;
}
// Hover over the connection between nodes
return pathData.name + ', Number of points ' + pathData.path.length;
},
renderOptions: {
// Track line style
pathLineStyle: {
strokeStyle: 'red',
lineWidth: 6,
dirArrowStyle: true
}
}
});
// Here we build two simple tracks , For example only
pathSimplifierIns.setData([{
name: ' The trajectory 0',
path: [
[100.340417, 27.376994],
[108.426354, 37.827452],
[113.392174, 31.208439],
[124.905846, 42.232876]
]
}, {
name: ' Ground wire ',
// Create a message that includes 500 A geodesic line of interpolation points
path: PathSimplifier.getGeodesicPath([116.405289, 39.904987], [87.61792, 43.793308], 500)
}]);
// Create a cruiser
var navg0 = pathSimplifierIns.createPathNavigator(0, // Related to chapter 1 Tracks
{
loop: true, // Loop Playback
speed: 1000000
});
navg0.start();
}
Reference link :https://lbs.amap.com/demo/amap-ui/demos/amap-ui-pathsimplifier/index

边栏推荐
- pyqt5之designer制作表格
- Tencent cloud tdsql-c heavy upgrade, leading the cloud native database market in terms of performance
- 【深入理解TcaplusDB技术】单据受理之表管理
- 白皮书丨英特尔携手知名RISC-V工具提供商Ashling,着力扩展多平台RISC-V支持
- Getting started with reverse debugging - learn about PE structure files
- 微信小程序之在wx:for中绑定事件
- 中断和轮询
- Kali use
- Runtime application self-protection (rasp): self-cultivation of application security
- Flutter Clip剪裁组件
猜你喜欢

How deci and Intel can achieve up to 16.8x throughput improvement and +1.74% accuracy improvement on mlperf

MySQL single database and table splitting using MYCAT

Shell process control - 39. Special process control statements

Common usage of OS (picture example)

Former amd chip architect roast said that the cancellation of K12 processor project was because amd counseled!

KS007基于JSP实现人个人博客系统

First exposure! The only Alibaba cloud native security panorama behind the highest level in the whole domain

How to write vite plug-ins

leetcode:42. Rain water connection

【深入理解TcaplusDB技术】单据受理之表管理
随机推荐
【深入理解TcaplusDB技术】单据受理之表管理
4-way telephone +1-way Gigabit Ethernet 4-way PCM telephone optical transceiver
【深入理解TcaplusDB技术】Tmonitor系统升级
Hanyuan high tech new generation green energy-saving Ethernet access industrial switch high efficiency energy-saving Gigabit Industrial Ethernet switch
『忘了再学』Shell流程控制 — 39、特殊流程控制语句
Yyds dry inventory solution sword finger offer: judge whether it is a balanced binary tree
Learning experiences on how to design reusable software from three aspects: class, API and framework
[deeply understand tcapulusdb technology] transaction execution of document acceptance
微信小程序之在wx:for中绑定事件
Flutter Clip剪裁组件
php接收和发送数据
Quartus call & design D trigger Simulation & timing wave verification
Use openvinotm preprocessing API to further improve the reasoning performance of yolov5
You call this shit MQ?
串口、COM、UART、TTL、RS232(485)区别详解
leetcode:42. Rain water connection
微信小程序之input调整
Crmeb second open SMS function tutorial
AGCO AI frontier promotion (6.23)
实战 | 如何制作一个SLAM轨迹真值获取装置?