(function () {
var infoWindow;
var lnglat;
var mainMap;
var getVehicleData;
var overlayData;//
var vehicleMarker;//车辆marker
var circle;//主页显示围栏
var userInfo;//用户信息
var timeInterval = 10000;//定时刷新车辆数据间隔ms
var page = {
init: function ($page) {
userInfo = renlian.storage.get('userinfo');
//初始化顶部导航栏
function init_nav(){
var _html = '';
_html += '
';
_html += ' ';
_html += '
';
/*
_html += '\
';
*/
_html += '\
\
\
110丢失报警\
\
';
_html += '';
_html += ' ';
_html += '
';
_html += '';
_html += '';
_html += ' ';
_html += '
';
// $page.parent().find('.f-page-header').addClass('lr-workspace-header').html(_html);
$('.f-page-header').addClass('lr-workspace-header').html(_html);
/*
// 点击搜索框
$page.parent().find('.searchBox').on('tap', function () {
renlian.nav.go({ path: 'workspace/search', title: '', isBack: true, isHead: true });
});
*/
// 点击报警
// $page.parent().find('.alarm').on('tap', function () {
// renlian.nav.go({ path: 'baojingindex', title: '110丢失报警', isBack: true, isHead: true,type:'right' });
// if(infoWindow){infoWindow.close( );}
// });
// // 点击图表
// $page.parent().find('.chart').on('tap', function () {
// renlian.nav.go({ path: 'tongji', title: '统计', isBack: true, isHead: true,type:'right' });
// if(infoWindow){infoWindow.close( );}
// });
// // 点击消息图标
// $page.parent().find('.message').on('tap', function () {
// renlian.nav.go({ path: 'baojinginfo', title: '消息', isBack: true, isHead: true,type:'right' });
// if(infoWindow){infoWindow.close( );}
// });
// $page.parent().find('.my').on('tap', function () {
// renlian.nav.go({ path: 'my', title: '我的', isBack: true, isHead: true,type:'right' });
// if(infoWindow){infoWindow.close( );}
// });
// // 注册扫描
// $page.parent().find('.scanner').on('tap', function () {
// renlian.code.scan(function (res) {
// if (res.status === 'success') {
// renlian.layer.toast(res.msg);
// }
// else {
// renlian.layer.toast('扫描失败:' + res.msg);
// }
// });
// });
$('.lr-btn').on('tap', function () {
renlian.nav.go({ path: 'baojingindex', title: '110丢失报警', isBack: true, isHead: true,type:'right' });
if(infoWindow){infoWindow.close( );}
});
// 点击图表
$('.chart').on('tap', function () {
renlian.nav.go({ path: 'tongji', title: '统计', isBack: true, isHead: true,type:'right' });
if(infoWindow){infoWindow.close( );}
});
// 点击消息图标
$('.message').on('tap', function () {
renlian.nav.go({ path: 'baojinginfo', title: '消息', isBack: true, isHead: true,type:'right' });
if(infoWindow){infoWindow.close( );}
});
$('.my').on('tap', function () {
renlian.nav.go({ path: 'my', title: '我的', isBack: true, isHead: true,type:'right' });
if(infoWindow){infoWindow.close( );}
});
// 注册扫描
$('.scanner').on('tap', function () {
renlian.code.scan(function (res) {
if (res.status === 'success') {
renlian.layer.toast(res.msg);
}
else {
renlian.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 gps = [position.coords.longitude, position.coords.latitude];
AMap.convertFrom(gps, 'gps', function (status, result) {
if (result.info === 'ok') {
var lnglats = result.locations; // Array.
}
// var lnglat = lnglats[0]
var lnglat = new AMap.LngLat(lnglats[0].lng, lnglats[0].lat);
startEnd.start = lnglat;
userMarker.setPosition(lnglat);
userMarker.setMap(mainMap);
if(locationFlag){
if(latlngSign){
mainMap.setFitView([vehicleMarker, userMarker]);
}else{
mainMap.setFitView([userMarker]);
}
locationFlag = false;
}else{
if(latlngSign){
mainMap.setFitView([vehicleMarker]);
}
locationFlag = true;
}
// alert(lnglat)
});
// var lnglat = new AMap.LngLat(position.coords.longitude, position.coords.latitude);
// alert(lnglat)
// startEnd.start = lnglat;
// userMarker.setPosition(lnglat);
// userMarker.setMap(mainMap);
// if(locationFlag){
// if(latlngSign){
// mainMap.setFitView([vehicleMarker, userMarker]);
// }else{
// mainMap.setFitView([userMarker]);
// }
// locationFlag = false;
// }else{
// if(latlngSign){
// mainMap.setFitView([vehicleMarker]);
// }
// locationFlag = true;
// }
};
// onError Callback receives a PositionError object
//
function onError(error) {
console.log('code: ' + error.code + '\n' +
'message: ' + error.message + '\n');
}
navigator.geolocation.getCurrentPosition(onSuccess, onError);
}
//上报客户端极光注册信息
function update_jg_registrationid(){
var onGetRegistrationID = function(data) {
try {
if (data.length == 0) {
console.log('******** getRegistrationID');
var t1 = window.setTimeout(function(){
window.JPush.getRegistrationID(onGetRegistrationID);
}, 1000);
}else{
var post_data = {
"regid":data,
"uid":renlian.storage.get('userinfo').baseinfo.userId
};
console.log('******** update_jg_registrationid');
renlian.httppost(config.webapi+'?s=api/update_jg_registrationid',post_data,function(res){
console.log(res);
});
}
} catch (exception) {
}
};
// var getRegistrationID = function() {
// window.JPush.getRegistrationID(onGetRegistrationID);
// };
//window.setTimeout(getRegistrationID, 1000);
window.setTimeout(function(){
window.JPush.getRegistrationID(onGetRegistrationID);
}, 1000);
}
renlian.layer.loading(true, "加载数据中");
if(window.lrmui.isreal){
//上报用户极光推注册信息
update_jg_registrationid();
//获取手机GPS位置信息
get_mobile_gps_location();
}
init_nav();
//地图
var startEnd = {start: null, end: null};
var fenceCenterVehicle = null;
var routePageData = null;
var userIcon = new AMap.Icon({size: new AMap.Size(23,23), image:'./images/location.png', imageSize:new AMap.Size(23,23)})
var userMarker = new AMap.Marker({icon: userIcon, offset:new AMap.Pixel(-16, -28)});
get_mobile_gps_location();
//车辆信息初始化
//地图初始化
var defaultCity = renlian.storage.get('userinfo').baseinfo.defaultCity;
console.log(defaultCity);
if(!defaultCity || !defaultCity.lng || !defaultCity.lat){
defaultCity = [109.84040,40.658168];
}else{
defaultCity = [defaultCity.lng, defaultCity.lat];
}
if(!mainMap){
mainMap = new AMap.Map('amapcontainer', {
center: defaultCity,
zoom: 15
});
}
mainMap.on('complete', function(){
get_mobile_gps_location();
getVehicleData(overlayData, true);
renlian.layer.loading(false);
});
var bicycleIcon = new AMap.Icon({size: new AMap.Size(32,32), image:'./images/bicycle-2.png', imageSize:new AMap.Size(32,32)})
if(!vehicleMarker){
vehicleMarker = new AMap.Marker({icon:bicycleIcon, offset:new AMap.Pixel(0, -24)});
}
if(!circle){
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);
if(!overlayData){
overlayData = {map:mainMap, vehicle:vehicleMarker, circle:circle};
}
var latlngSign = null;
var defaultCenter = null;
getVehicleData = function(t, first=false){
var deviceNumber = renlian.storage.get('userinfo').baseinfo['deviceNumber'];
var licensePlate = renlian.storage.get('userinfo').baseinfo.plate;
var gpsNumber = renlian.storage.get('userinfo').baseinfo.gpsNumber;
var mapData = null;
renlian.httpget(config.webapi+"/?s=api/get_map_index_data", {deviceNumber:deviceNumber, licensePlate:licensePlate, gpsNumber:gpsNumber}, function (_res) {
if(!_res.success){
renlian.layer.toast(_res.message);
return;
}
mapData = _res.data;
console.log(mapData);
if(!mapData){
renlian.layer.warning('无地图数据,请检测网络或联系管理员!', function () { }, '提示', '关闭');
return;
}
latlngSign = mapData.vehicleLocation.longitude;
if(!latlngSign){
first = false;
if(first){
console.log('first');
t.map.setZoomAndCenter(15,startEnd.start);
}
t.vehicle.setPosition(null);
t.vehicle.setMap(null);
}else{
var vehiclePt = new AMap.LngLat(+mapData.vehicleLocation.longitude, +mapData.vehicleLocation.latitude);
defaultCenter = vehiclePt;
startEnd.end = vehiclePt;
fenceCenterVehicle = vehiclePt;
t.vehicle.setPosition(vehiclePt);
t.vehicle.setMap(t.map);
}
if(first){
console.log('firstB');
t.map.setZoomAndCenter(15,vehiclePt);
}
if(!mapData.onlineTime){
$('#battery').html('未获取');
$('#battery').css({color:"gray"});
}else{
if(!mapData.battery){
if(mapData.onlineTime.online){
$('#battery').html('正常');
$('#battery').css({color:"green"});
}else{
$('#battery').html('正常');
$('#battery').css({color:"gray"});
}
}else{
$('#battery').html(mapData.battery);
$('#battery').css({color:"red"});
}
}
$(".ract").off("click");
vehicleInfoWin();
//在线状态
if(mapData.onlineTime){
routePageData = {speed: mapData.speed == null ? 0 : mapData.speed, lastTime:mapData.lastLoactionTime ? mapData.lastLoactionTime : ''};
if(mapData.onlineTime.online){
$('#on-off-online').text('在线');
$('#on-off-online').css({color:"green"})
// $('#battery').css({color:"gray"});
}else{
var display = mapData.onlineTime.humenDisplay;
$('#on-off-online').text('离线'+display);
$('#on-off-online').css({color:"gray"})
}
}else{
$('#on-off-online').text('未在线过');
$('#on-off-online').css({color:"gray"})
routePageData = {speed: mapData.speed == null ? 0 : mapData.speed, lastTime:''};
}
var fence = mapData.fenceShapeInfo;
if(fence){
fence = JSON.parse(fence);
var fenceInfo = fence.fenceInfo;
if(fenceInfo.type == 'circle'){
t.circle.setCenter(new AMap.LngLat(fenceInfo.data.center.lng, fenceInfo.data.center.lat));
t.circle.setRadius(parseInt(fenceInfo.data.radius));
t.circle.setMap(t.map);
}
}
if(mapData.lockStatus == 1){
$('#lockStatus').removeClass('icon-jiesuo');
$('#lockStatus').addClass('icon-suo');
$('#lock-text').text('解锁');
}else{
$('#lock-text').text('锁车');
}
});
};
//定位
$('#user-location').on('tap', function(){
get_mobile_gps_location();
});
//锁车
$('#car-lock').on('tap', function(){
var lockStatus = $('#lockStatus');
var postData = {
deviceNumber: renlian.storage.get('userinfo').baseinfo.deviceNumber,
gpsNumber: renlian.storage.get('userinfo').baseinfo.gpsNumber,
plate: renlian.storage.get('userinfo').baseinfo.plate,
lockStatus: lockStatus.hasClass('icon-jiesuo') ? 1 : 0
}
renlian.httppost(config.webapi+'?s=api/change_lock_status',postData,function(res){
if(!res.success){
renlian.layer.toast(res.message);
return;
}
if(lockStatus.hasClass('icon-jiesuo')){
lockStatus.removeClass('icon-jiesuo');
lockStatus.addClass('icon-suo');
$('#lock-text').text('解锁');
// renlian.layer.toast('车辆已锁定');
}else{
lockStatus.removeClass('icon-suo');
lockStatus.addClass('icon-jiesuo');
$('#lock-text').text('锁车');
// renlian.layer.toast('车辆已解锁');
}
});
});
//test
var geocoder;
AMapUI.defineTpl("ui/overlay/SimpleInfoWindow/tpl/container.html", [], function() {
return document.getElementById('my-infowin-tpl').innerHTML;
});
function vehicleInfoWin(){
AMapUI.loadUI(['overlay/SimpleInfoWindow'], function(SimpleInfoWindow) {
lnglat = vehicleMarker.getPosition();
var address = '坐标未解析成功';
if(!geocoder){
geocoder = new AMap.Geocoder({
city: "0571", //城市设为北京,默认:“全国”
radius: 500 //范围,默认:500
});
}
geocoder.getAddress(lnglat, function(status, result) {
if (status === 'complete' && result.regeocode) {
address = result.regeocode.formattedAddress;
if(!infoWindow || userInfo.baseinfo.token != renlian.storage.get('userinfo').baseinfo.token){
infoWindow = new SimpleInfoWindow({
infoBody: ''+address+' ',
//基点指向marker的头部位置
offset: new AMap.Pixel(50, -36)
});
}
infoWindow.open(mainMap, lnglat);
console.log(infoWindow.get$Container());
infoWindow.get$Container().on('click', function(){
renlian.nav.go({ path: 'amap/navigation', title: '导航', isBack: true, isHead: true, param: startEnd});
if(infoWindow){
infoWindow.close( );
}
});
}else{
// renlian.layer.toast(JSON.stringify(result));
}
});
});
}
//坐标解析地址
//实时路况图层
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;
$('#route-situation').html(' ');
} else {
trafficLayer.show();
trafficLayerAble = true;
$('#route-situation').html(' ');
}
}
$('#route-situation').on('tap', function () {
routeSituationToggle();
});
//地图显示切换(卫星和常规)
var satelliteLayer = new AMap.TileLayer.Satellite();
var isSatelieteAble = false;
renlian.mapLayerChange = function (){
if (isSatelieteAble) {
mainMap.remove(satelliteLayer);
isSatelieteAble = false;
$('#layer-change').html(' ');
} else {
mainMap.add(satelliteLayer);
isSatelieteAble = true;
$('#layer-change').html(' ');
}
}
$('#layer-change').on('tap', function () {
renlian.mapLayerChange();
});
//轨迹页跳转
$('#route-play').on('tap', function () {
renlian.nav.go({ path: 'amap/route', title: '轨迹回放', isBack: true, isHead: true, param: {textData:routePageData, defaultCenter: defaultCenter || startEnd.start || null} });
if(infoWindow){infoWindow.close( );}
});
//围栏页跳转
$('#electric-fence').on('tap', function () {
renlian.nav.go({ path: 'amap/fence', title: '围栏设置', isBack: true, isHead: true, param: {default: fenceCenterVehicle || startEnd.start} });
if(infoWindow){infoWindow.close( );}
});
//保险页跳转
$('.insurance-img').on('tap', function () {
renlian.nav.go({ path: 'insure', title: '保险理赔', isBack: true, isHead: true, param: 'test' });
if(infoWindow){infoWindow.close( );}
});
//定时刷新数据
var mainPageInterval = setInterval(function(){
if($('.f-page').length > 1){
clearTimeout(mainPageInterval);
return;
}
getVehicleData(overlayData);
}, timeInterval);
},
reload: function ($page, pageinfo) {
if(userInfo.baseinfo.token != renlian.storage.get('userinfo').baseinfo.token){
vehicleMarker.setMap(null);
infoWindow = null;
getVehicleData(overlayData, true);
}else{
getVehicleData(overlayData);
}
if(infoWindow){
infoWindow.open(mainMap, lnglat);
}
},
destroy: function(pageinfo){
console.log('destroy amap')
}
};
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);