派生自 wuyushui/SewerAndRainNetwork

徐旺旺
2021-03-01 a1638dfffa2992ac78d68d9cd955c1263d71b803
src/views/MapTemplate.vue
@@ -1,60 +1,153 @@
<template>
  <div class="full-screen">
        <div id="map" ref="rootmap"></div>
        <sgis-layer-controller :preset="'warningPreset'"></sgis-layer-controller>
    <div class="full-screen">
        <popup ref="popup" @callPopup="callPopup"></popup>
        <div id="map" ref="rootmap">
        </div>
        <sgis-layer-controller :preset="'warningPreset'">
            <lc-basemap></lc-basemap>
            <!--            <div class="barline"></div>-->
            <lc-service-layer class="barline" v-if="lcServiceLayerVisible"></lc-service-layer>
        </sgis-layer-controller>
        <monitor-panel></monitor-panel>
  </div>
<!--        <top-enterprise-panel></top-enterprise-panel>-->
        <tool-box-panel></tool-box-panel>
      <menu-special></menu-special>
    </div>
</template>
<script>
import 'leaflet/dist/leaflet.css'
import Sgis from '@src/Sgis'
// import mapConfig from '@/conf/MapConfig'
import SgisLayerController from '@components/LayerController/LayerController'
import MonitorPanel from '@components/panel/MonitorPanel'
import { mapMutations, mapState } from 'vuex'
import LcBasemap from '@components/LayerController/modules/LcBaseMap'
import LcServiceLayer from '@components/LayerController/modules/LcServiceLayer'
import MonitorPanel from '@components/panel/RightSearchPanel'
// import TopEnterprisePanel from '@components/panel/TopEnterprisePanel'
import ToolBoxPanel from '@components/panel/ToolBoxPanel'
import Popup from '@views/popup/Popup'
import MenuSpecial from '@components/panel/MenuTopic'
export default {
  name: 'MapTemplate',
  components: {SgisLayerController, MonitorPanel},
  datas:{
      ...mapState("/",{})
  components: {
    MenuSpecial,
    ToolBoxPanel,
    // TopEnterprisePanel,
    SgisLayerController,
    MonitorPanel,
    LcBasemap,
    LcServiceLayer,
    Popup
  },
  mounted(){
      this.$nextTick(() => {
          this.init()
      })
  data () {
    return {
      map: null,
      lcServiceLayerVisible: false,
      basemapHelper: {},
      serviceLayerHelper: {},
      vectorLayerHelper: {}
    }
  },
  methods:{
      ...mapMutations({
        setMapObj: 'setMapObj',
        setLayerHelper: 'setLayerHelper'
      }),
      init() {
        const mapcontainer = this.$refs.rootmap
        this.mapObj = Sgis.initMap(mapcontainer)
        this.basemapHelper = Sgis.initBasemaps(this.mapObj.map, this.mapObj.L) // 初始化底图
        this.vectorLayerHelper = Sgis.initLayers(this.mapObj.map, this.mapObj.L, {}, this.$nodeEnv) // 初始化业务图层
        this.setLayerHelper(this.vectorLayerHelper)
        return this.map
      },
      setLayerHelper(){
  computed: {
    config () {
      return this.$store.state.map.config
    }
  },
  beforeMount () {
    this.$nextTick(() => {
      this.init()
    })
  },
  methods: {
    saveMapStatus () {
      window.serviceLayerHelper = this.serviceLayerHelper
      this.$store.commit('setMapObj', this.map)
      this.$store.commit('setBasemapHelper', this.basemapHelper)
      // this.$store.commit('setServiceLayerHelper', this.serviceLayerHelper)
      this.$store.commit('setVectorLayerHelper', this.vectorLayerHelper)
      }
      this.lcServiceLayerVisible = true
    },
    init () {
      const mapcontainer = this.$refs.rootmap
      this.map = Sgis.initMap(mapcontainer)
      this.basemapHelper = Sgis.initBasemapsHelper(this.map) // 初始化基础底图助手
      this.basemapHelper.initBasemap(this.config, false) // 第二个参数,表示是否内网底图
      this.serviceLayerHelper = Sgis.initTileLayersHelper(this.map) // 初始化业务底图助手
      console.log(this.$refs.popup.$el)
      this.serviceLayerHelper.initServiceLayers(this.config, this.$refs.popup)
      this.vectorLayerHelper = Sgis.initVectorLayersHelper(this.map) // 初始化动态要素图层助手
      this.vectorLayerHelper.initVectorLayers(this.config)
      this.saveMapStatus()
      // this.setMapObj(this.mapObj)
      // this.setBasemapHelper(this.basemapHelper)
      // this.setServiceLayerHelper(this.serviceLayerHelper)
      // this.setVectorLayerHelper(this.vectorLayerHelper)
      this.addMarker()
    },
    addMarker () {
      const L = this.L
      var icon = new L.Icon({
        iconUrl: 'assets/images/map/marker-icon.png',
        shadowUrl: 'assets/images/map/marker-shadow.png',
        iconSize: [25, 41],
        iconAnchor: [12, 41],
        popupAnchor: [1, -34],
        shadowSize: [41, 41]
      })
      var marker = L.marker([32.2221, 118.7843], {
        icon: icon
      }).addTo(this.map)
        .bindPopup(() => this.$refs.popup.$el, {
          className: 's-map-popup',
          minWidth: 300,
          closeButton: false,
          autoClose: false
        })
        .bindTooltip('字体光晕效果t.', {
          // permanent : true,
          offset: [0, 0], // 偏移
          direction: 'right', // 放置位置
          // sticky:true,//是否标记在点上面
          className: 'anim-tooltip'// CSS控制
        })
      marker.on('popupopen', this.onLayerClick)
    },
    onLayerClick () {
      this.$refs.popup.setShow()
    },
    callPopup (val) {
      console.log(val)
    }
  }
}
</script>
<style lang="less">
.full-screen{
    width: 100%;
    height: 100%;
    margin: 0;
    padding: 0;
    position: absolute;
  #map{
    height: 100%;
    width: 100%;
  }
}
    .full-screen {
        width: 100%;
        height: 100%;
        margin: 0;
        padding: 0;
        position: absolute;
        #map {
            height: 100%;
            width: 100%;
        }
        .barline {
            //width: 100%;
            //height: 1px;
            //background-color: #0661AE;
            border-top: 1px solid #0661AE;
        }
    }
</style>>