高德地圖vue實現自定義標點熱力圖效果(縮放時展示不同數據)

高德地圖插件引入省略。。。樣式和vue基礎組件省略。。。

  • 如果每個標點沒有數值,則可以用點聚合來實現功能
  • 下面例子,每個標點會有按市統計的數值,而且縮放一定程度時,需要展示按省統計的標點,因此需要自定義標點樣式和監聽地圖縮放時間,來實現這個功能
  1. 效果圖
    在這里插入圖片描述

1.1:初始化時,按省進行統計
在這里插入圖片描述
1.2:地圖放大一定程度時,按市進行統計
在這里插入圖片描述

  1. 同一個經緯點可支持展示兩個數據

在這里插入圖片描述

  1. 代碼實現
<template><div class="infringement-map"><div style="height: 100%;" class="card-style"><Row style="height: 100%" :gutter="16"><Col span="24" style="border-left:1px solid #E5E5E5;height: calc(100% - 30px);"><Row class="detail-header " style="background-color: #fff;"><span>高德熱力圖</span></Row><Row class="bg-white top-border" style="padding: 5px 10px;height: 100%" :gutter="22"><Col style="height: 100%;" span="24"><div class="box-wrap"><div id="tort-map"></div></div></Col></Row></Col></Row></div></div>
</template><script>
export default {data() {return {map: null,cityCoordinateList: [],provinceCoordinateList: [],listData: [],markersList: [],totalPoints: null,isLoadedProvince: false,isLoadedCity: false}},mounted() {this.initMap()this.searchHandler()},beforeDestroy() {this.map && this.map.destroy()this.zoomOff()},methods: {searchHandler() {const res = {'code': 0,'message': '','data': {'cityCoordinateList': [{'latitude': '116.405285','longitude': '39.904989','name': '北京','sellerQty': 14,'mfrsQty': null},{'latitude': '114.352482','longitude': '36.103442','name': '安陽市','sellerQty': null,'mfrsQty': 1},{'latitude': '113.051227','longitude': '23.685022','name': '清遠市','sellerQty': 9,'mfrsQty': null},{'latitude': '116.587245','longitude': '35.415393','name': '濟寧市','sellerQty': 2,'mfrsQty': null},{'latitude': '102.712251','longitude': '25.040609','name': '昆明市','sellerQty': null,'mfrsQty': 4},{'latitude': '111.975107','longitude': '21.859222','name': '陽江市','sellerQty': 2,'mfrsQty': null},{'latitude': '119.649506','longitude': '29.089524','name': '金華市','sellerQty': 1,'mfrsQty': null},{'latitude': '120.153576','longitude': '30.287459','name': '杭州市','sellerQty': 1,'mfrsQty': null},{'latitude': '114.412599','longitude': '23.079404','name': '惠州市','sellerQty': 1,'mfrsQty': null},{'latitude': '113.442973','longitude': '30.328407','name': '仙桃市','sellerQty': 4,'mfrsQty': null},{'latitude': '121.472644','longitude': '31.231706','name': '上海','sellerQty': 3,'mfrsQty': null},{'latitude': '111.134335','longitude': '37.524366','name': '呂梁市','sellerQty': 1,'mfrsQty': null},{'latitude': '108.948024','longitude': '34.263161','name': '西安市','sellerQty': 1,'mfrsQty': null},{'latitude': '117.043551','longitude': '30.50883','name': '安慶市','sellerQty': 1,'mfrsQty': null},{'latitude': '117.190182','longitude': '39.125596','name': '天津','sellerQty': null,'mfrsQty': 1},{'latitude': '117.283042','longitude': '31.86119','name': '合肥市','sellerQty': null,'mfrsQty': 1},{'latitude': '118.275162','longitude': '33.963008','name': '宿遷市','sellerQty': 1,'mfrsQty': null},{'latitude': '119.452753','longitude': '32.204402','name': '鎮江市','sellerQty': 1,'mfrsQty': null},{'latitude': '119.527082','longitude': '26.65924','name': '寧德市','sellerQty': 1,'mfrsQty': null},{'latitude': '113.132855','longitude': '29.37029','name': '岳陽市','sellerQty': 1,'mfrsQty': null},{'latitude': '118.175393','longitude': '39.635113','name': '唐山市','sellerQty': 1,'mfrsQty': null},{'latitude': '110.364977','longitude': '21.274898','name': '湛江市','sellerQty': 1,'mfrsQty': null},{'latitude': '87.617733','longitude': '43.792818','name': '烏魯木齊市','sellerQty': 1,'mfrsQty': null},{'latitude': '118.11022','longitude': '24.490474','name': '廈門市','sellerQty': 2,'mfrsQty': null},{'latitude': '114.085947','longitude': '22.547','name': '深圳市','sellerQty': 4,'mfrsQty': null},{'latitude': '82.074778','longitude': '44.903258','name': '博爾塔拉蒙古自治州','sellerQty': 1,'mfrsQty': null},{'latitude': '116.632301','longitude': '23.661701','name': '潮州市','sellerQty': 1,'mfrsQty': null},{'latitude': '113.280637','longitude': '23.125178','name': '廣州市','sellerQty': 1,'mfrsQty': 1},{'latitude': '115.469381','longitude': '35.246531','name': '菏澤市','sellerQty': null,'mfrsQty': 1},{'latitude': '109.702392','longitude': '18.638189','name': '保亭黎族苗族自治縣','sellerQty': 1,'mfrsQty': null},{'latitude': '126.427839','longitude': '41.942505','name': '白山市','sellerQty': 1,'mfrsQty': null},{'latitude': '106.504962','longitude': '29.533155','name': '重慶','sellerQty': 1,'mfrsQty': 1},{'latitude': '126.642464','longitude': '45.756967','name': '哈爾濱市','sellerQty': 1,'mfrsQty': null},{'latitude': '110.299121','longitude': '25.274215','name': '桂林市','sellerQty': 1,'mfrsQty': null},{'latitude': '114.391136','longitude': '27.8043','name': '宜春市','sellerQty': 1,'mfrsQty': null},{'latitude': '113.665412','longitude': '34.757975','name': '鄭州市','sellerQty': 1,'mfrsQty': null},{'latitude': '105.724998','longitude': '34.578529','name': '天水市','sellerQty': 1,'mfrsQty': null},{'latitude': '108.320004','longitude': '22.82402','name': '南寧市','sellerQty': 1,'mfrsQty': null},{'latitude': '120.301663','longitude': '31.574729','name': '無錫市','sellerQty': 2,'mfrsQty': null}],'provinceCoordinateList': [{'latitude': '103.823557','longitude': '36.058039','name': '甘肅省','sellerQty': 1,'mfrsQty': null},{'latitude': '114.502461','longitude': '38.045474','name': '河北省','sellerQty': 1,'mfrsQty': null},{'latitude': '117.000923','longitude': '36.675807','name': '山東省','sellerQty': 2,'mfrsQty': 1},{'latitude': '118.767413','longitude': '32.041544','name': '江蘇省','sellerQty': 4,'mfrsQty': null},{'latitude': '116.405285','longitude': '39.904989','name': '北京','sellerQty': 14,'mfrsQty': null},{'latitude': '102.712251','longitude': '25.040609','name': '云南省','sellerQty': null,'mfrsQty': 4},{'latitude': '110.33119','longitude': '20.031971','name': '海南省','sellerQty': 1,'mfrsQty': null},{'latitude': '125.3245','longitude': '43.886841','name': '吉林省','sellerQty': 1,'mfrsQty': null},{'latitude': '119.306239','longitude': '26.075302','name': '福建省','sellerQty': 3,'mfrsQty': null},{'latitude': '120.153576','longitude': '30.287459','name': '浙江省','sellerQty': 2,'mfrsQty': null},{'latitude': '114.298572','longitude': '30.584355','name': '湖北省','sellerQty': 4,'mfrsQty': null},{'latitude': '121.472644','longitude': '31.231706','name': '上海','sellerQty': 3,'mfrsQty': null},{'latitude': '113.280637','longitude': '23.125178','name': '廣東省','sellerQty': 19,'mfrsQty': 1},{'latitude': '106.504962','longitude': '29.533155','name': '重慶','sellerQty': 1,'mfrsQty': 1},{'latitude': '112.549248','longitude': '37.857014','name': '山西省','sellerQty': 1,'mfrsQty': null},{'latitude': '117.190182','longitude': '39.125596','name': '天津','sellerQty': null,'mfrsQty': 1},{'latitude': '115.892151','longitude': '28.676493','name': '江西省','sellerQty': 1,'mfrsQty': null},{'latitude': '108.948024','longitude': '34.263161','name': '陜西省','sellerQty': 1,'mfrsQty': null},{'latitude': '126.642464','longitude': '45.756967','name': '黑龍江省','sellerQty': 1,'mfrsQty': null},{'latitude': '113.665412','longitude': '34.757975','name': '河南省','sellerQty': 1,'mfrsQty': 1},{'latitude': '87.617733','longitude': '43.792818','name': '新疆維吾爾自治區','sellerQty': 2,'mfrsQty': null},{'latitude': '117.283042','longitude': '31.86119','name': '安徽省','sellerQty': 1,'mfrsQty': 1},{'latitude': '108.320004','longitude': '22.82402','name': '廣西壯族自治區','sellerQty': 2,'mfrsQty': null},{'latitude': '112.982279','longitude': '28.19409','name': '湖南省','sellerQty': 1,'mfrsQty': null}]}}this.removeMarkers()// 按市統計的數據this.cityCoordinateList = res.data && res.data.cityCoordinateList || []// 按省統計的數據this.provinceCoordinateList = res.data && res.data.provinceCoordinateList || []// 默認按省進行標點,按省匯總標點總數this.totalPoints = this.provinceCoordinateList.lengththis.addPoint('province')},/** ******  地圖 start  ********/// 初始化地圖initMap() {this.map = new AMap.Map('tort-map', {zoom: 4, // 級別mapStyle: 'amap://styles/grey',center: [116.397428, 39.90923], // 中心點坐標viewMode: '3D' // 使用3D視圖})this.map.on('complete', () => {console.log('地圖渲染完成')this.zoomOn()})},addPoint(type) {const pointList = type === 'province' ? this.provinceCoordinateList : this.cityCoordinateListpointList.forEach(item => {const marker = new AMap.Marker({position: [item.latitude, item.longitude], // 位置// 將 html 傳給 contentcontent: this.preRenderMarker(item)})this.map.add(marker) // 添加到地圖// 記錄地圖上的標點,移除時需要this.markersList.push(marker)})},preRenderMarker(item) {// item.mfrsQty:M數據  item.sellerQty:S數據const { mfrsQty, sellerQty } = itemif (mfrsQty && sellerQty) {// M數據和S數據都有值,則渲染復合的標記return this.renderClusterMarkerBoth(mfrsQty, sellerQty)} else if (mfrsQty) {// 只有M數據有值,渲染M數據的標點return this.renderClusterMarker(mfrsQty, 'mfrsQty')} else if (sellerQty) {// 只有S數據有值,渲染S數據的標點return this.renderClusterMarker(sellerQty, 'sellerQty')}},getBgColorByType (clusterCount, type) {let bgColor = null// 聚合點配色const defaultColor = type === 'mfrsQty' ? ['253,187,187','247,162,162','237,127,127','228,93,93','219,60,60']: ['195,252,195','178,240,178','153,222,154','130,205,131','120,198,121']if (clusterCount >= 0 && clusterCount < 10) {bgColor = defaultColor[0]} else if (clusterCount >= 10 && clusterCount < 50) {bgColor = defaultColor[1]} else if (clusterCount >= 50 && clusterCount < 100) {bgColor = defaultColor[2]} else if (clusterCount >= 100 && clusterCount < 200) {bgColor = defaultColor[3]} else if (clusterCount >= 200) {bgColor = defaultColor[4]}return bgColor},// 單種類型的標點自定義樣式renderClusterMarker (count, type) {// 聚合中點個數const clusterCount = countconst bgColor = this.getBgColorByType(count, type)const div = document.createElement('div')div.style.backgroundColor = 'rgba(' + bgColor + ',.5)'const size = Math.round(10 + Math.pow(clusterCount / this.totalPoints, 1 / 10) * 20)div.style.width = div.style.height = size + 'px'div.style.border = 'solid 1px rgba(' + bgColor + ',1)'div.style.borderRadius = size / 2 + 'px'div.innerHTML = clusterCountdiv.style.lineHeight = size + 'px'div.style.color = '#ffffff'div.style.fontSize = '12px'div.style.textAlign = 'center'return div},// 兩種類型的標點自定義樣式renderClusterMarkerBoth (mfrsQty, sellerQty) {const bgColorS = this.getBgColorByType(sellerQty, 'sellerQty')const bgColorM = this.getBgColorByType(mfrsQty, 'mfrsQty')const divDom = document.createElement('div')const divS = document.createElement('div')const divM = document.createElement('div')divDom.style.display = 'flex'divS.style.backgroundColor = 'rgba(' + bgColorS + ',.5)'divS.style.width = 30 + 'px'divS.style.height = 20 + 'px'divS.style.lineHeight = 20 + 'px'divS.style.border = 'solid 1px rgba(' + bgColorS + ',1)'divS.style.borderRadius = '30px 0 0 30px'divS.innerHTML = sellerQtydivS.style.color = '#ffffff'divS.style.fontSize = '12px'divS.style.textAlign = 'center'divM.style.backgroundColor = 'rgba(' + bgColorM + ',.5)'divM.style.width = 30 + 'px'divM.style.height = 20 + 'px'divM.style.lineHeight = 20 + 'px'divM.style.border = 'solid 1px rgba(' + bgColorM + ',1)'divM.style.borderRadius = '0 30px 30px 0'divM.innerHTML = mfrsQtydivM.style.color = '#ffffff'divM.style.fontSize = '12px'divM.style.textAlign = 'center'divDom.append(divS)divDom.append(divM)return divDom},removeMarkers() {this.map && this.map.remove(this.markersList)},// 地圖縮放等級改變mapZoom() {const currentZoom = this.map.getZoom() // 獲取當前地圖級別if (currentZoom <= 4 && !this.isLoadedProvince) {// 按省來渲染標記this.totalPoints = this.provinceCoordinateList.lengththis.isLoadedProvince = truethis.isLoadedCity = falsethis.removeMarkers()this.addPoint('province')} else if (currentZoom > 4 && !this.isLoadedCity) {// 按市渲染標記this.totalPoints = this.cityCoordinateList.lengththis.isLoadedCity = truethis.isLoadedProvince = falsethis.removeMarkers()this.addPoint('city')}},// 地圖縮放事件綁定zoomOn() {this.map && this.map.on('zoomchange', this.mapZoom)},// 地圖縮放事件解綁zoomOff() {this.map && this.map.off('zoomchange', this.mapZoom)}}
}</script><style scoped lang="scss">
.infringement-map {height: 100%;margin-top: -35px;.box-wrap {height: 100%;#tort-map {width: 100%;height: 100%;.citylist_popup_main {.city_content_top {box-sizing: content-box;}}}}
}
</style>

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/news/210122.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/210122.shtml
英文地址,請注明出處:http://en.pswp.cn/news/210122.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

leetcode刷題日志-54螺旋矩陣

思路&#xff1a; 上下左右設置四個邊界 每走完一行或者一列&#xff0c;移動相應邊界&#xff0c;當左邊界大于右邊界&#xff0c;或者上邊界大于下邊界時&#xff0c;結束 代碼如下&#xff1a; class Solution {public List<Integer> spiralOrder(int[][] matrix) {…

線程上下文切換

線程上下文切換 巧妙地利用了時間片輪轉的方式, CPU 給每個任務都服務一定的時間&#xff0c;然后把當前任務的狀態保存下來&#xff0c;在加載下一任務的狀態后&#xff0c;繼續服務下一任務&#xff0c;任務的狀態保存及再加載, 這段過程就叫做上下文切換。時間片輪轉的方式…

Determining Which Version of GDS is Installed

Determining Which Version of GDS is Installed To determine which version of GDS you have, run the following command: $ gdscheck.py -v Example output: GDS release version: 1.0.0.78 nvidia_fs version: 2.7 libcufile version: 2.4

冒泡排序和直接選擇排序(C/C++實現)

文章目錄 冒泡排序(交換排序&#xff09;基本思想特性總結代碼實現 直接選擇排序基本思想特性總結代碼實現&#xff08;優化&#xff0c;每次循環同時選擇最小和最大的數&#xff09; 冒泡排序(交換排序&#xff09; 基本思想 基本思想&#xff1a;所謂交換&#xff0c;就是根…

class065 A星、Floyd、Bellman-Ford與SPFA【算法】

class065 A星、Floyd、Bellman-Ford與SPFA【算法】 2023-12-9 19:27:02 算法講解065【必備】A星、Floyd、Bellman-Ford與SPFA code1 A*算法模版 // A*算法模版&#xff08;對數器驗證&#xff09; package class065;import java.util.PriorityQueue;// A*算法模版&#xff…

vue3+TypeScript全局事件總線mitt

在vue3中 $ on&#xff0c;$off 和 $once 實例方法已被移除&#xff0c;組件實例不再實現事件觸發接口&#xff0c;因此大家熟悉的EventBus便無法使用了。然而我們習慣了使用EventBus&#xff0c;對于這種情況我們可以使用Mitt庫 npm i mitt -S 首先要在全局掛載 mitt 在app…

兩年外包生涯做完,感覺自己廢了一半。。。。。

先說一下自己的情況&#xff0c;本科生&#xff0c;19年通過校招進入南京某軟件公司&#xff0c;干了接近2年的功能測試&#xff0c;今年年初&#xff0c;感覺自己不能夠在這樣下去了&#xff0c;長時間呆在一個舒適的環境會讓一個人墮落!而我已經在一個企業干了2年的功能測試&…

laravel的ORM 對象關系映射

Laravel 中的 ORM&#xff08;Eloquent ORM&#xff09;是 Laravel 框架內置的一種對象關系映射系統&#xff0c;用于在 PHP 應用中與數據庫進行交互。Eloquent 提供了一種優雅而直觀的語法&#xff0c;使得開發者可以使用面向對象的方式進行數據庫查詢和操作。 定義模型&…

結合ColorUI組件開發微信小程序

1.自定義組件生命周期函數&#xff1a; Component({data: {},attached() {console.log("自定義組件生命周期函數 attached--先執行");this.getPos();},ready() {console.log("ready生命周期函數---在attached之后執行")},methods: {getPos() {var that th…

數據結構:位圖、布隆過濾器以及海量數據面試題

位圖、布隆過濾器以及海量數據面試題 1.位圖1.1概念1.2實現1.3位圖應用 2.布隆過濾器2.1布隆過濾器的提出2.2布隆過濾器的概念2.3布隆過濾器的查找2.4布隆過濾器的實現2.5布隆過濾器的刪除2.6布隆過濾器的優點2.7布隆過濾器的缺點 3.海量數據面試題3.1哈希切分3.2位圖應用3.3布…

如何成為前1%的程序員

如果你想成為前1%的程序員&#xff0c;你必須遵循1%的程序員做什么&#xff0c;了解其他99%的人不做什么。在現代&#xff0c;我們有各種學習平臺&#xff0c;里面充滿了與編程相關的視頻、圖文以及其他資料。 舉例來說&#xff0c;我作為編程的初學者&#xff0c;去尋找路線圖…

IDEA2023找不到add framework support怎么解決

問題: 我的idea版本是2023.01&#xff0c;新版idea右鍵項目沒有Add Framework Support&#xff0c;help里面也找不到相關的。 從project structue的facets里面添加就行了&#xff0c;都是一樣的。 1.依舊是新建一個項目 2.file-->project structure--->facets 左上角加…

數據結構與程序的關系

在計算機科學中,數據結構和算法是兩個核心的概念。數據結構是程序的基礎,它組織和存儲數據的方式直接影響程序的設計、效率、可讀性以及程序的錯誤檢測和調試。本文將詳細討論數據結構如何影響程序,以及數據結構與算法的組合如何使程序更高效、可靠。 一、數據結構的選擇影…

Android studio如何安裝ai輔助工具

引言 在沒有翻墻的情況下&#xff0c;即單純在公司打工&#xff0c;經測試&#xff0c;大部分ai工具都是使用不了的&#xff08;比如各種gpt,codeium,copilot&#xff09;&#xff0c;根本登錄不了賬號&#xff0c;但有一個國內的codegeex是可以使用的&#xff0c;在這里不對各…

tensorflow中張量tensor

在 TensorFlow 中&#xff0c;主要操作的對象是張量&#xff08;tf.Tensor&#xff09;。張量表示一個多維數組&#xff0c;可以執行各種操作以構建和修改計算圖。以下是一些常見的 TensorFlow 張量操作&#xff1a; 1. 創建張量&#xff1a; 使用 tf.constant 創建常量張量。…

Android app性能優化指南

Android應用性能優化指南 提高應用程序的性能以實現更流暢的用戶體驗和更高的可見度。 性能在任何應用程序的成功中發揮著重要的作用。為用戶提供流暢無縫的體驗應該是開發人員的重點。 應用程序大小 在用戶開始使用我們的應用程序之前&#xff0c;他們需要下載應用程序并將…

DTCC2023大會-DBdoctor-基于eBPF觀測數據庫-附所有PPT下載鏈接

DTCC2023大會-DBdoctor-基于eBPF觀測數據庫-附所有PPT下載鏈接 8月16日—18日,第14屆中國數據庫技術大會(DTCC-2023)在北京國際會議中心舉行。聚好看在大會上首次發布基于eBPF觀測數據庫性能的產品DBdoctor&#xff0c;受到了業界廣泛的關注。近期幾位業內同仁過來要大會的PPT…

2024考研數學二備考歷程

GoodNotesGoodNotes apphttps://share.goodnotes.com/s/bhsraJMZ6OJwuYJb3OWnzP

Python點云處理(二十)點云輪廓邊界提取——基于鄰域三角形距離算法

目錄 0 簡述1 點云輪廓提取原理2 點云輪廓提取應用3 算法步驟4 代碼實現5 結果展示0 簡述 點云輪廓提取/邊界提取,對于掃描物信息化提取、矢量化等都具有很重要的意義。掃描物體輪廓不僅包含位置和形狀信息,而且可作為一種先驗形狀信息推斷其結構以輔助三維模型重建,因此輪…

C/C++之輸入輸出

文章目錄 一.C語言的輸入輸出1.printfi. 輸出整數ii. 浮點數iii.字符 & 字符串 2.scanfi.整數ii.浮點數iii. 字符 & 字符串 3.特殊用法i. * 的應用ii. %n 的應用iii. %[] 的應用 二.C中的輸入輸出1.couti. 緩沖區&#xff08;buffer&#xff09;ii. cout之格式化輸出 2…