From f19e5267cc23b1c714dc746239864f33ed715dd9 Mon Sep 17 00:00:00 2001
From: riku <risaku@163.com>
Date: 星期五, 05 十二月 2025 17:55:02 +0800
Subject: [PATCH] 完成地图制作任务功能初版
---
src/utils/map/marks.js | 44 +++++++++++++++++++++++++++++++++-----------
1 files changed, 33 insertions(+), 11 deletions(-)
diff --git a/src/utils/map/marks.js b/src/utils/map/marks.js
index a72dcdf..05137fd 100644
--- a/src/utils/map/marks.js
+++ b/src/utils/map/marks.js
@@ -2,7 +2,7 @@
* 楂樺痉鍦板浘鐐规爣璁扮粯鍒剁浉鍏�
*/
-import { map } from './index_old';
+import { map, AMap } from './index';
import { useToolboxStore } from '@/stores/toolbox';
const toolboxStore = useToolboxStore();
@@ -25,7 +25,7 @@
for (let i = 0; i < lnglats.length; i++) {
data.push({
lnglat: lnglats[i], //鐐规爣璁颁綅缃�
- name: `${fDatas.times[i]}<br/>${_factor.factorName}: ${_factor.datas[i].factorData} mg/m鲁`,
+ name: `${fDatas.times[i]}<br/>${_factor.factorName}: ${_factor.datas[i].factorData} 渭g/m鲁`,
id: i
});
}
@@ -34,12 +34,12 @@
var styleObject = {
url: 'https://a.amap.com/jsapi_demos/static/images/mass1.png',
// url: './asset/mipmap/ic_up_white.png', // 鍥炬爣鍦板潃
- // eslint-disable-next-line no-undef
+
size: new AMap.Size(11, 11), // 鍥炬爣澶у皬
- // eslint-disable-next-line no-undef
+
anchor: new AMap.Pixel(5, 5) // 鍥炬爣鏄剧ず浣嶇疆鍋忕Щ閲忥紝鍩哄噯鐐逛负鍥炬爣宸︿笂瑙�
};
- // eslint-disable-next-line no-undef
+
var massMarks = new AMap.MassMarks(data, {
zIndex: 5, // 娴烽噺鐐瑰浘灞傚彔鍔犵殑椤哄簭
zooms: [15, 18], // 鍦ㄦ寚瀹氬湴鍥剧缉鏀剧骇鍒寖鍥村唴灞曠ず娴烽噺鐐瑰浘灞�
@@ -50,11 +50,11 @@
// 3. 鑷畾涔夌偣鍑讳簨浠�
onClick(i);
});
- // eslint-disable-next-line no-undef
+
var marker = new AMap.Marker({
content: ' ',
map: map,
- // eslint-disable-next-line no-undef
+
offset: new AMap.Pixel(13, 12)
});
var timeout;
@@ -86,8 +86,7 @@
* @param {boolean} collision 鏍囨敞閬胯
* @returns
*/
- createLabelMarks(img, dataList, collision = true) {
- // eslint-disable-next-line no-undef
+ createLabelMarks(img, dataList, collision = true, showTxt = true) {
const layer = new AMap.LabelsLayer({
zooms: [3, 20],
zIndex: 1000,
@@ -119,7 +118,7 @@
retina: true
},
text: {
- content: data.name,
+ content: showTxt ? data.name : '',
direction: 'top',
offset: [0, -5],
style: {
@@ -136,7 +135,6 @@
index: i
};
- // eslint-disable-next-line no-undef
var labelMarker = new AMap.LabelMarker(curData);
// markers.push(labelMarker);
@@ -145,5 +143,29 @@
}
return layer;
+ },
+
+ createMarker({ position, img, title, content, label = '', extData }) {
+ //鍒涘缓 AMap.Icon 瀹炰緥锛�
+ const icon = new AMap.Icon({
+ size: new AMap.Size(30, 30), //鍥炬爣灏哄
+ image: img, //Icon 鐨勫浘鍍�
+ // imageOffset: new AMap.Pixel(-9, -3), //鍥惧儚鐩稿灞曠ず鍖哄煙鐨勫亸绉婚噺锛岄�備簬闆ⅶ鍥剧瓑
+ imageSize: new AMap.Size(30, 30) //鏍规嵁鎵�璁剧疆鐨勫ぇ灏忔媺浼告垨鍘嬬缉鍥剧墖
+ });
+ const marker = new AMap.Marker({
+ position: position,
+ // offset: new AMap.Pixel(-13, -30),
+ icon: icon, //娣诲姞 icon 鍥炬爣 URL
+ content: content,
+ title: title,
+ label: {
+ content: label,
+ direction: 'bottom'
+ },
+ extData
+ });
+ // map.add(marker);
+ return marker;
}
};
--
Gitblit v1.9.3