Browse Source

添加了”聚合显示“和改正了”地图下方的空白条“

xicheng79 3 years ago
parent
commit
802f6e81bf

+ 11 - 9
src/components/LayerSelector.vue

@@ -1,13 +1,13 @@
 <template>
     <div class="change-div" id="change-div">
       <div class="change-container-div">
-        <div class="layer-select-button-div" id="layer-select-button-div">
-          <img id="layer-select-button" class="layer-select-button" src="../../static/img/layerselect.png" alt=""
-               @click="basemapShow = !basemapShow">
+        <div class="layer-select-button-div" id="layer-select-button-div" @click="basemapShow = !basemapShow">
+          <i class="fa fa-map-o" aria-hidden="true"  v-if="!basemapShow"></i>
+          <i class="fa fa-map" aria-hidden="true"  v-if="basemapShow"></i>
         </div>
-        <div class="info-select-button-div" id="info-select-button-div">
-          <img id="info-select-button" class="info-select-button" src="../../static/img/info.png" alt=""
-               @click="infomapShow = !infomapShow">
+        <div class="info-select-button-div" id="info-select-button-div"  @click="infomapShow = !infomapShow">
+          <i class="fa fa-commenting-o" aria-hidden="true" v-if="!infomapShow"></i>
+          <i class="fa fa-commenting" aria-hidden="true" v-if="infomapShow"></i>
         </div>
       </div>
 
@@ -83,7 +83,8 @@ export default {
   height: 12px;
 }
 .basemap-text{
-  color: #007bff;
+  /* color: #007bff; */
+  color: rgb(159, 123,80);
   font-weight: bold;
   font-family: "Source Han Sans CN";
 
@@ -129,7 +130,7 @@ export default {
 }
 
 .change-div {
-  background-color: rgb(255, 255, 255);
+  background-color:transparent;
   width:65px;
   height: 35px;
   z-index: 999;
@@ -144,13 +145,14 @@ export default {
   position: absolute;
   font-size: 12px;
   z-index: 100;
-  background: rgba(255, 255, 255, 0.7);
+  background: transparent;
   opacity: 0.95;
   right: 0px;
   margin-top: 40px;
   height: 65px;
   width:100px;
   align-content: center;
+  margin-top: 35px
 }
 
 .info-content {

+ 41 - 46
src/components/map.vue

@@ -80,7 +80,7 @@ import {defaults as defaultInteractions} from 'ol/interaction'
 import Feature from 'ol/Feature'
 import * as control from 'ol/control'
 import {Style, Icon, Stroke} from 'ol/style'
-import {Vector as VectorSource} from 'ol/source'
+import {Cluster, Vector as VectorSource} from 'ol/source'
 import TileSource from 'ol/source/TileWMS'
 import XYZ from 'ol/source/XYZ'
 import Overlay from 'ol/Overlay'
@@ -99,7 +99,7 @@ import more from '../assets/icon/more.svg'
 import DrawShape from '../../static/js/startDrawShape'
 
 // card
-import phoneCard from './card.vue'
+import phoneCard from './Card.vue'
 
 // slogan
 import slogan from './slogan.vue'
@@ -172,7 +172,7 @@ export default {
           image: new Icon({
             crossOrigin: 'anonymous',
             src: more,
-            scale: 0.25
+            scale: 0.15
           })
         }),
         LineString: new Style({
@@ -282,20 +282,46 @@ export default {
         interactions: defaultInteractions({
           pinchRotate: false // 移动端禁止地图旋转
         }),
+
         view: new View({
           center: center,
           zoom: zoom,
           extent: extent,
           maxZoom: 18.5
         }),
-        // controls: control.defaults({
-        //   // zoom: false
-        // }),
-        controls: control.defaults().extend([
-          new control.MousePosition()
-        ])
+
+        controls: control.defaults({
+          zoom: false
+        })
+        // controls: control.defaults().extend([
+        //   new control.MousePosition()
+        // ])
       })
-      map.updateSize()
+      setTimeout(function () { map.updateSize() })
+    },
+
+    /**
+     * @description:开启聚合
+     */
+    addCluster: function (layerName, style) {
+      let layer = map.getLayers().array_
+      for (let i = 0; i < layer.length; i++) {
+        if (layer[i].className_ === layerName) {
+          var targetLayer = layer[i]
+        }
+      }
+      if (targetLayer) {
+        let features = targetLayer.getSource().getFeatures()
+        let source = new VectorSource({
+          features: features
+        })
+        let clusterSource = new Cluster({
+          distance: 20,
+          source: source
+        })
+        targetLayer.setSource(clusterSource)
+        targetLayer.setStyle(style)
+      }
     },
 
     /**
@@ -374,6 +400,7 @@ export default {
           title: title,
           class: 'layer',
           className: title,
+          // extent: this.extent,
           source: new VectorSource({
           })
         })
@@ -574,6 +601,7 @@ export default {
           res.data.forEach(item => {
             that.printFeature('reportLayer', item, 'report')
           })
+          this.addCluster('reportLayer', this.reportStyles.Point)
         })
     },
 
@@ -592,6 +620,7 @@ export default {
           res.data.forEach(item => {
             that.printFeature('noticeLayer', item, 'notice')
           })
+          this.addCluster('noticeLayer', this.noticeStyles.Point)
         })
     },
 
@@ -607,6 +636,7 @@ export default {
           res.data.forEach(e => {
             that.printFeature('cultureLayer', e, 'culture')
           })
+          this.addCluster('cultureLayer', this.cultureStyles.Point)
         })
     },
 
@@ -621,6 +651,7 @@ export default {
           res.data.forEach(e => {
             that.printFeature('otherLayer', e, 'other')
           })
+          this.addCluster('otherLayer', this.cultureStyles.Point)
         })
     },
 
@@ -855,42 +886,6 @@ export default {
       }
     },
 
-    /**
-     * @description:底图切换
-     * @param {string} name:识别字符串
-     */
-    basemapChange: function (name) {
-      switch (name) {
-        case 'all':
-          this.setMapVisible(['cdut', 'tiandi', 'tiandi-label'])
-          break
-        case 'cdut':
-          this.setMapVisible(['cdut'])
-          break
-        case 'tiandi':
-          this.setMapVisible(['tiandi', 'tiandi-label'])
-          break
-      }
-    },
-
-    /**
-     * @description:设置图层可见性
-     * @param {Array} titles:装有图层title的数组
-     */
-    setMapVisible: function (titles) {
-      var layers = map.getLayers().array_
-      for (var i = 0; i < layers.length; i++) {
-        if (layers[i].values_.class !== 'basemap') {
-          continue
-        }
-        if (titles.indexOf(layers[i].values_.title) > -1) {
-          layers[i].setVisible(true)
-        } else {
-          layers[i].setVisible(false)
-        }
-      }
-    },
-
     // LayerSelector related
     // 底图选择 和 消息选择 的图层切换
     getCheckedMap: function (checkMapList) {

+ 1 - 1
src/components/pcBar.vue

@@ -1,7 +1,7 @@
 <template>
   <div>
     <!-- 侧边栏 -->
-    <b-list-group id="list" v-show="isShow">
+    <b-list-group id="list" v-show="isShow" app>
       <!-- header -->
       <b-list-group-item id="header">
           <i class="fa fa-list" aria-hidden="true"></i>&nbsp; 列表

+ 1 - 1
src/components/slogan.vue

@@ -41,7 +41,7 @@ export default {
     writing-mode: vertical-lr; /*设置文字纵向*/
     box-sizing: border-box; /*固定div大小*/
     line-height: 35px;
-    font-size: 19px;
+    font-size: 18px;
     font-family: "Source Han Sans CN";
     white-space: pre-wrap;
     /*float: left;*/

+ 2 - 0
src/pages/home.vue

@@ -48,6 +48,8 @@ export default {
    width:310px
  }
  .map {
+   bottom: 0%;
+   width: 100%;
    height: 100%;
    flex: 1;
    /* width: calc(100% - 310px); */