Shannon_mu 3 tahun lalu
induk
melakukan
6c9711a003

+ 37 - 73
operationSupport/src/views/patrolManagement/popups/mapValue.vue

@@ -1,41 +1,53 @@
 <template>
     <div>
-        <div id="mapValue" ></div>
+        <div id="mapValue" :style="`height:${height||300}px`"></div>
         <!--控制条-->
         <div class="map-control" v-if="isStart">
-            <div class="clickIco" @click="startAnimation()">
-                <i class="zoniot_font" :class="isSta?'zoniot-icon-kaishi':'zoniot-icon-tingzhi'"></i>
+            <div class="clickIco">
+                <i
+                    class="zoniot_font zoniot-icon-kaishi"
+                    v-if="palyStayus==0"
+                    @click="navgControl('start')"
+                ></i>
+                <i
+                    class="zoniot_font zoniot-icon-tingzhi"
+                    v-else-if="palyStayus==2"
+                    @click="navgControl('pause')"
+                ></i>
+                <i
+                    class="zoniot_font zoniot-icon-kaishi"
+                    v-else-if="palyStayus==1"
+                    @click="navgControl('resume')"
+                ></i>
             </div>
             <el-slider
                 class="slider"
                 v-model="sliderVal"
+                :show-tooltip="false"
                 :format-tooltip="hideFormat"
                 :step="0.0001"
+                :disabled="beforeInit"
+                @change="carReLocate"
             ></el-slider>
-            <el-select v-model="speed">
-                <el-option :value="1000" label="1倍速"></el-option>
-                <el-option :value="1500" label="1.5倍速"></el-option>
-                <el-option :value="2000" label="2倍速"></el-option>
-                <el-option :value="3000" label="3倍速"></el-option>
+            <el-select v-model="times">
+                <el-option :value="1" label="1倍速"></el-option>
+                <el-option :value="2" label="2倍速"></el-option>
+                <el-option :value="3" label="3倍速"></el-option>
+                <el-option :value="4" label="4倍速"></el-option>
             </el-select>
         </div>
     </div>
 </template>
 
 <script>
+import functionJs from './pathSimplifierIns';
 export default {
-    props: ['point','isStart'],
+    props: ['point', 'isStart', 'height'],
+    mixins: [functionJs],
     data() {
         return {
-            map: '',
             marker: '',
-            icon: 'https://webapi.amap.com/theme/v1.3/markers/n/mark_b.png',
-            markerArr: [],
-            lineArr: [],
-            marker2: '',
-            speed: 1000,
-            sliderVal: 0,
-            isSta: true
+            markerArr: []
         };
     },
     watch: {
@@ -49,9 +61,6 @@ export default {
                     this.addIcon(item, tag);
                 }
             });
-        },
-        speed(e) {
-            this.startAnimation(e);
         }
     },
     methods: {
@@ -68,62 +77,17 @@ export default {
                 icon: this.icon,
                 position: lineArr
             });
-            this.map.add(this.marker);
             this.markerArr.push(this.marker);
             this.lineArr.push(lineArr);
-            this.map.setFitView();
             if (is) {
-                this.initLineArr();
+                this.map.add(this.markerArr);
+                this.map.setFitView();
+                if (this.isStart) {
+                    this.initPlayBox();
+                    this.beforeInit = true;
+                    this.initLineArr();
+                }
             }
-        },
-        initLineArr() {
-            let _this = this;
-            this.marker2 = new AMap.Marker({
-                map: _this.map,
-                position: _this.lineArr[0],
-                icon: 'https://webapi.amap.com/images/car.png',
-                offset: new AMap.Pixel(-26, -13),
-                autoRotation: true,
-                angle: -90
-            });
-            // 绘制轨迹
-            let polyline = new AMap.Polyline({
-                map: this.map,
-                path: _this.lineArr,
-                showDir: true,
-                strokeColor: '#28F', //线颜色
-                // strokeOpacity: 1,     //线透明度
-                strokeWeight: 6 //线宽
-                // strokeStyle: "solid"  //线样式
-            });
-            let passedPolyline = new AMap.Polyline({
-                map: _this.map,
-                // path: lineArr,
-                strokeColor: '#AF5', //线颜色
-                // strokeOpacity: 1,     //线透明度
-                strokeWeight: 6 //线宽
-                // strokeStyle: "solid"  //线样式
-            });
-            this.marker2.on('moving', e => {
-                passedPolyline.setPath(e.passedPath);
-            });
-            this.marker2.on('moveend', e => {
-                this.isSta = true;
-            });
-        },
-        startAnimation(time) {
-            let _this = this;
-            this.isSta = false;
-            this.marker2.moveAlong(
-                this.lineArr,
-                time | 1000,
-                e => {
-                    this.sliderVal = e * 100;
-                    return e;
-                },
-
-                false
-            );
         }
     },
     created() {
@@ -138,7 +102,7 @@ export default {
 #mapValue {
     // margin-top: 20px;
     width: 100%;
-    height: 300px;
+    // height: 300px;
 }
 .my-autocomplete {
     li {

+ 230 - 0
operationSupport/src/views/patrolManagement/popups/pathSimplifierIns.js

@@ -0,0 +1,230 @@
+export default {
+    data() {
+        return {
+            lineArr: [],
+            // 巡航轨迹
+            AMap: null,
+            map: null,
+            PathSimplifier: null,
+            beforeInit: true,
+            isPlay: true,
+            sliderVal: 0, // 进度条
+            times: 1, // 倍速
+            maxSpeed: 40, // 最高倍速
+            navgtrSpeed: 1000, // 速度
+            isMinSpeed: true,
+            isMaxSpeed: false,
+            navgtr: null,
+            pathSimplifierIns: null,
+            actualList: [],
+            defaultRenderOptions: {
+                renderAllPointsIfNumberBelow: -1, // 描绘路径点,如不需要设为-1
+                pathTolerance: 2,
+                keyPointTolerance: 0,
+                pathLineStyle: {
+                    lineWidth: 6,
+                    strokeStyle: '#409eff',
+                    borderWidth: 1,
+                    borderStyle: '#eeeeee',
+                    dirArrowStyle: false
+                },
+                pathLineHoverStyle: {
+                    lineWidth: 6,
+                    strokeStyle: '#ff0000',
+                    borderWidth: 1,
+                    borderStyle: '#cccccc',
+                    dirArrowStyle: false
+                },
+                dirArrowStyle: {
+                    stepSpace: 30,
+                    strokeStyle: '#ffffff',
+                    lineWidth: 2
+                },
+                pathLineSelectedStyle: {
+                    lineWidth: 6,
+                    strokeStyle: '#409eff',
+                    borderWidth: 1,
+                    borderStyle: '#cccccc',
+                    dirArrowStyle: true
+                },
+                keyPointStyle: {
+                    radius: 0,
+                    fillStyle: 'rgba(8, 126, 196, 1)',
+                    lineWidth: 1,
+                    strokeStyle: '#eeeeee'
+                },
+                keyPointHoverStyle: {
+                    radius: 0,
+                    fillStyle: 'rgba(0, 0, 0, 0)',
+                    lineWidth: 2,
+                    strokeStyle: '#ffa500'
+                },
+                keyPointOnSelectedPathLineStyle: {
+                    radius: 0,
+                    fillStyle: 'rgba(8, 126, 196, 1)',
+                    lineWidth: 2,
+                    strokeStyle: '#eeeeee'
+                }
+            },
+            isCursorAtPathEnd: false,
+            palyStayus: 0, //0->未开始  1->行驶中  2->暂停
+            value: 0, // 进度条初始化
+
+            // signMarker: null,
+            currentPoint: null,
+
+            timeValue: '',
+            trackData: []
+        };
+    },
+    methods: {
+        initLineArr() {
+            let _this = this;
+            let that = this;
+
+            AMapUI.load(['ui/misc/PathSimplifier'], PathSimplifier => {
+                if (!PathSimplifier.supportCanvas) {
+                    alert('当前环境不支持 Canvas!');
+                    return;
+                }
+
+                // 如果已存在巡航轨迹,则删除
+                if (window.pathSimplifierIns && that.pathSimplifierIns) {
+                    //通过该方法清空上次传入的轨迹
+                    that.pathSimplifierIns.setData([]);
+                }
+
+                // 初始化坐标点
+                if (_this.lineArr.length > 0) {
+                    that.actualList = _this.lineArr;
+
+                    //创建一个巡航轨迹路线
+                    that.pathSimplifierIns = new PathSimplifier({
+                        zIndex: 100, //地图层级,
+                        map: this.map, //所属的地图实例
+                        //巡航路线轨迹列表
+                        getPath: (pathData, pathIndex) => {
+                            return pathData.path;
+                        },
+                        //hover每一个轨迹点,展示内容
+                        getHoverTitle: function (pathData, pathIndex, pointIndex) {
+                            return '';
+                        },
+                        //自定义样式,可设置巡航器样式,巡航轨迹样式,巡航轨迹点击、hover等不同状态下的样式,不设置则用默认样式,详情请参考api文档 renderOptions:{}
+                        //绘制路线节点
+                        renderOptions: that.defaultRenderOptions
+                    });
+                    window.pathSimplifierIns = that.pathSimplifierIns;
+                    //设置数据
+                    that.pathSimplifierIns.setData([
+                        {
+                            name: '轨迹路线',
+                            path: that.actualList
+                        }
+                    ]);
+                    that.pathSimplifierIns.setSelectedPathIndex(0);
+
+                    function onload() {
+                        that.pathSimplifierIns.renderLater();
+                    }
+
+                    function onerror(e) {
+                        console.log('图片加载失败!');
+                    }
+
+                    //对第一条线路(即索引 0)创建一个巡航器
+                    let image = PathSimplifier.Render.Canvas.getImageContent('https://webapi.amap.com/images/car.png', onload, onerror);
+                    that.navgtr = that.pathSimplifierIns.createPathNavigator(0, {
+                        loop: false, //循环播放
+                        speed: that.navgtrSpeed, //巡航速度,单位千米/小时
+                        pathNavigatorStyle: {
+                            width: 20,
+                            height: 30,
+                            //使用图片
+                            content: image, // 自定义巡航样式
+                            strokeStyle: null,
+                            fillStyle: null,
+                            //经过路径的样式
+                            pathLinePassedStyle: {
+                                lineWidth: 6,
+                                strokeStyle: '#69f81e',
+                                dirArrowStyle: {
+                                    stepSpace: 15,
+                                    strokeStyle: '#FFF'
+                                }
+                            }
+                        }
+                    });
+
+                    that.navgtr.on('start resume', function () {
+                        that.navgtr._startTime = Date.now();
+                        that.navgtr._startDist = this.getMovedDistance();
+                    });
+                    that.navgtr.on('stop pause', function () {
+                        that.navgtr._movedTime = Date.now() - that.navgtr._startTime;
+                        that.navgtr._movedDist = this.getMovedDistance() - that.navgtr._startDist;
+                    });
+                    that.navgtr.on('move', function (data, position) {
+                        that.isCursorAtPathEnd = false;
+                        let idx = position.dataItem.pointIndex; //走到了第几个点
+                        let tail = position.tail; //至下一个节点的比例位置
+                        let totalIdx = idx + tail;
+                        let len = position.dataItem.pathData.path.length - 1;
+                        // 设置当前点位
+                        that.currentPoint = that.actualList[idx];
+                        if (idx < len - 1) {
+                            that.navgtr.setSpeed(that.navgtrSpeed * that.times);
+                        }
+                        // 进度条实时展示tail
+                        !that.isOnSlider && (that.sliderVal = (totalIdx / len) * 100);
+
+                        // 如果到头了,回到初始状态
+                        if (that.navgtr.isCursorAtPathEnd()) {
+                            that.isCursorAtPathEnd = true;
+                            that.initPlayBox();
+                        }
+                    });
+
+                    // 加载完成
+                    that.beforeInit = false;
+                }
+            });
+        },
+        initPlayBox() {
+            // 暂停
+            this.navgControl('pause');
+            this.playIcon = 'start';
+            this.isPlay = true; // 播放图标
+            this.palyStayus = 0; // 继续状态
+        },
+        // 控制播放按钮
+        navgControl(type) {
+            if (!this.navgtr || !type) {
+                return;
+            }
+            if (type === 'start' || type === 'resume') {
+                this.isPlay = false;
+                this.palyStayus = 2;
+                // 如果已经到了终点,重新定位坐标
+                if (this.isCursorAtPathEnd && this.actualList.length > 0) {
+                    this.map.setCenter(this.actualList[0]);
+
+                }
+            } else if (type === 'pause') {
+                this.isPlay = true;
+                this.palyStayus = 1;
+            }
+            this.navgtr[type]();
+            this.map.setFitView();
+        },
+        // carReLocate() {
+        //     // 鼠标从滑动条抬起时,重新定位
+        //     if (this.currentPoint) {
+        //         let timeout = setTimeout(() => {
+        //             clearTimeout(timeout)
+        //             this.map.setCenter(this.currentPoint)
+        //         }, 0)
+        //     }
+        // },
+    }
+};

+ 9 - 3
operationSupport/src/views/patrolManagement/popups/patrolDetails.vue

@@ -10,7 +10,7 @@
         </div>
         <div class="contentText">
             <div class="leftMap">
-                <map-value :point="targetData" ref="mapVal" :isStart='true'></map-value>
+                <map-value :point="targetData" ref="mapVal" :isStart="true" :height="400"></map-value>
                 <div class="formLabel">
                     <div class="formLabelList">
                         <div class="label">所属社区</div>
@@ -107,15 +107,21 @@ export default {
                 this.thisItem = data;
                 this.targetData = [
                     { longitude: '114.073587', latitude: '22.59709' },
-                    { longitude: '114.086634', latitude: '22.57763' }
+                    { longitude: '114.086634', latitude: '22.57763' },
+                    { longitude: '114.096634', latitude: '22.55763' }
                 ];
                 console.log(data);
             });
-        },
+        }
     },
     created() {
         this.getDetail(this.thisObj.id);
         this.getTrack(this.thisObj.id);
+
+        const s = document.createElement('script');
+        s.style = 'text/javascript';
+        s.src = 'https://webapi.amap.com/ui/1.1/main.js';
+        document.body.appendChild(s);
     }
 };
 </script>>