HomeMap.vue 2.98 KB
<template>
  <div id="map">
  </div>
</template>

<script>
import * as i2d from "i2d";
import 'leaflet/dist/leaflet.css'
import 'i2d/dist/i2d.css'

export default {
  name: 'HomeMap',
  data() {
    return {
      mapOptions: {
        copyright: false,
        basemaps: [
          {
            type: 'group',
            name: '天地图电子',
            layers: [
              {
                type: 'tdt',
                layer: 'vec_d',
                key: i2d.Token.tiandituArr,
                crs: i2d.CRS.EPSG4490,
              },
              {
                type: 'tdt',
                layer: 'vec_z',
                key: i2d.Token.tiandituArr,
                crs: i2d.CRS.EPSG4490,
              }
            ],
            icon: './dz.png',
            show: true
          },
          {
            type: 'group',
            name: '天地图地形',
            layers: [
              {
                type: 'tdt',
                layer: 'ter_d',
                key: i2d.Token.tiandituArr,
                errorTileUrl: 'img/tile/errortile.png',
                crs: i2d.CRS.EPSG4490
              },
              {
                type: 'tdt',
                layer: 'ter_z',
                key: i2d.Token.tiandituArr,
                crs: i2d.CRS.EPSG4490
              }
            ],
            icon: './dx.png'
          },
          {
            type: 'group',
            name: '天地图影像',
            layers: [
              {
                type: 'tdt', layer: 'img_d', key: i2d.Token.tiandituArr,
                crs: i2d.CRS.EPSG4490
              },
              {
                type: 'tdt', layer: 'img_z', key: i2d.Token.tiandituArr,
                crs: i2d.CRS.EPSG4490
              }
            ],
            icon: './yx.png',
            //必须给最后一个底图配置zindex要不然最后底图切换专题图层不展示
            // 要比专题图层小
            zIndex: 1
          }
        ],
        zoom: 12,
        minZoom: 4,
        maxZoom: 20,
        // 纬度在前
        center: [34.247161, 108.944213],
        crs: i2d.CRS.EPSG4490,
        control: {
          scale: true,
          locationBar: {
            crs: 'CGCS2000_GK_Zone_3',
            template: '<div>经度:{lng}</div> <div>纬度:{lat}</div> <div>层级:{level}</div>'
          },
          zoom: {position: 'bottomleft'},
          toolBar: {
            position: 'bottomleft',
            item: ['home', 'fullscreen', 'clear']
          },
          mapSwitch: {
            position: 'bottomright'
          }
        }
      }
    }
  },
  mounted() {
    const map = new i2d.Map('map', this.mapOptions)
    map.on('baselayerchange', (map) => {
      map.sourceTarget.getLayers().forEach(lyr => {
        console.log(lyr.name, lyr.zIndex)
      })
      map.sourceTarget.getBasemaps().forEach(lyr => {
        console.log(lyr.name, lyr.zIndex)
      })
    })
  }
}
</script>

<style scoped>
#map {
  position: absolute;
  margin: 0;
  height: 60%;
  width: 60%;
}
</style>