|
@@ -78,12 +78,12 @@
|
|
|
// 'Timestamp: ' + position.timestamp + '\n');
|
|
|
var lnglat = new AMap.LngLat(position.coords.longitude, position.coords.latitude);
|
|
|
userMarker.setPosition(lnglat);
|
|
|
- userMarker.setMap(learun.map);
|
|
|
+ userMarker.setMap(mainMap);
|
|
|
if(locationFlag){
|
|
|
- learun.map.setFitView();
|
|
|
+ mainMap.setFitView();
|
|
|
locationFlag = false;
|
|
|
}else{
|
|
|
- learun.map.setFitView([learun.vehicleMarker]);
|
|
|
+ mainMap.setFitView([vehicleMarker]);
|
|
|
locationFlag = true;
|
|
|
}
|
|
|
};
|
|
@@ -135,6 +135,8 @@
|
|
|
}
|
|
|
init_nav();
|
|
|
|
|
|
+
|
|
|
+ console.log(userinfo);
|
|
|
|
|
|
|
|
|
var startEnd = {start:new AMap.LngLat(113.951104,22.542902), end:new AMap.LngLat(113.955439,22.532956)};
|
|
@@ -142,17 +144,17 @@
|
|
|
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.png", offset:new AMap.Pixel(16, -16)});
|
|
|
+ var userMarker = new AMap.Marker({icon: "./images/gelocation-2.png", offset:new AMap.Pixel(16, -16)});
|
|
|
|
|
|
//车辆信息初始化
|
|
|
- learun.timeInterval = 5000;
|
|
|
+ var timeInterval = 5000;
|
|
|
//地图初始化
|
|
|
- learun.map = new AMap.Map('amapcontainer');
|
|
|
- learun.map.on('complete', function(){
|
|
|
+ var mainMap = new AMap.Map('amapcontainer');
|
|
|
+ mainMap.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({
|
|
|
+ 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,
|
|
@@ -168,7 +170,7 @@
|
|
|
zIndex: 50,
|
|
|
});
|
|
|
|
|
|
- learun.circle.setMap(learun.map);
|
|
|
+ circle.setMap(mainMap);
|
|
|
|
|
|
// learun.vehicleInfoWin = new AMap.InfoWindow({
|
|
|
// isCustom: true,
|
|
@@ -176,13 +178,14 @@
|
|
|
// content: '<div class="ract LeftBubble"><span>位置导航XX小区...</span></div>'
|
|
|
// });
|
|
|
|
|
|
- learun.data = {map:learun.map, vehicle:learun.vehicleMarker, circle:learun.circle, infoWin:learun.vehicleInfoWin};
|
|
|
+ var overlayData = {map:mainMap, vehicle:vehicleMarker, circle:circle, infoWin:learun.vehicleInfoWin};
|
|
|
|
|
|
- learun.getVehicleData = function(t, first=false){
|
|
|
- var deviceNumber = 'A00000000031';
|
|
|
+ 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;
|
|
|
+ mapData = _res.data;
|
|
|
+ console.log(mapData);
|
|
|
if(!mapData){
|
|
|
learun.layer.warning('无地图数据,请检测网络或联系管理员!', function () { }, '提示', '关闭');
|
|
|
return;
|
|
@@ -249,7 +252,7 @@
|
|
|
|
|
|
|
|
|
//test
|
|
|
- learun.getVehicleData(learun.data, true);
|
|
|
+ getVehicleData(overlayData, true);
|
|
|
|
|
|
|
|
|
//导航页面跳转
|
|
@@ -258,23 +261,42 @@
|
|
|
// 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 infoWindow = new SimpleInfoWindow({
|
|
|
- myCustomContent: '<span>位置导航XX小区...</span>',
|
|
|
- //基点指向marker的头部位置
|
|
|
- offset: new AMap.Pixel(54, -47)
|
|
|
- });
|
|
|
-
|
|
|
- function openInfoWin() {
|
|
|
- // infoWindow.open(learun.map, learun.data.vehicle.getPosition());
|
|
|
- infoWindow.open(learun.map, learun.vehicleMarker.getPosition());
|
|
|
+ var lnglat = vehicleMarker.getPosition();
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ if(!geocoder){
|
|
|
+ geocoder = new AMap.Geocoder({
|
|
|
+ city: "0571", //城市设为北京,默认:“全国”
|
|
|
+ radius: 500 //范围,默认:500
|
|
|
+ });
|
|
|
}
|
|
|
- openInfoWin();
|
|
|
+ var address = '坐标未解析成功'
|
|
|
+ geocoder.getAddress(lnglat, function(status, result) {
|
|
|
+ if (status === 'complete' && result.regeocode) {
|
|
|
+ address = result.regeocode.formattedAddress;
|
|
|
+
|
|
|
+ if(!infoWindow){
|
|
|
+ var infoWindow = new SimpleInfoWindow({
|
|
|
+ myCustomContent: '<span style="max-width:100%">'+address+'</span>',
|
|
|
+ //基点指向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 });
|
|
@@ -285,41 +307,45 @@
|
|
|
|
|
|
|
|
|
|
|
|
+ //坐标解析地址
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
|
|
|
|
|
|
//实时路况图层
|
|
|
- learun.trafficLayer = new AMap.TileLayer.Traffic({
|
|
|
+ var 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;
|
|
|
+ var trafficLayerAble = false;
|
|
|
+ trafficLayer.hide();
|
|
|
+ trafficLayer.setMap(mainMap);
|
|
|
+ var routeSituationToggle = function (){
|
|
|
+ if (trafficLayerAble) {
|
|
|
+ trafficLayer.hide();
|
|
|
+ trafficLayerAble = false;
|
|
|
$page.find('#route-situation').html('<svg class="icon" aria-hidden="true"><use xlink:href="#icon-lukuang"></use></svg>');
|
|
|
} else {
|
|
|
- learun.trafficLayer.show();
|
|
|
- learun.trafficLayerAble = true;
|
|
|
+ trafficLayer.show();
|
|
|
+ trafficLayerAble = true;
|
|
|
$page.find('#route-situation').html('<svg class="icon" aria-hidden="true"><use xlink:href="#icon-lukuang1"></use></svg>');
|
|
|
}
|
|
|
}
|
|
|
$page.find('#route-situation').on('tap', function () {
|
|
|
- learun.routeSituationToggle();
|
|
|
+ routeSituationToggle();
|
|
|
});
|
|
|
|
|
|
//地图显示切换(卫星和常规)
|
|
|
- learun.satelliteLayer = new AMap.TileLayer.Satellite();
|
|
|
- learun.isSatelieteAble = false;
|
|
|
+ var satelliteLayer = new AMap.TileLayer.Satellite();
|
|
|
+ var isSatelieteAble = false;
|
|
|
learun.mapLayerChange = function (){
|
|
|
- if (learun.isSatelieteAble) {
|
|
|
- learun.map.remove(learun.satelliteLayer);
|
|
|
- learun.isSatelieteAble = false;
|
|
|
+ if (isSatelieteAble) {
|
|
|
+ mainMap.remove(satelliteLayer);
|
|
|
+ isSatelieteAble = false;
|
|
|
$page.find('#layer-change').html('<svg class="icon" aria-hidden="true"><use xlink:href="#icon-qiehuan1"></use></svg>');
|
|
|
} else {
|
|
|
- learun.map.add(learun.satelliteLayer);
|
|
|
- learun.isSatelieteAble = true;
|
|
|
+ mainMap.add(satelliteLayer);
|
|
|
+ isSatelieteAble = true;
|
|
|
$page.find('#layer-change').html('<svg class="icon" aria-hidden="true"><use xlink:href="#icon-qiehuan"></use></svg>');
|
|
|
}
|
|
|
}
|
|
@@ -341,8 +367,8 @@
|
|
|
//定时刷新数据
|
|
|
|
|
|
// setInterval(function(){
|
|
|
- // learun.getVehicleData(learun.data);
|
|
|
- // }, learun.timeInterval);
|
|
|
+ // getVehicleData(overlayData);
|
|
|
+ // }, timeInterval);
|
|
|
|
|
|
}
|
|
|
};
|