还未完成 地图点聚合改造

This commit is contained in:
TimSpan 2024-12-26 16:52:02 +08:00
parent fcfee709b6
commit 1de9dfe3ad
2 changed files with 134 additions and 94 deletions

View File

@ -11,10 +11,10 @@
<body>
<div id="app"></div>
<script
src="https://webapi.amap.com/maps?v=1.4.15&key=ca549d915cb38803582ca7e85c5f972c&plugin=AMap.MarkerClusterer"></script>
<!-- <script
src="https://webapi.amap.com/maps?v=2.0&key=ca549d915cb38803582ca7e85c5f972c&plugin=AMap.MarkerClusterer"></script> -->
src="https://webapi.amap.com/maps?v=1.4.15&key=ca549d915cb38803582ca7e85c5f972c&plugin=AMap.MarkerClusterer"></script> -->
<script
src="https://webapi.amap.com/maps?v=2.0&key=ca549d915cb38803582ca7e85c5f972c&plugin=AMap.MarkerCluster"></script>
<!-- &plugin=AMap.MarkerClusterer -->
<script src="/haikang/h5player.min.js"></script>

View File

@ -406,7 +406,7 @@ var state = {
id: 'indexx',
map: null as any
}
var cluster: any
import {LoadingOutlined} from '@ant-design/icons-vue'
const indicator = h(LoadingOutlined, {
@ -720,8 +720,12 @@ const clickKz = (dat2a: any) => {
})
visible.value = true
}
var count: any
var points: any[] = []
let count: any
let points: any[] = []
// @ts-ignore
let cluster: AMap.MarkerCluster | null = null
let markers: AMap.Marker[] = []
var _renderClusterMarker = function (context: any) {
var factor = Math.pow(context.count / count, 1 / 18)
var div = document.createElement('div')
@ -744,15 +748,30 @@ var _renderClusterMarker = function (context: any) {
context.marker.setOffset(new AMap.Pixel(-size / 2, -size / 2))
context.marker.setContent(div)
}
onMounted(() => {
getAiCount()
gettotal()
initMap()
gettree4('')
getAi()
getjingqing()
})
//
const createCluster = () => {
// cluster = null
if (cluster) cluster.setMap(null) //
// @ts-ignore
cluster = new AMap.MarkerCluster(state.map, points, {
gridSize: 80,
maxZoom: 12,
renderClusterMarker: _renderClusterMarker
})
}
// Marker
function clearMarkers() {
const overlays = state.map.getAllOverlays('marker')
overlays.forEach((marker: any) => {
if (!marker.isCluster) {
state.map.remove(marker) // Marker
}
})
}
//
// const clearMarkers = () => {
// markers.forEach((marker) => state.map.remove(marker))
// markers = []
// }
const treedata = () => {
api
.post('/multialarm/client/alarm_point/count', {
@ -769,53 +788,94 @@ const treedata = () => {
})
.then((res: JsonResult<any>) => {
console.log('🚀 ~ .then ~ res:', res)
res.data.map((x: any) => {
const marker = new AMap.Marker({
position: new AMap.LngLat(x.longitude == null ? 0 : x.longitude, x.latitude == null ? 0 : x.latitude),
offset: new AMap.Pixel(-15, -15),
icon: new AMap.Icon({
image: x.deviceType == '00' ? image3 : x.deviceType == '03' ? image1 : x.deviceType == '04' ? image2 : '',
size: new AMap.Size(40, 46.5),
imageSize: new AMap.Size(30, 30) //
}),
title: ''
})
marker.on('click', function () {
deviceInfoWindow.value = new AMap.InfoWindow({
isCustom: true, //使
content: createSubstanceInfowindow2(x, '1'),
offset: new AMap.Pixel(5, -13)
})
deviceInfoWindow.value.open(state.map, [x.longitude == null ? 0 : x.longitude, x.latitude == null ? 0 : x.latitude])
})
state.map.add(marker)
points.push(marker)
points = res.data.map((x: any) => {
return {lnglat: [x.longitude == null ? 0 : x.longitude, x.latitude == null ? 0 : x.latitude], x: x}
})
count = points.length
// console.log('___________________________points', points)
//
cluster = new AMap.MarkerClusterer(state.map, points, {
gridSize: 80,
maxZoom: 12,
renderClusterMarker: _renderClusterMarker
console.log('points___________________________', points)
createCluster() //
state.map.on('zoomend', () => {
let zoom = state.map.getZoom()
console.log('zoom等级____________________________', zoom)
clearMarkers() // Marker
if (zoom > 12) {
points.forEach((item: any) => {
// console.log('🚀 ~ points.forEach ~ p:', item)
const marker = new AMap.Marker({
position: item.lnglat,
icon: new AMap.Icon({
image: item.x.deviceType == '00' ? image3 : item.x.deviceType == '03' ? image1 : item.x.deviceType == '04' ? image2 : '',
size: new AMap.Size(40, 46.5),
imageSize: new AMap.Size(30, 30)
})
})
marker.on('click', function () {
deviceInfoWindow.value = new AMap.InfoWindow({
isCustom: true,
content: createSubstanceInfowindow2(item.x, '1'),
offset: new AMap.Pixel(5, -13)
})
deviceInfoWindow.value.open(state.map, item.lnglat)
})
state.map.add(marker)
})
cluster?.setMap(null) //
} else {
createCluster() //
// cluster.setMap(state.map)
//
// cluster.setMap(state.map)
}
})
state.map.plugin(['AMap.MarkerClusterer'], () => {
// Marker
cluster.on('click', function (e: any) {
const {clusterData, lnglat} = e
let currentZoom = state.map.getZoom()
console.log('🚀 ~ currentZoom:', currentZoom)
// <= 12
if (currentZoom < 12) {
state.map.setZoomAndCenter(currentZoom + 1, lnglat) // 2
}
clearMarkers() // Marker
let markers: any[] = []
console.log('🚀 ~ e:', e)
clusterData.forEach((item: any) => {
console.log('🚀 ~ clusterData.forEach ~ item:', item)
const marker = new AMap.Marker({
position: item.lnglat,
offset: new AMap.Pixel(-15, -15),
icon: new AMap.Icon({
image: item.x.deviceType == '00' ? image3 : item.x.deviceType == '03' ? image1 : item.x.deviceType == '04' ? image2 : '',
size: new AMap.Size(40, 46.5),
imageSize: new AMap.Size(30, 30)
})
})
marker.on('click', function () {
deviceInfoWindow.value = new AMap.InfoWindow({
isCustom: true,
content: createSubstanceInfowindow2(item.x, '1'),
offset: new AMap.Pixel(5, -13)
})
deviceInfoWindow.value.open(state.map, item.lnglat)
})
markers.push(marker)
state.map.add(marker)
})
// Marker
state.map.setFitView(markers)
})
state.map.plugin('AMap.MarkerCluster', () => {
let zoom = state.map.getZoom()
console.log('当前地图的缩放级别是:' + zoom)
cluster
})
// var cluster = new AMap.MarkerCluster(state.map, points, {
// gridSize: 80,
// maxZoom: 12,
// renderClusterMarker: _renderClusterMarker
// })
// state.map.plugin('AMap.MarkerCluster', () => {
// let zoom = state.map.getZoom()
// console.log('' + zoom)
// cluster
// })
})
})
}
@ -972,44 +1032,18 @@ const gettotal = () => {
let deviceInfoWindow = ref<any>()
const selectA = (selectedKeys: any, e: any) => {
console.log('selectedKeys', selectedKeys, e)
if (selectedKeys[0].length >= 13) {
let targetLangLat = [e.selectedNodes[0].longitude == null ? 0 : e.selectedNodes[0].longitude, e.selectedNodes[0].latitude == null ? 0 : e.selectedNodes[0].latitude]
// if (selectedKeys[0].length >= 13) {
let targetLangLat = [e.selectedNodes[0].longitude == null ? 0 : e.selectedNodes[0].longitude, e.selectedNodes[0].latitude == null ? 0 : e.selectedNodes[0].latitude]
deviceInfoWindow.value = new AMap.InfoWindow({
isCustom: true, //使
content: createSubstanceInfowindow2(e.selectedNodes[0], '1'),
offset: new AMap.Pixel(5, -13)
})
deviceInfoWindow.value.open(state.map, [e.selectedNodes[0].longitude == null ? 0 : e.selectedNodes[0].longitude, e.selectedNodes[0].latitude == null ? 0 : e.selectedNodes[0].latitude])
deviceInfoWindow.value = new AMap.InfoWindow({
isCustom: true, //使
content: createSubstanceInfowindow2(e.selectedNodes[0], '1'),
offset: new AMap.Pixel(5, -13)
})
deviceInfoWindow.value.open(state.map, [e.selectedNodes[0].longitude == null ? 0 : e.selectedNodes[0].longitude, e.selectedNodes[0].latitude == null ? 0 : e.selectedNodes[0].latitude])
state.map.setZoomAndCenter(12, targetLangLat)
// cluster = new AMap.MarkerClusterer(state.map, points, {
// gridSize: 80,
// maxZoom: 12,
// renderClusterMarker: _renderClusterMarker
// })
// state.map.plugin(['AMap.MarkerClusterer'], () => {
// let zoom = state.map.getZoom()
// console.log('' + zoom)
// cluster
// })
// state.map.setCenter(targetLangLat)
// state.map.on('moveend', () => {
// console.log(11111)
// })
// state.map.on('zoomend', () => {
// console.log(22222)
// })
// state.map.on('moveend', () => {
// console.log(33333)
// })
// if (cluster) {
// cluster.draw()
// }
// treedata()
}
state.map.setZoomAndCenter(12, targetLangLat, true) //
// }
}
const createSubstanceInfowindow = (obj: any, type: any) => {
@ -1406,9 +1440,15 @@ const initMap = () => {
getdayline()
// stationWebsocket();
}
// state.map.on('zoomend', () => {
// console.log(11111)
// })
onMounted(() => {
getAiCount()
gettotal()
initMap()
gettree4('')
getAi()
getjingqing()
})
</script>
<style scoped lang="scss">