(function () { var page = { init: function ($page) { //初始化顶部导航栏 function init_nav(){ var _html = ''; _html += '
'; _html += ''; _html += '
'; /* _html += '\ '; */ _html += '\
\ \
'; _html += '
'; _html += ''; _html += '
'; _html += '
'; _html += ''; _html += ''; _html += '
'; $page.parent().find('.f-page-header').addClass('lr-workspace-header').html(_html); /* // 点击搜索框 $page.parent().find('.searchBox').on('tap', function () { learun.nav.go({ path: 'workspace/search', title: '', isBack: true, isHead: true }); }); */ // 点击报警 $page.parent().find('.alarm').on('tap', function () { learun.nav.go({ path: 'baojingindex', title: '110丢失报警', isBack: true, isHead: true,type:'right' }); }); // 点击图表 $page.parent().find('.chart').on('tap', function () { learun.nav.go({ path: 'tongji', title: '统计', isBack: true, isHead: true,type:'right' }); }); // 点击消息图标 $page.parent().find('.message').on('tap', function () { learun.nav.go({ path: 'baojinginfo', title: '消息', isBack: true, isHead: true,type:'right' }); }); $page.parent().find('.my').on('tap', function () { learun.nav.go({ path: 'my', title: '我的', isBack: true, isHead: true,type:'right' }); }); // 注册扫描 $page.parent().find('.scanner').on('tap', function () { learun.code.scan(function (res) { if (res.status === 'success') { learun.layer.toast(res.msg); } else { learun.layer.toast('扫描失败:' + res.msg); } }); }); } //获取手机GPS位置 function get_mobile_gps_location(onSuccess,onError){ var onSuccess = function(position) { alert('Latitude: ' + position.coords.latitude + '\n' + 'Longitude: ' + position.coords.longitude + '\n' + 'Altitude: ' + position.coords.altitude + '\n' + 'Accuracy: ' + position.coords.accuracy + '\n' + 'Altitude Accuracy: ' + position.coords.altitudeAccuracy + '\n' + 'Heading: ' + position.coords.heading + '\n' + 'Speed: ' + position.coords.speed + '\n' + 'Timestamp: ' + position.timestamp + '\n'); }; // onError Callback receives a PositionError object // function onError(error) { alert('code: ' + error.code + '\n' + 'message: ' + error.message + '\n'); } navigator.geolocation.getCurrentPosition(onSuccess, onError); } var userinfo = learun.storage.get('userinfo'); //上报客户端极光注册信息 function update_jg_registrationid(){ if(window.lrmui.jgRegistrationId){ var post_data = { "regid":window.lrmui.jgRegistrationId, "uid":userinfo.baseinfo.userId }; learun.httppost(config.webapi+'?s=api/update_jg_registrationid',post_data,function(res){ }); } } learun.layer.loading(true, "加载数据中"); if(window.lrmui.isreal){ //上报用户极光推注册信息 update_jg_registrationid(); //获取手机GPS位置信息 get_mobile_gps_location(); } init_nav(); //车辆信息初始化 learun.timeInterval = 5000; //地图初始化 learun.map = new AMap.Map('amapcontainer'); learun.map.on('complete', function(){ learun.layer.loading(false); }); learun.vehicleMarker = new AMap.Marker({icon:'./images/bicycle.png', offset:new AMap.Pixel(0, -51)}); learun.circle = new AMap.Circle({ borderWeight: 3, strokeColor: "#FF33FF", strokeOpacity: 1, strokeWeight: 6, strokeOpacity: 0.2, fillOpacity: 0.2, strokeStyle: 'dashed', strokeDasharray: [10, 10], // 线样式还支持 'dashed' fillColor : '#1791fc', zIndex: 50, }); // learun.vehicleInfoWin = new AMap.InfoWindow({ // isCustom: true, // offset: new AMap.Pixel(60, -40), // content: '
位置导航XX小区...
' // }); learun.data = {map:learun.map, vehicle:learun.vehicleMarker, circle:learun.circle, infoWin:learun.vehicleInfoWin}; learun.getVehicleData = function(t, first=false){ var deviceNumber = 'A00000000031'; var mapData = null; learun.httpget(config.webapi+"/?s=api/get_map_index_data", {deviceNumber:deviceNumber}, function (_res) { console.log("******** "+JSON.stringify(_res)); // console.log(_res); mapData = _res.data; if(!mapData){ learun.layer.warning('无地图数据,请检测网络或联系管理员!', function () { }, '提示', '关闭'); return; } // console.log(mapData); var vehiclePt = new AMap.LngLat(+mapData.vehicleLocation.longitude, +mapData.vehicleLocation.latitude) if(first){ t.map.setZoomAndCenter(15,vehiclePt); } $page.find('#battery').html(mapData.battery+'%'); t.vehicle.setPosition(vehiclePt); t.vehicle.setMap(t.map); // t.infoWin.setPosition(vehiclePt) // t.infoWin.setMap(t.map); console.log(mapData); var fence = JSON.parse(mapData.fenceShapeInfo); if(fence.type == 'circle'){ t.circle.setCenter(new AMap.LngLat(fence.data.center.lng, fence.data.center.lat)); t.circle.setRadius(fence.data.radius); t.circle.setMap(t.map); } if(mapData.lockStatus == 1){ $page.find('#lockStatus').removeClass('icon-jiesuo'); $page.find('#lockStatus').addClass('icon-suo'); } }); }; // //锁车 $page.find('#car-lock').on('tap', function(){ var lockStatus = $page.find('#lockStatus'); console.log(lockStatus.hasClass('icon-jiesuo')); if(lockStatus.hasClass('icon-jiesuo')){ lockStatus.removeClass('icon-jiesuo'); lockStatus.addClass('icon-suo'); learun.layer.toast('车辆已锁定'); }else{ lockStatus.removeClass('icon-suo'); lockStatus.addClass('icon-jiesuo'); learun.layer.toast('车辆已解锁'); } }); //test learun.getVehicleData(learun.data, true); //导航页面跳转 // $page.find('.ract').on('tap', function(){ // console.log('re'); // learun.nav.go({ path: 'demo/amap/navigation', title: '导航', isBack: true, isHead: true, param: '我是一个参数' }); // }); AMapUI.defineTpl("ui/overlay/SimpleInfoWindow/tpl/container.html", [], function() { return document.getElementById('my-infowin-tpl').innerHTML; }); AMapUI.loadUI(['overlay/SimpleInfoWindow'], function(SimpleInfoWindow) { var infoWindow = new SimpleInfoWindow({ myCustomContent: '位置导航XX小区...', //基点指向marker的头部位置 offset: new AMap.Pixel(54, -47) }); function openInfoWin() { // infoWindow.open(learun.map, learun.data.vehicle.getPosition()); infoWindow.open(learun.map, learun.vehicleMarker.getPosition()); } openInfoWin(); //marker 点击时打开 infoWindow.get$Container().on('click', function(){ learun.nav.go({ path: 'amap/navigation', title: '导航', isBack: true, isHead: true, param: '我是一个参数' }); }); }); //实时路况图层 learun.trafficLayer = new AMap.TileLayer.Traffic({ zIndex: 10 }); learun.trafficLayerAble = false; learun.trafficLayer.hide(); learun.trafficLayer.setMap(learun.map); learun.routeSituationToggle = function (){ if (learun.trafficLayerAble) { learun.trafficLayer.hide(); learun.trafficLayerAble = false; $page.find('#route-situation').html(''); } else { learun.trafficLayer.show(); learun.trafficLayerAble = true; $page.find('#route-situation').html(''); } } $page.find('#route-situation').on('tap', function () { learun.routeSituationToggle(); }); //地图显示切换(卫星和常规) learun.satelliteLayer = new AMap.TileLayer.Satellite(); learun.isSatelieteAble = false; learun.mapLayerChange = function (){ if (learun.isSatelieteAble) { learun.map.remove(learun.satelliteLayer); learun.isSatelieteAble = false; $page.find('#layer-change').html(''); } else { learun.map.add(learun.satelliteLayer); learun.isSatelieteAble = true; $page.find('#layer-change').html(''); } } $page.find('#layer-change').on('tap', function () { learun.mapLayerChange(); }); //轨迹页跳转 $page.find('#route-play').on('tap', function () { learun.nav.go({ path: 'amap/route', title: '轨迹回放', isBack: true, isHead: true, param: '我是一个参数' }); }); //定时刷新数据 // setInterval(function(){ // learun.getVehicleData(learun.data); // }, learun.timeInterval); } }; return page; })(); //icon.js !function(h){var t,l='',c=(t=document.getElementsByTagName("script"))[t.length-1].getAttribute("data-injectcss");if(c&&!h.__iconfont__svg__cssinject__){h.__iconfont__svg__cssinject__=!0;try{document.write("")}catch(t){console&&console.log(t)}}!function(t){if(document.addEventListener)if(~["complete","loaded","interactive"].indexOf(document.readyState))setTimeout(t,0);else{var c=function(){document.removeEventListener("DOMContentLoaded",c,!1),t()};document.addEventListener("DOMContentLoaded",c,!1)}else document.attachEvent&&(e=t,i=h.document,a=!1,o=function(){a||(a=!0,e())},(l=function(){try{i.documentElement.doScroll("left")}catch(t){return void setTimeout(l,50)}o()})(),i.onreadystatechange=function(){"complete"==i.readyState&&(i.onreadystatechange=null,o())});var e,i,a,o,l}(function(){var t,c,e,i,a,o;(t=document.createElement("div")).innerHTML=l,l=null,(c=t.getElementsByTagName("svg")[0])&&(c.setAttribute("aria-hidden","true"),c.style.position="absolute",c.style.width=0,c.style.height=0,c.style.overflow="hidden",e=c,(i=document.body).firstChild?(a=e,(o=i.firstChild).parentNode.insertBefore(a,o)):i.appendChild(e))})}(window);