git il y a 6 ans
Parent
commit
a27c699fe9

BIN
images/bicycle.png


BIN
images/gelocation-2.png


BIN
images/gelocation.png


+ 1 - 1
index.html

@@ -33,7 +33,7 @@
         <script type="text/javascript" src="scripts/learun-custmerform.js"></script>
         <script type="text/javascript" src="scripts/index.js"></script>
         <script type="text/javascript" src="scripts/fence-slider.js"></script>
-        <script type="text/javascript" src="https://webapi.amap.com/maps?v=1.4.12&key=78735d0efd243f8085837edf355526cb&plugin=AMap.Riding"></script>
+        <script type="text/javascript" src="https://webapi.amap.com/maps?v=1.4.12&key=78735d0efd243f8085837edf355526cb&plugin=AMap.Riding,AMap.Geocoder"></script>
         
         <!-- ui组件库 -->
         <script src="https://webapi.amap.com/ui/1.0/main.js"></script>

+ 1 - 1
pages/amap/amap.html

@@ -66,7 +66,7 @@
                     <!-- 窗体模板 -->
                     <script id="my-infowin-tpl" type="text/template">
                         <div class="ract LeftBubble">
-                            <span>位置导航XX小区...</span>
+                            <span><%= myCustomContent %></span>
                         </div>
                     </script>
                     

+ 72 - 46
pages/amap/amap.js

@@ -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);
             
         }
     };

+ 24 - 11
pages/amap/fence/fence.js

@@ -25,10 +25,14 @@
             // // })
 
 
+            if(param){
+                var fenceInfo = param.fenceInfo;
+                var defaultPt = param.defaultLocation;
+                var ableStatus = param.fenceAlarmStatus;
+                var radius = fenceInfo.data.radius;
+            }
+            
 
-            var fenceInfo = param.fenceInfo;
-            var defaultPt = param.defaultLocation;
-            var ableStatus = param.fenceAlarmStatus;
 
             if(ableStatus){
                 $('#fence-switch').addClass('f-active');
@@ -40,7 +44,7 @@
 
             var circleFence = new AMap.Circle({
                 center: defaultPt,
-                radius: fenceInfo.data.radius || 100, 
+                radius: radius || 100, 
                 strokeOpacity: 0,
                 strokeWeight: 0,
                 strokeOpacity: 0.2,
@@ -58,7 +62,7 @@
             $page.find('#fence-switch').lrswitch();
 
             var rangeObj = $('#fence-radius');
-            rangeObj[0].value = fenceInfo.data.radius || 100;
+            rangeObj[0].value = radius || 100;
             $('#display-radius')[0].innerHTML = rangeObj[0].value;
             //获取要设置的半径
             function getSetRadius(){
@@ -85,6 +89,7 @@
                 learun.layer.confirm('保存将会覆盖原围栏', function (_index) { 
                     if(_index === '1'){
                         var data = getPostData();
+                        console.log(data);
                         if(!data){
                             learun.layer.toast('围栏信息有误或者为空');
                             return;
@@ -99,15 +104,23 @@
             //获取提交数据
             function getPostData(){
                 var fenceEnable = getAbleStatus();
-                var radius = circleFence.getRadius();
                 var circleCenter = circleFence.getCenter();
                 var center = {lng: circleCenter.lng, lat:circleCenter.lat}
-                var data = {
-                    type: 'circle',
-                    data: {radius: radius, center: center},
-                    fenceAlarmEnable: fenceEnable
-                };
 
+                var fenceData = {};
+                fenceData.type = 'circle';
+                fenceData.data = {};
+                fenceData.data.radius = circleFence.getRadius();
+                fenceData.data.center = center;
+
+                var data = {};
+                // vehicleNumber: 'AAAAAA000003',
+                // data: fenceData,
+                // fenceAlarmEnable: fenceEnable
+                data.vehicleNumber = 'AAAAAA000003';
+                data.data =  JSON.stringify(fenceData);
+                data.fenceAlarmEnable = fenceEnable;
+                console.log(data)
                 return data;
             }
 

+ 4 - 3
pages/amap/navigation/navigation.js

@@ -20,7 +20,7 @@
                 
 			});
 
-            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)});
 
             //骑行导航
            var riding = new AMap.Riding({
@@ -52,7 +52,6 @@
                     var lnglat = new AMap.LngLat(position.coords.longitude, position.coords.latitude);
                     userMarker.setPosition(lnglat);
                     userMarker.setMap(map);
-                    map.setFitView();
 				};
 			 
 				// onError Callback receives a PositionError object
@@ -68,7 +67,9 @@
 
 
             setInterval(function(){
-                get_mobile_gps_location()
+                if(window.lrmui.isreal){
+                    get_mobile_gps_location()
+                }
             }, 5000);