<template> <div> <div id="map" class="leaflet_container" style="background-color: white" /> <div style="background: #FFF; position: absolute; top: 20px; left: 50px; padding: 15px; z-index: 999; width: 400px;"> <el-input v-model="lnglat" size="small" /> </div> <div style="background: #FFF; position: absolute; top: 20px; right: 50px; padding: 15px; z-index: 999;"> <el-checkbox v-model="showBase">矢量</el-checkbox> <el-checkbox v-model="showImg">影像</el-checkbox> </div> </div> </template> <script> import L from 'leaflet' import { mapGetters } from 'vuex' import { getPartsTypeName } from '@/utils/constant' const esri = require('esri-leaflet') export default { name: 'CoordPicker', data() { return { showBase: false, showImg: true, map: null, // 地图对象 baseLayer: [], selectLayers: [0], // 选中图层 maps: [], // 地图图层 markers: [], lnglat: '', parts: [], // 部件图层 layerGroups: [], // 图层组,用于控制一组内容显示或者隐藏 featureLayer: null, imageLayer: null } }, computed: { ...mapGetters([ 'baseUrl', 'partsUrl', 'shopUrl', 'mapUrl' ]) }, watch: { showBase(val) { if (val) this.map.addLayer(this.featureLayer) else this.map.removeLayer(this.featureLayer) }, showImg(val) { if (val) this.map.addLayer(this.imageLayer) else this.map.removeLayer(this.imageLayer) } }, mounted() { this.init() }, methods: { // 地图初始化 init() { const map = L.map('map', { minZoom: 14, maxZoom: 25, center: this.baseConfig.center, zoom: this.baseConfig.zoom, zoomControl: false, attributionControl: false, crs: L.CRS.EPSG3857 }) map.doubleClickZoom.disable() // 禁止双击 this.map = map // data挂载map window.map = map // 加载天地图底图和标注 this.baseLayer.push(L.tileLayer(this.baseConfig.mapUrl).addTo(map)) this.baseLayer.push(L.tileLayer(this.baseConfig.labelUrl).addTo(map)) // 构建并加载layerGroup /* eslint-disable new-cap */ this.featureLayer = new L.layerGroup() this.imageLayer = new L.layerGroup() this.addMapDtLyaer() // 底图 // 部件图层组 for (let i = 3; i < 10; i++) { this.addPartsLayer(i) } const that = this map.on('click', function(e) { that.markers.forEach(marker => { that.map.removeLayer(marker) }) const pos = L.marker(e.latlng) that.map.addLayer(pos) that.markers.push(pos) that.lnglat = e.latlng.lng + ', ' + e.latlng.lat }) }, // 添加底图图层 addMapDtLyaer: function() { // 创建图层并加载到layerGroup中 const item = { url: `${this.baseUrl}${this.mapUrl}`, maxZoom: 25 } esri.dynamicMapLayer(item).addTo(this.featureLayer) L.tileLayer(this.baseConfig.satelliteUrl, { maxZoom: 25 }).addTo(this.imageLayer) this.layerGroups.push(this.featureLayer) this.layerGroups.push(this.imageLayer) // this.map.addLayer(this.featureLayer) this.map.addLayer(this.imageLayer) }, addPartsLayer: function(index) { const that = this const group = new L.layerGroup() // 创建layerGroup const domains = this.baseConfig.layers[index].domain domains.forEach(dom => { // 创建图层并加载到layerGroup中 const item = { url: `${this.baseUrl}${this.partsUrl}/${dom}`, minZoom: 18 } const layer = esri.featureLayer(item).addTo(group) this.parts.push(item) layer.on('click', function(e) { // 获取要素的属性 const properties = e.layer.feature.properties const dlCode = properties.objid.substring(6, 8) const xlCode = properties.objid.substring(8, 10) // 弹窗样式 const popupStr = '<div class="popup-div">' + '<div class="popup-title">部件信息</div>' + '<div class="dashed-line"></div>' + '<div class="popup-item"><label>部件类型</label>' + getPartsTypeName(dlCode, xlCode) + '</div>' + '<div class="popup-item"><label>部件编号</label>' + properties.objid + '</div>' + '<div class="popup-item"><label>所在网格编号</label>' + properties.bgid + '</div>' + '<div class="popup-item"><label>权属部门</label>' + properties.deptname2 + '</div>' + '<div class="popup-item"><label>责任部门</label>' + properties.deptname1 + '</div>' + '<div class="popup-item"><label>养护部门</label>' + properties.deptname3 + '</div>' + '</div>' // 弹出窗口 L.popup().setContent(popupStr).setLatLng(e.latlng).openOn(that.map) }) that.layerGroups.push(group) }) this.map.addLayer(group) } } } </script> <style rel="stylesheet/scss" lang="scss" scoped> /deep/ .el-input-group__append, .el-input-group__prepend { background-color: #409eff !important; border: 1px solid #409eff !important; } /*/deep/ .leaflet-touch .leaflet-control-layers, /deep/ .leaflet-touch .leaflet-bar {*/ /*!*border: 2px solid rgba(0,0,0,0.2);*!*/ /*!*background-clip: padding-box;*!*/ /*position: absolute !important;*/ /*right: 300px !important;*/ /*top: 10px;*/ /*}*/ $tableTitleHeight:35px; .leaflet_container{ width: calc( 100vw - 208px ); height: calc( 100vh - 158px ); background-color: white; } .search-total{ background-color: white; width: 300px;height: 35px; margin-top: 6px;border: 1px solid #DCDFE6; padding-left: 15px;color: #409eff; padding-top: 8px; font-size: 13px; border-radius:3px; } .draw-icon{ background-color: white; width: 100px;height: 40px; border: 1px solid #DCDFE6; border-radius:4px; } .table{ width: 300px;margin-top: 3px; border: 1px solid #DCDFE6; border-radius:3px; /deep/ .el-table th.is-leaf, /deep/ .el-table td { border-bottom: 1px solid white !important; } /deep/ .el-table--group::after, .el-table--border::after, .el-table::before { background-color: white !important; } .table-item{ padding: 5px; margin-top: 2px; margin-bottom: 1px; -moz-box-shadow: 0px 1px 3px #d9d9d9; /* 老的 Firefox */ box-shadow: 0px 1px 3px #d9d9d9; .item-icon{ width: 30px; height: 30px; background-size: contain; background-image: url("../../assets/global_images/point.png"); color: white; text-align: center; margin-top: 10px; margin-left: 5px; padding-top: 2px; } } } .top_title{ height: 40px; font-size: 18px; border: 1px solid #b5b5b5; padding-top: 10px; } .title{ height: 40px; width: 320px; padding-top: 10px; padding-left: 5px; z-index: 100000; background-color: rgba(255, 255, 255, 0.91); } .titletext{ text-align: center; font-size: 15px; } .titlenumtext{ text-align: center; font-size: 19px; } .list{ text-align:center; width: 500px; height: 40px; z-index: 10000; position: absolute; right:20px; top:20px; } .btn_bottom{ text-align:center; width: 100%; height:70px; z-index: 1000; position: fixed; bottom: 0; left: 0;right:0; } .table-name{ position:relative; width: 100px; top:20px; margin:-10px auto; //外面的div高度的一半 z-index: 100001; } .right-card{ margin-top: 20px;position: absolute;right:50px;z-index: 100000;width: 130px; } .table-title{ background-color:rgba(243, 243, 243, 1); height: $tableTitleHeight; .title-header{ line-height:$tableTitleHeight; color: #606266; font-size: 15px; i{ margin-left: 5px; margin-right: 5px; } } } </style> <style> .leaflet-container a.leaflet-popup-close-button { top: 5px; /* 修改弹窗关闭按钮样式 */ right: 10px; /* 修改弹窗关闭按钮样式 */ } .leaflet-popup-content .popup-div { font-size: 15px; padding: 6px; } .leaflet-popup-content .popup-title { font-weight: bold; } .leaflet-popup-content .dashed-line { border-bottom: 1px dashed #dddddd; margin: 10px -10px; } .leaflet-popup-content .popup-item { padding-bottom: 6px; } .leaflet-popup-content .popup-item label { font-weight: bold; padding-right: 15px; } </style>