Преглед на файлове

指挥中心添加全局地图模块

Shannon_mu преди 3 години
родител
ревизия
6e5db1fb32

BIN
commandCenter/src/assets/img/icon_point_community.png


+ 14 - 4
commandCenter/src/components/common/Header.vue

@@ -28,6 +28,7 @@
                     placeholder="所有社区"
                     class="saveColumn-select"
                     @change="$store.commit('setHomeCommunityAll', communityId)"
+                    clearable
                 >
                     <el-option v-for="(item, index) in communityList" :label="item.communityName" :value="item.id" :key="index"></el-option>
                 </el-select>
@@ -45,6 +46,7 @@
 </template>
 <script>
 import envConfig from '@/config';
+import { mapState } from 'vuex';
 export default {
     name: 'vheader',
     data() {
@@ -88,10 +90,18 @@ export default {
         };
     },
     computed: {
+        ...mapState(['homeCommunityAll']),
         menuList() {
             return this.$store.getters['getMenuList'] || [];
         }
     },
+    watch: {
+        homeCommunityAll(val) {
+            if (!!val) {
+                this.communityId = val;
+            }
+        }
+    },
     methods: {
         getUserInfo() {
             this.$http.postForm('/sc-user-center/user/findLoginUserById').then(({ status, data, msg }) => {
@@ -132,8 +142,8 @@ export default {
             this.$http.get('/sc-community/assets/community/list').then(({ data, msg, status }) => {
                 if (status == 0) {
                     this.communityList = data;
-                    this.communityId = data[0].id;
-                    this.$store.commit('setHomeCommunityAll', this.communityId);
+                    // this.communityId = data[0].id;
+                    // this.$store.commit('setHomeCommunityAll', this.communityId);
                     this.$store.commit('setAreaSelect', data);
                 }
             });
@@ -142,7 +152,7 @@ export default {
             this.tagTabIndex = index;
             this.$router.push({ name: item.linkPath });
         },
-     
+
         setINdex() {
             let index = 0;
             this.menuList.map((item, inx) => {
@@ -219,7 +229,7 @@ $colorOption: rgba(250, 250, 250, 0.6);
             border: 1px solid $colorOption;
             cursor: pointer;
             box-sizing: border-box;
-            background: #18344E;
+            background: #18344e;
             width: 100px;
             line-height: 30px;
             text-align: center;

+ 1 - 1
commandCenter/src/utils/AmapSearch.js

@@ -1,4 +1,4 @@
-var url = 'https://webapi.amap.com/maps?v=1.4.15&key=c2df9f4026e98b41962148c1703d8f33&plugin=AMap.Autocomplete,AMap.PlaceSearch&callback=onLoad';
+var url = 'https://webapi.amap.com/maps?v=1.4.15&key=c2df9f4026e98b41962148c1703d8f33&plugin=AMap.Autocomplete,AMap.PlaceSearch,AMap.Geocoder,AMap.DistrictSearch&callback=onLoad';
 var jsapi = document.createElement('script');
 jsapi.type = "text/javascript";
 jsapi.src = url;

+ 60 - 47
commandCenter/src/views/commandDispatch/index.vue

@@ -1,60 +1,67 @@
 <template>
     <div class="index-content">
-        <div
-            class="img-content"
-            :class="{ mouseStyle: openCur == 1 }"
-            ref="divImg"
-            :style="`backgroundImage:url(${modelPictureUrl});backgroundSize: 100% 100%;`"
-            @click="openCur == 1 ? paintingPoint($event) : null"
-        ></div>
-        <div class="point" :style="`left:${item.xcoordinate}%;top:${item.ycoordinate}%`" v-for="(item, index) in points" :key="index">
-            <span class="point-type" :class="`point-type${item.deviceType}`" @click="openCur !== 2 ? togglePop(item) : null"></span>
-            <span class="textStyle">{{ item.deviceName }}</span>
-            <span class="pointClose" @click="pointClose(item)" v-if="openCur == 2">x</span>
-        </div>
-        <div class="index-content-left" v-if="showChart">
-            <last-month-alarm></last-month-alarm>
-            <alarm-trend-analysis></alarm-trend-analysis>
-            <proportion-of-alarm-types></proportion-of-alarm-types>
-            <work-order-processing-status></work-order-processing-status>
-        </div>
-        <div class="index-content-right-buttom" @click="toggleShow"><span></span>{{ !showChart ? '显示' : '隐藏' }}图表</div>
-        <div class="index-dotting-list" :class="showChart ? '' : 'showChart'" v-if="menuListShow">
-            <div class="list-type" @click="addPoint()" :class="{ thisDotting: openCur == 1 }">
-                <span class="zoniot_font zoniot-icon-tianjia1"></span>添加
+        <template v-if="!showMap">
+            <div
+                class="img-content"
+                :class="{ mouseStyle: openCur == 1 }"
+                ref="divImg"
+                :style="`backgroundImage:url(${modelPictureUrl});backgroundSize: 100% 100%;`"
+                @click="openCur == 1 ? paintingPoint($event) : null"
+            ></div>
+            <div class="point" :style="`left:${item.xcoordinate}%;top:${item.ycoordinate}%`" v-for="(item, index) in points" :key="index">
+                <span class="point-type" :class="`point-type${item.deviceType}`" @click="openCur !== 2 ? togglePop(item) : null"></span>
+                <span class="textStyle">{{ item.deviceName }}</span>
+                <span class="pointClose" @click="pointClose(item)" v-if="openCur == 2">x</span>
             </div>
-            <div class="list-type" @click="editPoint" :class="{ thisDotting: openCur == 2 }">
-                <span class="zoniot_font zoniot-icon-bianji3"></span>编辑
+            <div class="index-content-left" v-if="showChart">
+                <last-month-alarm></last-month-alarm>
+                <alarm-trend-analysis></alarm-trend-analysis>
+                <proportion-of-alarm-types></proportion-of-alarm-types>
+                <work-order-processing-status></work-order-processing-status>
             </div>
-            <!-- <div class="list-type" @click="submitPoint" :class="{ thisDotting: openCur == 3 }">
+            <div class="index-content-right-buttom" @click="toggleShow"><span></span>{{ !showChart ? '显示' : '隐藏' }}图表</div>
+            <div class="index-dotting-list" :class="showChart ? '' : 'showChart'" v-if="menuListShow">
+                <div class="list-type" @click="addPoint()" :class="{ thisDotting: openCur == 1 }">
+                    <span class="zoniot_font zoniot-icon-tianjia1"></span>添加
+                </div>
+                <div class="list-type" @click="editPoint" :class="{ thisDotting: openCur == 2 }">
+                    <span class="zoniot_font zoniot-icon-bianji3"></span>编辑
+                </div>
+                <!-- <div class="list-type" @click="submitPoint" :class="{ thisDotting: openCur == 3 }">
                 <span class="zoniot_font zoniot-icon-baocun"></span>保存
-            </div> -->
-        </div>
-        <div class="rightFloatType" :class="showChart ? '' : 'showChart'">
-            <el-checkbox-group v-model="showPointArr">
-                <el-checkbox :class="'typeIcon' + items.type" v-for="items in deviceArr" :label="items.type" :key="items.type">{{
-                    items.label
-                }}</el-checkbox>
-            </el-checkbox-group>
-        </div>
-        <div class="index-content-right" v-if="showChart">
-            <water-consumption></water-consumption>
-            <power-consumption></power-consumption>
-            <patrol-task-completion-rate></patrol-task-completion-rate>
-            <key-areas></key-areas>
-        </div>
-        <div class="index-content-buttom" v-if="showChart">
-            <passenger-flow-statistics></passenger-flow-statistics>
-        </div>
-        <modular-loading :loadding="false" tipsText="地图加载中"></modular-loading>
+                </div> -->
+            </div>
+            <div class="rightFloatType" :class="showChart ? '' : 'showChart'">
+                <el-checkbox-group v-model="showPointArr">
+                    <el-checkbox :class="'typeIcon' + items.type" v-for="items in deviceArr" :label="items.type" :key="items.type">{{
+                        items.label
+                    }}</el-checkbox>
+                </el-checkbox-group>
+            </div>
+            <div class="index-content-right" v-if="showChart">
+                <water-consumption></water-consumption>
+                <power-consumption></power-consumption>
+                <patrol-task-completion-rate></patrol-task-completion-rate>
+                <key-areas></key-areas>
+            </div>
+            <div class="index-content-buttom" v-if="showChart">
+                <passenger-flow-statistics></passenger-flow-statistics>
+            </div>
+        </template>
+        <map-com v-else></map-com>
+        <!-- <modular-loading :loadding="loadding" tipsText="地图加载中"></modular-loading> -->
     </div>
 </template>
 
 <script>
 import smallModuleIndex from '@views/smallModule/index.js';
+import MapCom from './map.vue';
 import { mapState } from 'vuex';
 export default {
     mixins: [smallModuleIndex],
+    components: {
+        MapCom
+    },
     data() {
         return {
             showChart: true,
@@ -89,7 +96,8 @@ export default {
             showPointArr: [1, 2, 3, 4, 5],
             point: [],
             showOK: false,
-            imgUrl: require('@/assets/img/homeIcon/bg_bottom.png')
+            imgUrl: require('@/assets/img/homeIcon/bg_bottom.png'),
+            showMap: true
         };
     },
     computed: {
@@ -114,11 +122,15 @@ export default {
     watch: {
         //全局社区接口调用
         homeCommunityAll(val) {
-            try {
+            debugger;
+            if (!!val) {
                 this.mixins_query.communityId = val;
                 this.getData();
                 this.getImg();
-            } catch {}
+                this.showMap = false;
+            } else {
+                this.showMap = true;
+            }
         }
     },
     methods: {
@@ -259,6 +271,7 @@ export default {
     created() {
         this.mixins_query.communityId = this.homeCommunityAll;
         if (!!this.mixins_query.communityId) {
+            this.showMap = false;
             this.getImg();
             this.getData();
         }

+ 269 - 0
commandCenter/src/views/commandDispatch/map.vue

@@ -0,0 +1,269 @@
+<template>
+    <div class="mapItems">
+        <modular-loading :loadding="loadding" tipsText="地图加载中"></modular-loading>
+        <div class="topSelect">
+            <div></div>
+        </div>
+        <div class="mapInit" id="mapInit"></div>
+    </div>
+</template>
+<script>
+import { mapState } from 'vuex';
+export default {
+    data() {
+        return {
+            map: '',
+            disCountry: '',
+            placeSearch: '',
+            district: null,
+            marker: '',
+            polygons: [],
+            addressName: '', //地址查询名称
+            poisArray: [],
+            loadding: true,
+            mixins_query: {
+                communityId: ''
+            },
+            centet: []
+        };
+    },
+    mounted() {},
+    computed: {
+        ...mapState(['homeCommunityAll']),
+        poisArrays() {
+            return this.poisArray;
+            // let arrs = [];
+            // this.poisArray.map((item) => {
+            //     if (!!this.mixins_query.communityId) {
+            //         if (item.id == this.mixins_query.communityId) {
+            //             arrs = [item];
+            //         }
+            //     } else {
+            //         arrs = this.poisArray;
+            //     }
+            // });
+            // return arrs;
+        }
+    },
+    watch: {
+        homeCommunityAll(val) {
+            if (!!val) {
+                this.mixins_query.communityId = val;
+                if (!!this.map) {
+                    this.map.clearMap();
+                }
+            }
+            if (this.poisArrays.length > 0) {
+                this.addIcon(this.poisArrays);
+            }
+        }
+    },
+
+    methods: {
+        init() {
+            this.map = new AMap.Map('mapInit', {
+                resizeEnable: true, //是否监控地图容器尺寸变化
+                center: this.centet,
+                zoom: 8, //初始化地图层级
+                mapStyle: 'amap://styles/darkblue',
+                defaultCursor: 'pointer'
+            });
+            //地图加载完成监听点击事件
+            this.map.on('complete', () => {
+                this.loadding = false;
+                if (this.poisArrays.length > 0) {
+                    this.addIcon(this.poisArrays);
+                }
+                this.mapClick();
+            });
+        },
+        mapClick() {
+            this.map.on('click', (ev) => {
+                this.getAddress([ev.lnglat.lng, ev.lnglat.lat]);
+            });
+        },
+
+        addIcon(arrs) {
+            let self = this;
+            arrs.map((item) => {
+                self.marker = new AMap.Marker({
+                    icon: new AMap.Icon({
+                        image: require('@assets/img/icon_point_community.png'),
+                        size: new AMap.Size(40, 50),
+                        imageSize: new AMap.Size(40, 50)
+                    }),
+                    position: [item.longitude, item.latitude],
+                    map: self.map,
+                    communityData: item
+                });
+                self.marker.setLabel({
+                    offset: new AMap.Pixel(-15, 50),
+                    content: `${item.communityName}`
+                });
+                if (self.poisArrays.length < 2) {
+                    self.map.setFitView();
+                }
+                self.marker.on('click', function () {
+                    self.setCommunity(this.De.communityData);
+                });
+            });
+        },
+        setCommunity(its) {
+            this.$store.commit('setHomeCommunityAll', its.id);
+            this.$parent.showMap = false;
+        },
+        //搜索区域
+        districtMask(val) {
+            if (!this.district) {
+                //实例化DistrictSearch
+                var opts = {
+                    subdistrict: 0, //获取边界不需要返回下级行政区
+                    extensions: 'all', //返回行政区边界坐标组等具体信息
+                    level: 'district' //查询行政级别为 市
+                };
+                this.district = new AMap.DistrictSearch(opts);
+            }
+            // this.district.setLevel(val);
+            this.district.search(val, (status, result) => {
+                this.map.remove(this.polygons); //清除上次结果
+                this.polygons = [];
+                var bounds = result.districtList[0].boundaries;
+                if (bounds) {
+                    for (var i = 0, l = bounds.length; i < l; i++) {
+                        //生成行政区划polygon
+                        var polygon = new AMap.Polygon({
+                            strokeWeight: 1, //边界宽度
+                            path: bounds[i],
+                            fillOpacity: 0.3, // 透明度
+                            fillColor: '#2887f2',
+                            strokeColor: '#2887f2' //边界颜色
+                        });
+                        this.polygons.push(polygon);
+                    }
+                }
+                this.map.add(this.polygons);
+                this.map.setFitView(this.polygons); //视口自适应
+            });
+        },
+        getAddress(points) {
+            //获取准确地址
+            let geocoder = new AMap.Geocoder({ radius: 1000 });
+            geocoder.getAddress(points, (status, result) => {
+                if (status === 'complete' && result.regeocode) {
+                    this.districtMask(result.regeocode.addressComponent.district);
+                } else {
+                    this.map.remove(this.polygons);
+                }
+            });
+        },
+        getPoin(resolve) {
+            this.$http.get('/sc-community/assets/community/list').then(({ data, status, msg }) => {
+                if (status == 0) {
+                    this.poisArray = data;
+                    this.centet = this.getPointsCenter(data);
+                    resolve && resolve(true);
+                }
+            });
+        },
+        getLoc(resolve) {
+            this.$http.get('/sc-user-center/user/findUserArea').then(({ data, status, msg }) => {
+                if (status == 0) {
+                    this.centet[0] = data.lng;
+                    this.centet[1] = data.lat;
+                    resolve && resolve(true);
+                }
+            });
+        },
+        getPointsCenter(points) {
+            var point_num = points.length; //坐标点个数
+            var X = 0,
+                Y = 0,
+                Z = 0;
+            for (let i = 0; i < points.length; i++) {
+                if (points[i] == '') {
+                    continue;
+                }
+                var lat, lng, x, y, z;
+                lat = (parseFloat(points[i].latitude) * Math.PI) / 180;
+                lng = (parseFloat(points[i].longitude) * Math.PI) / 180;
+                x = Math.cos(lat) * Math.cos(lng);
+                y = Math.cos(lat) * Math.sin(lng);
+                z = Math.sin(lat);
+                X += x;
+                Y += y;
+                Z += z;
+            }
+            X = X / point_num;
+            Y = Y / point_num;
+            Z = Z / point_num;
+            var tmp_lng = Math.atan2(Y, X);
+            var tmp_lat = Math.atan2(Z, Math.sqrt(X * X + Y * Y));
+
+            return [(tmp_lng * 180) / Math.PI, (tmp_lat * 180) / Math.PI];
+            return [
+                Math.floor(((tmp_lng * 180) / Math.PI) * 1000000) / 1000000,
+                Math.floor(((tmp_lat * 180) / Math.PI) * 1000000) / 1000000
+            ];
+        }
+    },
+    destroyed() {
+        this.map && this.map.destroy();
+    },
+    created() {
+        // this.getPoin();
+        // new Promise((resolve) => {
+        //     this.getLoc(resolve);
+        // }).then(() => {
+        //     new Promise((resolve) => {
+        //         if (!!AMap) {
+        //             resolve(true);
+        //         }
+        //     }).then(() => {
+        //         this.init();
+        //     });
+        // });
+
+        new Promise((resolve) => {
+            this.getPoin(resolve);
+        }).then(() => {
+            new Promise((resolve) => {
+                if (!!AMap) {
+                    resolve(true);
+                }
+            }).then(() => {
+                this.init();
+            });
+        });
+    }
+};
+</script>
+<style scoped lang="scss">
+@import '@assets/css/public-style.scss';
+.mapItems {
+    height: 100%;
+    position: relative;
+    color: white;
+    .topSelect {
+        position: absolute;
+        top: rem(15);
+        left: 0;
+        padding: 0 rem(15);
+        width: 100%;
+    }
+}
+#mapInit {
+    width: 100%;
+    height: 100%;
+    /deep/ .amap-marker-label {
+        background: rgba(0, 0, 0, 0.5);
+        text-align: center;
+        min-width: rem(80);
+        min-height: rem(20);
+        line-height: rem(20);
+        box-shadow: 0px 2px 10px 0px rgba(66, 70, 86, 0.08);
+        border: 0 none;
+        white-space: nowrap;
+        box-shadow: 0 0 5px 0rgba (0, 0, 0, 0.3);
+    }
+}
+</style>