2021-03-25 19:33:48 +08:00
|
|
|
|
<template>
|
|
|
|
|
|
<div class="latlng">
|
|
|
|
|
|
<div class="input-box">
|
2021-11-05 20:19:26 +08:00
|
|
|
|
<div class="input-box-item" style="display: none;">
|
|
|
|
|
|
<el-input v-model="lnglat" @blur="setLatlng" @change="setLatlng">
|
2022-06-23 16:58:18 +08:00
|
|
|
|
<template slot="prepend" v-if="showZoom">{{$t('config.system.basic.lnglat')}}</template>
|
2021-03-25 19:33:48 +08:00
|
|
|
|
</el-input>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
<div class="input-box-item" v-if="showZoom">
|
2023-06-26 15:43:25 +08:00
|
|
|
|
<el-input-number v-model="zoom" :max="mapParam.maxZoom" :precision="0" :min="mapParam.minZoom" :controls="false" class="prepend_unit" :data-unit="$t('config.system.basic.zoom')">
|
|
|
|
|
|
</el-input-number>
|
2021-03-25 19:33:48 +08:00
|
|
|
|
</div>
|
2021-08-24 09:30:01 +08:00
|
|
|
|
<div class="input-box-item" style="margin-right: unset !important;width: 30px !important;flex:unset;" @click="mapConfigVisible = true"><i class="nz-icon nz-icon-weizhi" style="color:rgb(238, 157, 63)"></i></div>
|
2021-03-25 19:33:48 +08:00
|
|
|
|
</div>
|
|
|
|
|
|
<el-dialog :visible.sync="mapConfigVisible" :title="$t('config.system.basic.mapTitle')" width="calc(50% - 10px)" @close="mapClose" @opened="initMap" class=" nz-dialog map-config-dialog" :modal-append-to-body="appendToBody">
|
2022-08-18 14:58:06 +08:00
|
|
|
|
<div id="map" style="height: 100%; width: 100%"></div>
|
2021-03-25 19:33:48 +08:00
|
|
|
|
</el-dialog>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</template>
|
|
|
|
|
|
|
|
|
|
|
|
<script>
|
2021-03-31 11:10:04 +08:00
|
|
|
|
// 引入Leaflet对象 挂载到Vue上,便于全局使用,也可以单独页面中单独引用
|
|
|
|
|
|
import 'leaflet/dist/leaflet.css'
|
2022-08-18 14:58:06 +08:00
|
|
|
|
import maplibregl from 'maplibre-gl'
|
2022-08-23 10:55:05 +08:00
|
|
|
|
import mapAllStyle from '@/components/chart/chart/mapStyle'
|
2021-03-31 11:10:04 +08:00
|
|
|
|
export default {
|
|
|
|
|
|
name: 'latlngPicker',
|
|
|
|
|
|
props: {
|
2021-08-24 09:30:01 +08:00
|
|
|
|
initData: { },
|
2021-03-31 11:10:04 +08:00
|
|
|
|
appendToBody: { type: Boolean, default: true },
|
|
|
|
|
|
showZoom: { type: Boolean, default: true }
|
|
|
|
|
|
},
|
|
|
|
|
|
data () {
|
|
|
|
|
|
return {
|
2022-08-23 10:55:05 +08:00
|
|
|
|
theme: localStorage.getItem(`nz-user-${localStorage.getItem('nz-user-id')}-theme`) || 'light',
|
2021-03-31 11:10:04 +08:00
|
|
|
|
lnglat: '',
|
2021-06-04 14:35:22 +08:00
|
|
|
|
oldlnglat: '',
|
2022-08-18 14:58:06 +08:00
|
|
|
|
mapParam: { longitude: 116.39, latitude: 39.9, zoom: 4, minZoom: 1, maxZoom: 7 },
|
2021-03-31 11:10:04 +08:00
|
|
|
|
map: null,
|
|
|
|
|
|
marker: null,
|
2021-11-05 20:19:26 +08:00
|
|
|
|
mapConfigVisible: false,
|
|
|
|
|
|
changeZoom: false,
|
2022-08-18 15:19:05 +08:00
|
|
|
|
zoom: null
|
2021-03-31 11:10:04 +08:00
|
|
|
|
}
|
|
|
|
|
|
},
|
2021-06-04 14:35:22 +08:00
|
|
|
|
watch: {
|
|
|
|
|
|
initData: {
|
2021-08-23 15:21:46 +08:00
|
|
|
|
immediate: true,
|
2021-11-05 20:19:26 +08:00
|
|
|
|
handler (n) {
|
|
|
|
|
|
this.queryDefaultMapConfig(n).then(() => {
|
2021-08-23 15:21:46 +08:00
|
|
|
|
this.lnglat = this.mapParam.longitude + ',' + this.mapParam.latitude
|
2021-11-05 20:19:26 +08:00
|
|
|
|
})
|
2021-06-04 14:35:22 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
},
|
2021-03-31 11:10:04 +08:00
|
|
|
|
mounted () {
|
|
|
|
|
|
},
|
|
|
|
|
|
methods: {
|
2021-11-05 20:19:26 +08:00
|
|
|
|
initMap () {
|
2021-03-31 11:10:04 +08:00
|
|
|
|
if (this.map) {
|
|
|
|
|
|
this.map.remove()
|
|
|
|
|
|
this.map = null
|
2021-03-25 19:33:48 +08:00
|
|
|
|
}
|
2021-03-31 11:10:04 +08:00
|
|
|
|
this.setLatlng()
|
2022-08-23 13:54:13 +08:00
|
|
|
|
const mapStyle = mapAllStyle[this.theme]
|
2022-08-18 14:58:06 +08:00
|
|
|
|
mapStyle.center = [Number(this.mapParam.longitude), Number(this.mapParam.latitude)]
|
|
|
|
|
|
mapStyle.zoom = Number(this.zoom)
|
|
|
|
|
|
const mapId = document.getElementById('map')
|
|
|
|
|
|
this.map = new maplibregl.Map({
|
|
|
|
|
|
container: mapId,
|
|
|
|
|
|
style: mapStyle,
|
2023-04-06 11:02:13 +08:00
|
|
|
|
maxZoom: this.mapParam.maxZoom || 7,
|
|
|
|
|
|
minZoom: this.mapParam.minZoom || 1,
|
2022-08-24 09:57:40 +08:00
|
|
|
|
renderWorldCopies: false,
|
|
|
|
|
|
maxBounds: [[-179, -85], [179, 85]],
|
2022-08-18 14:58:06 +08:00
|
|
|
|
hash: false,
|
|
|
|
|
|
transformRequest: function (url, resourceType) {
|
|
|
|
|
|
if (resourceType === 'Tile' && url.indexOf('https://api.maptiler.com/tiles/v3') > -1) {
|
|
|
|
|
|
const urlParams = url.split('.pbf')[0].split('/')
|
|
|
|
|
|
const z = urlParams[urlParams.length - 3]
|
|
|
|
|
|
const x = urlParams[urlParams.length - 2]
|
|
|
|
|
|
const y = urlParams[urlParams.length - 1]
|
2022-09-27 13:47:53 +08:00
|
|
|
|
const newUrl1 = `nzMap:///static/Titles/${z}/${x}/${y}.pbf`
|
2022-08-18 14:58:06 +08:00
|
|
|
|
return {
|
|
|
|
|
|
url: newUrl1,
|
|
|
|
|
|
credentials: 'include',
|
|
|
|
|
|
method: 'GET'
|
|
|
|
|
|
// Include cookies for cross-origin requests
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
if (resourceType === 'SpriteJSON') {
|
|
|
|
|
|
return {
|
2022-09-27 13:47:53 +08:00
|
|
|
|
url: 'nzMap:///static/Titles/sprite.json',
|
2022-08-18 14:58:06 +08:00
|
|
|
|
credentials: 'include',
|
|
|
|
|
|
method: 'GET'
|
|
|
|
|
|
// Include cookies for cross-origin requests
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
if (resourceType === 'SpriteImage') {
|
|
|
|
|
|
return {
|
2022-09-27 13:47:53 +08:00
|
|
|
|
url: 'nzMap:///static/Titles/sprite.png',
|
2022-08-18 14:58:06 +08:00
|
|
|
|
credentials: 'include',
|
|
|
|
|
|
method: 'GET'
|
|
|
|
|
|
// Include cookies for cross-origin requests
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2021-03-31 11:10:04 +08:00
|
|
|
|
})
|
2022-08-18 14:58:06 +08:00
|
|
|
|
maplibregl.addProtocol('nzMap', (params, callback) => { // 切片显示接口 防止跨域的问题
|
|
|
|
|
|
fetch(`${params.url.split('://')[1]}`)
|
|
|
|
|
|
.then(t => {
|
|
|
|
|
|
if (t.status == 200) {
|
|
|
|
|
|
t.arrayBuffer().then(arr => {
|
|
|
|
|
|
callback(null, arr, null, null)
|
|
|
|
|
|
})
|
|
|
|
|
|
} else {
|
|
|
|
|
|
callback(new Error(`Tile fetch error: ${t.statusText}`))
|
|
|
|
|
|
}
|
|
|
|
|
|
})
|
|
|
|
|
|
.catch(e => {
|
|
|
|
|
|
callback(new Error(e))
|
|
|
|
|
|
})
|
|
|
|
|
|
return { cancel: () => { } }
|
|
|
|
|
|
})
|
|
|
|
|
|
const marker = ''
|
|
|
|
|
|
const self = this
|
|
|
|
|
|
const geoJSON = {
|
|
|
|
|
|
type: 'FeatureCollection',
|
|
|
|
|
|
features: [
|
|
|
|
|
|
{
|
|
|
|
|
|
type: 'Feature',
|
|
|
|
|
|
properties: {},
|
|
|
|
|
|
geometry: {
|
|
|
|
|
|
type: 'Point',
|
|
|
|
|
|
coordinates: [Number(self.mapParam.longitude), Number(self.mapParam.latitude)]
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
]
|
|
|
|
|
|
}
|
|
|
|
|
|
this.map.on('load', function () {
|
|
|
|
|
|
self.map.addSource('centerMarker',
|
|
|
|
|
|
{
|
|
|
|
|
|
type: 'geojson',
|
|
|
|
|
|
data: geoJSON
|
|
|
|
|
|
})
|
|
|
|
|
|
self.map.addLayer({
|
|
|
|
|
|
id: 'centerMarkerLayer',
|
|
|
|
|
|
type: 'circle',
|
|
|
|
|
|
source: 'centerMarker',
|
|
|
|
|
|
paint: {
|
|
|
|
|
|
'circle-radius': 8,
|
|
|
|
|
|
'circle-color': '#23BF9A',
|
|
|
|
|
|
'circle-opacity': 1
|
|
|
|
|
|
}
|
|
|
|
|
|
})
|
2022-08-23 13:54:13 +08:00
|
|
|
|
self.map.addControl(new maplibregl.NavigationControl(), 'bottom-right')
|
|
|
|
|
|
const mapboxglInner = document.getElementsByClassName('mapboxgl-ctrl-attrib-inner')
|
|
|
|
|
|
mapboxglInner[0].innerHTML = '<span>© MapTiler</span> <span>© OpenStreetMap contributors</span>'
|
2022-08-18 14:58:06 +08:00
|
|
|
|
})
|
|
|
|
|
|
// const marker = L.marker([this.mapParam.latitude, this.mapParam.longitude]).addTo(map)
|
|
|
|
|
|
this.map.on('click', function (e) {
|
|
|
|
|
|
const coords = e.lngLat
|
|
|
|
|
|
geoJSON.features[0].geometry.coordinates = [coords.lng, coords.lat]
|
|
|
|
|
|
self.map.getSource('centerMarker').setData(geoJSON)
|
2021-03-31 11:10:04 +08:00
|
|
|
|
})
|
2022-08-18 14:58:06 +08:00
|
|
|
|
// this.marker = marker
|
2021-03-31 11:10:04 +08:00
|
|
|
|
},
|
2021-11-05 20:19:26 +08:00
|
|
|
|
mapClose () {
|
|
|
|
|
|
this.changZoom = true
|
2021-03-31 11:10:04 +08:00
|
|
|
|
this.mapConfigVisible = false
|
2022-08-18 14:58:06 +08:00
|
|
|
|
const latlng = this.map.getSource('centerMarker')._data.features[0].geometry.coordinates
|
|
|
|
|
|
this.mapParam.longitude = latlng[0].toFixed(7)
|
|
|
|
|
|
this.mapParam.latitude = latlng[1].toFixed(7)
|
2021-03-31 11:10:04 +08:00
|
|
|
|
this.lnglat = this.mapParam.longitude + ',' + this.mapParam.latitude
|
2021-11-05 20:19:26 +08:00
|
|
|
|
this.zoom = this.map.getZoom()
|
|
|
|
|
|
this.setLatlng()
|
2021-03-31 11:10:04 +08:00
|
|
|
|
},
|
2021-11-05 20:19:26 +08:00
|
|
|
|
setLatlng () {
|
2021-03-31 11:10:04 +08:00
|
|
|
|
const lnglat = this.lnglat.split(',')
|
2021-12-31 14:17:06 +08:00
|
|
|
|
const lnglatValue = /^\d+(\.\d{1,7})?$/
|
2022-02-10 09:48:21 +08:00
|
|
|
|
if (lnglat[0] !== 'undefined' && lnglat[1] !== 'undefined' && lnglatValue.test(lnglat[1]) && lnglatValue.test(lnglat[0])) {
|
2021-12-20 11:27:29 +08:00
|
|
|
|
this.mapParam.longitude = lnglat[0]
|
|
|
|
|
|
this.mapParam.latitude = lnglat[1]
|
|
|
|
|
|
} else {
|
|
|
|
|
|
this.mapParam.longitude = '-33.9257813'
|
|
|
|
|
|
this.mapParam.latitude = '55.5761251'
|
|
|
|
|
|
}
|
2021-11-05 20:19:26 +08:00
|
|
|
|
this.$emit('lnglatChange', this.lnglat, this.zoom)
|
2021-03-31 11:10:04 +08:00
|
|
|
|
},
|
2021-11-05 20:19:26 +08:00
|
|
|
|
getAttribute () {
|
|
|
|
|
|
return JSON.parse(JSON.stringify({ ...this.mapParam, zoom: this.zoom }))
|
2021-03-31 11:10:04 +08:00
|
|
|
|
},
|
2021-11-05 20:19:26 +08:00
|
|
|
|
setLnglat (lat, lng) {
|
2021-03-31 11:10:04 +08:00
|
|
|
|
if (lat && lng) {
|
|
|
|
|
|
this.mapParam.latitude = lat
|
|
|
|
|
|
this.mapParam.longitude = lng
|
|
|
|
|
|
this.lnglat = this.mapParam.longitude + ',' + this.mapParam.latitude
|
2021-03-25 19:33:48 +08:00
|
|
|
|
}
|
2021-03-31 11:10:04 +08:00
|
|
|
|
},
|
2021-11-05 20:19:26 +08:00
|
|
|
|
queryDefaultMapConfig (data) {
|
2021-08-23 15:21:46 +08:00
|
|
|
|
return new Promise(resolve => {
|
|
|
|
|
|
this.$get('/sysConfig?paramKey=map_center_config').then(response => {
|
|
|
|
|
|
if (response.code == 200) {
|
2021-11-05 20:19:26 +08:00
|
|
|
|
const mapParam = JSON.parse(response.data.paramKey.map_center_config)
|
|
|
|
|
|
if (data) {
|
|
|
|
|
|
const coord = data.split(',')
|
|
|
|
|
|
this.mapParam = { ...mapParam, longitude: coord[0], latitude: coord[1] }
|
|
|
|
|
|
} else {
|
|
|
|
|
|
this.mapParam = { ...mapParam }
|
|
|
|
|
|
}
|
2023-06-26 15:43:25 +08:00
|
|
|
|
this.zoom = mapParam.zoom
|
2021-08-23 15:21:46 +08:00
|
|
|
|
resolve()
|
|
|
|
|
|
}
|
|
|
|
|
|
})
|
2021-03-31 11:10:04 +08:00
|
|
|
|
})
|
2021-03-25 19:33:48 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
2021-03-31 11:10:04 +08:00
|
|
|
|
}
|
2021-03-25 19:33:48 +08:00
|
|
|
|
</script>
|