智慧保安互联网APP
shuishen
2021-08-12 489acf5ce86f711ef70e67a3bb1511571177a8bb
mapWz/js/vueMain.js
File was renamed from xcxMapWz/js/vueMain.js
@@ -24,46 +24,46 @@
        shipingM3u8Url: '',
        resultFeedbackPopupShow: false,
        popupDisplay: "none",
        userId: null,
    },
    methods: {
        getDataList() {
            var that = this;
            that.beginCome();
        },
        beginCome() {
            var data = []
                //url解码
         axios.get('http://192.168.0.108:81/blade-user/page?size=99999').then((res) => {
            console.log(res, 4848)
            res.data.data.records.forEach(item => {
               if (item.longitude && item.latitude) {
                  data.push(item)
               }
            })
         })
            // this.getdata = this.getQueryVariable('data') || data;
            this.map = this.beginMap(this.map, data); //创建并接受map
            this.move = new myDomMove('#seedata', '.title', '#map');
            this.map.invalidateSize(true); //应用地图高度
            this.move.followFinger(this.map, 'down');
            var resultData = []
            //url解码
            var jurisdictionId = this.GetQueryString('id')
            this.userId = this.GetQueryString('userid')
            axios.get('http://223.82.109.183:2080/api/blade-user/page?size=99999&jurisdiction=' + jurisdictionId).then((res) => {
                if (res.data.data.records.length > 0) {
                    res.data.data.records.forEach(item => {
                        if (item.longitude && item.latitude) {
                            resultData.push(item)
                        }
                    })
                }
                this.map = this.beginMap(this.map, resultData); //创建并接受map
                this.move = new myDomMove('#seedata', '.title', '#map');
                this.map.invalidateSize(true); //应用地图高度
                this.move.followFinger(this.map, 'down');
            })
        },
        //url解码
        getQueryVariable(variable) {
            var query = window.location.search.substring(1);
            var vars = query.split("&");
            for (var i = 0; i < vars.length; i++) {
                var pair = vars[i].split("=");
                if (pair[0] == variable) { return JSON.parse(decodeURI(pair[1])); } //解码url 和 JSON
            }
            return (false);
        GetQueryString(name) {
            var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
            var r = window.location.search.substr(1).match(reg);
            if (r != null) return unescape(r[2]);
            return null;
        },
        beginMap(map, data) {
            var that = this,
                center = [Number(data[0].longitude), Number(data[0].latitude)];
                // url = `http://s16s652780.51mypc.cn/api/alarm/alarm/APP-getAlarm?id=${data[0].id}`;
            var that = this, center = [28.708432053474827, 115.85883507433789];
            // url = `http://s16s652780.51mypc.cn/api/alarm/alarm/APP-getAlarm?id=${data[0].id}`;
            // url = `http://localhost:89/alarm/alarm/APP-getAlarm?id=${data[0].id}`;
            this.nowPosition = center;
            // axios.post(url).then((res) => {
@@ -104,20 +104,13 @@
                    iconSize: [30, 30], // 图标尺寸
                }
            });
            var carIcon = new transportIcon({ //引入图标
                    iconUrl: './img/gray.png'
                }),
                planeIcon = new transportIcon({
                    iconUrl: './img/green.png'
                }),
                busIcon = new transportIcon({
                    iconUrl: './img/red.png'
                });
            wzIcon = new transportIcon({
                iconUrl: './img/wz.png'
            });
            var wzIcon = new transportIcon({
                iconUrl: './img/wz.png'
            });
            var setData = (a) => { //定义图标
                marker = L.marker([Number(a.longitude), Number(a.latitude)], {
                marker = L.marker([Number(a.latitude), Number(a.longitude)], {
                    icon: wzIcon,
                    // icon: a.dtype == 0 ? carIcon : a.dtype == 1 ? planeIcon : a.dtype == 2 ? busIcon : '',
                    // title: title,
@@ -138,19 +131,44 @@
            }
            map.addLayer(markers);
            // markers.on('click', function(a) {
            //     // that.drawer = true;
            //     that.seedata = a.layer.options.myData;
            //     that.nowPosition = [that.seedata.wd, that.seedata.jd]
            //     $('#seedata').css('top', '');
            //     $('#map').css("height", (index, value) => { //改变地图高度
            //         return '50%';
            //     })
            //     map.invalidateSize(true); //应用地图高度
            //     that.move.destruction();
            //     that.move.followFinger(map, 'down');
            markers.on('click', function (a) {
                // that.drawer = true;
                that.seedata = a.layer.options.myData;
                that.nowPosition = [that.seedata.wd, that.seedata.jd]
                $('#seedata').css('top', '');
            // });
                $('#seedata .content').html(`<div>
                        <label for="">所属公司:</label>
                            ${that.seedata.deptName}
                    </div>
                    <div>
                        <label for="">保安姓名:</label>
                            ${that.seedata.realName}
                    </div>`);
                $('#seedata').stop().show();
                $('#seedata .clear').click(function () {
                    $('#seedata').stop().hide();
                    $('#map').css("height", (index, value) => { //改变地图高度
                        return '100%';
                    })
                })
                $('#map').css("height", (index, value) => { //改变地图高度
                    return '80%';
                })
                map.invalidateSize(true); //应用地图高度
                that.move.destruction();
                that.move.followFinger(map, 'down');
            });
            this.nowPosition = center;
            return map; //抛出map
        },
@@ -276,7 +294,9 @@
                    .post(
                        "/api_control", {}, {
                            params: {
                                param: JSON.stringify({ PktType: "GetAccessToken" }),
                                param: JSON.stringify({
                                    PktType: "GetAccessToken"
                                }),
                            },
                        }
                    )
@@ -312,6 +332,22 @@
                that.lat = position.lat; //
                that.lng = position.lng; //火星坐标 //TODO 实现业务代码逻辑 
                console.log(adCode, position, addr, 15145)
                axios.post("http://223.82.109.183:2080/api/liveLocation/saveLiveLocationAndLocus", {
                    type: 1,
                    workerId: that.userId,
                    longitude: position.lng,
                    latitude: position.lat,
                    location: addr == '' ? position.province + position.city : addr
                }).then((res) => {
                    console.log(res, 4848)
                })
                if (that.LXdhStart != null) {
                    that.map.removeLayer(that.LXdhStart);
                }
@@ -342,13 +378,22 @@
            };
            geolocation.getLocation(showPosition, showErr, options);
        },
    },
    created() {},
    mounted() {
        this.getDataList();
        this.beginCome();
        this.getLocationData();
        var that = this;
        setInterval(() => {
            that.getLocationData();
        }, 10000);
    },
    wacth: {}
})