123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313 |
- (function () {
- var page = {
- init: function ($page, param) {
- //页面初始化
- renlian.layer.loading(true, "加载数据中");
- var userinfo = renlian.storage.get('userinfo');
- $('#route-gpsNumber').text(userinfo.baseinfo.gpsNumber);
- $('#date-time').text('时间:'+param.textData.lastTime || '0000-00-00 00:00:00');
- $('#vehicle-speed').text('速度:'+param.textData.speed+' km/h')
-
- //播放控制相关事件清除
- function removeEvents(){
- $("#play-pause").off("tap");
- $(".icon-last").off("tap");
- $(".icon-next").off("tap");
- $(".speed-set").off("tap");
- }
- //地图初始化
- var routeMap = new AMap.Map('route-map', {
- center: param.defaultCenter,
- zoom: 15
- });
- routeMap.on('complete', function(){
- renlian.layer.loading(false);
- });
- //test
- var initPage = function(PathSimplifier, data) {
- removeEvents();
- if(!data){
- if( window.pathSimplifierIns){
- window.pathSimplifierIns.setData([]);
- window.pathSimplifierIns = null;
- }
- $page.find('.icon-bofang').on('tap', function () {
- renlian.layer.toast('当前日期无轨迹');
- });
- return;
- }
- removeEvents();
- if(window.pathSimplifierIns){
- window.pathSimplifierIns.setData([]);
- window.pathSimplifierIns = null;
- }
- //创建组件实例
- var pathSimplifierIns = new PathSimplifier({
- zIndex: 100,
- map: routeMap, //所属的地图实例
- getPath: function(pathData, pathIndex) {
- //返回轨迹数据中的节点坐标信息,[AMap.LngLat, AMap.LngLat...] 或者 [[lng|number,lat|number],...]
- // return pathData.path;
-
- var points = pathData.points,
- lnglatList = [];
- for (var i = 0, len = points.length; i < len; i++) {
- lnglatList.push(points[i].lngLat);
- }
- return lnglatList;
- },
- renderOptions: {
- //轨迹线的样式
- pathLineStyle: {
- strokeStyle: 'red',
- lineWidth: 6,
- dirArrowStyle: true
-
- },
- eventSupport: false,
- //巡航线样式
- pathNavigatorStyle:{
- pathLinePassedStyle:{
- lineWidth:2
- },
- },
-
-
- },
- });
-
- pathSimplifierIns.setData(data);
-
- //创建一个巡航器
- var navg0 = pathSimplifierIns.createPathNavigator(0, //关联第1条轨迹
- {
- loop: false, //循环播放
- speed: 1000
- });
-
- //播放速度控制
- $page.find('.speed-set').on('tap', function () {
- var speedSign = $page.find('#speed-icon');
- if(speedSign.hasClass('icon-beisu1')){
- speedSign.removeClass('icon-beisu1');
- speedSign.addClass('icon-beisu2');
- $page.find('.speed-level').html('中速');
- navg0.setSpeed(2*1000);
- }else if(speedSign.hasClass('icon-beisu2')){
- speedSign.removeClass('icon-beisu2');
- speedSign.addClass('icon-beisu4');
- $page.find('.speed-level').html('快速');
- navg0.setSpeed(4*1000);
- }else if(speedSign.hasClass('icon-beisu4')){
- speedSign.removeClass('icon-beisu4');
- speedSign.addClass('icon-beisu1');
- $page.find('.speed-level').html('慢速');
- navg0.setSpeed(1000);
- }
- });
- // 播放暂停切换
- $page.find('#play-pause').on('tap', function () {
- var playSign = $page.find('#play-pause');
- if(playSign.hasClass('icon-bofang')){
- playSign.removeClass('icon-bofang');
- playSign.addClass('icon-zanting');
- if(navg0.getNaviStatus() == 'stop'){
- navg0.start();
- }else{
- navg0.resume();
- }
- }else{
- playSign.removeClass('icon-zanting');
- playSign.addClass('icon-bofang');
- navg0.pause();
- }
- });
- //节点控制
- $page.find('.icon-last').on('tap', function () {
- if(navg0.getNaviStatus() == 'stop'){
- return;
- }
- if(navg0.getNaviStatus() == 'moving'){
- navg0.pause();
- // $('#play-pause').removeClass('icon-zanting');
- // $('#play-pause').addClass('icon-bofang');
- }
- //当前节点索引
- var presentNode = navg0.getCursor().idx;
- if(presentNode == 0){
- navg0.moveToPoint(0, 0);
- return;
- }
- navg0.moveToPoint(presentNode-1, 0);
- pathSimplifierIns.render();
- });
- $page.find('.icon-next').on('tap', function () {
- if(navg0.getNaviStatus() == 'stop'){
- navg0.start();
- navg0.pause();
- // return;
- }
- if(navg0.getNaviStatus() == 'moving'){
- navg0.pause();
- // $('#play-pause').removeClass('icon-zanting');
- // $('#play-pause').addClass('icon-bofang');
- }
- var endNode = navg0.getPathEndIdx();
- var presentNode = navg0.getCursor().idx;
- if(presentNode == endNode){
- return;
- }
- navg0.moveToPoint(presentNode+1, 0);
- pathSimplifierIns.render();
- });
- //重置
- $page.find('.icon-reset').on('tap', function () {
- navg0.moveToPoint(0, 0);
- navg0.stop();
- });
- //检测末端
- navg0.on('pause', function(){
- $('#play-pause').removeClass('icon-zanting');
- $('#play-pause').addClass('icon-bofang');
- });
- navg0.on('stop', function(){
- $('#play-pause').removeClass('icon-zanting');
- $('#play-pause').addClass('icon-bofang');
- });
- // $page.find('.text-area').on('tap', function(){
- // navg0.destroy();
- // });
- var pathData = pathSimplifierIns.getPathData(0).points;;
- navg0.on('move', function(){
- var presentIndex = navg0.getCursor().idx;
- var time = pathData[presentIndex].time;
- var speed = pathData[presentIndex].speed;
- if(!speed){
- speed = 0;
- }
- $('#date-time').text('时间:'+time);
- $('#vehicle-speed').text('速度:'+speed+'km/h');
- });
- window.pathSimplifierIns = pathSimplifierIns;
-
- }
-
- AMapUI.load(['ui/misc/PathSimplifier'], function(PathSimplifier) {
- if (!PathSimplifier.supportCanvas) {
- alert('当前环境不支持 Canvas!');
- return;
- }
- $page.find('.date-set').rldate({
- type: 'date'
- },function(date){
-
- // $page.find('.f-dtpicker-ok').on('tap', function(){
-
- // });
- var pattern = /\d{4}(\-|\/|.)\d{1,2}\1\d{1,2}/;
-
- if(!pattern.test(date)){
- renlian.layer.toast('请选择正确轨迹的日期');
- return;
- }
- var post_data = {
- "date":date,
- "gpsNumber": userinfo.baseinfo.gpsNumber
- }
- var geocoder = null;
- renlian.httppost(config.webapi+'?s=api/get_gps_route_table',post_data,function(res){
- if(!geocoder){
- geocoder = new AMap.Geocoder({
- radius: 500 //范围,默认:500
- });
- }
- if(!res.success){
- renlian.layer.toast(res.message);
- }
- var data = null;
- if(res.data){
- data = [{name:'test1',points:[]}];
- JSON.parse(res.data).forEach(v => {
- data[0].points.push({speed:v.speed, lngLat:[v.lng, v.lat], time:v.deviceTime});
- // lngLats.push([v.lng, v.lat]);
- });
- }
- initPage(PathSimplifier, data);
- });
- });
- console.log('ddddddddddddddddddddddddd')
- console.log(userinfo.baseinfo.gpsNumber);
-
- //启动页面
- // initPage(PathSimplifier);
- // 6789012345
- var nowDate = new Date().Format("yyyy-MM-dd");
- var post_data = {
- "date": nowDate,
- "gpsNumber": userinfo.baseinfo.gpsNumber
- }
- renlian.httppost(config.webapi+'?s=api/get_gps_route_table',post_data,function(res){
- if(!res.success){
- renlian.layer.toast(res.message);
- }
- var data = null;
- if(res.data){
- data = [{name:'test1',points:[]}];
- JSON.parse(res.data).forEach(v => {
- data[0].points.push({speed:v.speed, lngLat:[v.lng, v.lat], time:v.deviceTime});
- // lngLats.push([v.lng, v.lat]);
- });
- }
- initPage(PathSimplifier, data);
- });
- });
-
-
- }
- };
- return page;
- })();
|