(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位置 var locationFlag = true; 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'); var lnglat = new AMap.LngLat(position.coords.longitude, position.coords.latitude); userMarker.setPosition(lnglat); userMarker.setMap(mainMap); if(locationFlag){ mainMap.setFitView(); locationFlag = false; }else{ mainMap.setFitView([vehicleMarker]); locationFlag = true; } }; // 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(){ var onGetRegistrationID = function(data) { try { if (data.length == 0) { var t1 = window.setTimeout(getRegistrationID, 1000); }else{ console.log("JPushPlugin:registrationID is " + data); var post_data = { "regid":data, "uid":userinfo.baseinfo.userId }; learun.httppost(config.webapi+'?s=api/update_jg_registrationid',post_data,function(res){ console.log(res.message); }); } } catch (exception) { console.log(exception); } }; var getRegistrationID = function() { window.JPush.getRegistrationID(onGetRegistrationID); }; window.setTimeout(getRegistrationID, 1000); } learun.layer.loading(true, "加载数据中"); if(window.lrmui.isreal){ //上报用户极光推注册信息 update_jg_registrationid(); //获取手机GPS位置信息 get_mobile_gps_location(); } init_nav(); console.log(userinfo); var startEnd = {start:new AMap.LngLat(113.951104,22.542902), end:new AMap.LngLat(113.955439,22.532956)}; var fencePageData = null; // var userIcon = new AMap.Icon({size: new AMap.Size(50,50), image:'./images/gelocation.png'}) var userMarker = new AMap.Marker({icon: "./images/gelocation-2.png", offset:new AMap.Pixel(16, -16)}); //车辆信息初始化 var timeInterval = 5000; //地图初始化 var mainMap = new AMap.Map('amapcontainer'); mainMap.on('complete', function(){ learun.layer.loading(false); }); var vehicleMarker = new AMap.Marker({icon:'./images/bicycle.png', offset:new AMap.Pixel(0, -51)}); var circle = new AMap.Circle({ radius: 0, center: [0, 0], borderWeight: 3, strokeColor: "#FF33FF", strokeOpacity: 1, strokeWeight: 6, strokeOpacity: 0.2, fillOpacity: 0.2, strokeStyle: 'dashed', strokeDasharray: [10, 10], // 线样式还支持 'dashed' fillColor : '#1791fc', zIndex: 50, }); circle.setMap(mainMap); // learun.vehicleInfoWin = new AMap.InfoWindow({ // isCustom: true, // offset: new AMap.Pixel(60, -40), // content: '
位置导航XX小区...
' // }); var overlayData = {map:mainMap, vehicle:vehicleMarker, circle:circle, infoWin:learun.vehicleInfoWin}; var getVehicleData = function(t, first=false){ var deviceNumber = 'AAAAAA000003'; var mapData = null; learun.httpget(config.webapi+"/?s=api/get_map_index_data", {deviceNumber:deviceNumber}, function (_res) { mapData = _res.data; console.log(mapData); if(!mapData){ learun.layer.warning('无地图数据,请检测网络或联系管理员!', function () { }, '提示', '关闭'); return; } 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'); } fencePageData = {fenceInfo: fence, defaultLocation: vehiclePt, fenceStatus:mapData.fenceAlarmStatus}; }); }; //定位 $page.find('#user-location').on('tap', function(){ get_mobile_gps_location(function(position){ // position.coords.latitude }); }); //锁车 $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 getVehicleData(overlayData, true); //导航页面跳转 // $page.find('.ract').on('tap', function(){ // console.log('re'); // learun.nav.go({ path: 'demo/amap/navigation', title: '导航', isBack: true, isHead: true, param: '我是一个参数' }); // }); var geocoder; AMapUI.defineTpl("ui/overlay/SimpleInfoWindow/tpl/container.html", [], function() { return document.getElementById('my-infowin-tpl').innerHTML; }); AMapUI.loadUI(['overlay/SimpleInfoWindow'], function(SimpleInfoWindow) { var lnglat = vehicleMarker.getPosition(); if(!geocoder){ geocoder = new AMap.Geocoder({ city: "0571", //城市设为北京,默认:“全国” radius: 500 //范围,默认:500 }); } var address = '坐标未解析成功' geocoder.getAddress(lnglat, function(status, result) { if (status === 'complete' && result.regeocode) { address = result.regeocode.formattedAddress; if(!infoWindow){ var infoWindow = new SimpleInfoWindow({ myCustomContent: ''+address+'', //基点指向marker的头部位置 offset: new AMap.Pixel(54, -47) }); } infoWindow.open(mainMap, lnglat); }else{alert(JSON.stringify(result))} }); //marker 点击时打开 infoWindow.get$Container().on('click', function(){ learun.nav.go({ path: 'amap/navigation', title: '导航', isBack: true, isHead: true, param: startEnd }); }); }); //坐标解析地址 //实时路况图层 var trafficLayer = new AMap.TileLayer.Traffic({ zIndex: 10 }); var trafficLayerAble = false; trafficLayer.hide(); trafficLayer.setMap(mainMap); var routeSituationToggle = function (){ if (trafficLayerAble) { trafficLayer.hide(); trafficLayerAble = false; $page.find('#route-situation').html(''); } else { trafficLayer.show(); trafficLayerAble = true; $page.find('#route-situation').html(''); } } $page.find('#route-situation').on('tap', function () { routeSituationToggle(); }); //地图显示切换(卫星和常规) var satelliteLayer = new AMap.TileLayer.Satellite(); var isSatelieteAble = false; learun.mapLayerChange = function (){ if (isSatelieteAble) { mainMap.remove(satelliteLayer); isSatelieteAble = false; $page.find('#layer-change').html(''); } else { mainMap.add(satelliteLayer); 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: '我是一个参数' }); }); //围栏页跳转 $page.find('#electric-fence').on('tap', function () { learun.nav.go({ path: 'amap/fence', title: '围栏设置', isBack: true, isHead: true, param: fencePageData }); }); //定时刷新数据 // setInterval(function(){ // getVehicleData(overlayData); // }, 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);