You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
pingAnQiYeWeb/public/static/map.html

139 lines
6.7 KiB

1 year ago
<!DOCTYPE html>
<html lang="en">
9 months ago
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
1 year ago
<title>Document</title>
<style>
9 months ago
#container {
width: 100vw;
height: 100vh;
/* border: 0.1px solid #495e70; */
}
1 year ago
9 months ago
/* 去除百度地图logo */
.anchorBL {
display: none;
}
1 year ago
</style>
1 year ago
<!-- <script src="https://unpkg.com/mapv-three@1.0.10/dist/mapvthree.umd.js"></script> -->
9 months ago
<script src="https://api.map.baidu.com/api?v=1.0&type=webgl&ak=CSfWwqFqSVkQaqcAAMxKyXg6Moe9UUqA"></script>
9 months ago
</head>
1 year ago
9 months ago
<body>
1 year ago
<div id="container"></div>
<script>
9 months ago
// 创建地图实例
var map = new BMapGL.Map("container"); // 创建地图实例
var point = new BMapGL.Point(121.619992, 30.025703); // 创建点坐标
window.addEventListener("message", function (event) {
let company_list = event.data;
//console.log('data01', company_list);
company_list.forEach((item) => {
let company_point = new BMapGL.Point(item.longitude, item.latitude);
let myIcon = {};
// 根据公司排名打点
if (item.areaRank == "1") {
myIcon = new BMapGL.Icon("./top01.png", new BMapGL.Size(40, 60), {
imageOffset: new BMapGL.Size(0, 0, 5),
9 months ago
});
9 months ago
var marker = new BMapGL.Marker(company_point, { icon: myIcon }); // 创建点位
marker.disableMassClear();
map.addOverlay(marker);
} else if (item.areaRank == "2") {
myIcon = new BMapGL.Icon("./top02.png", new BMapGL.Size(40, 60), {
imageOffset: new BMapGL.Size(0, 0, 5),
});
var marker = new BMapGL.Marker(company_point, { icon: myIcon }); // 创建点位
marker.disableMassClear();
map.addOverlay(marker);
} else if (item.areaRank == "3") {
myIcon = new BMapGL.Icon("./top03.png", new BMapGL.Size(40, 60), {
imageOffset: new BMapGL.Size(0, 0, 5),
});
var marker = new BMapGL.Marker(company_point, { icon: myIcon }); // 创建点位
marker.disableMassClear();
map.addOverlay(marker);
} else if (item.areaRank == "4") {
myIcon = new BMapGL.Icon("./top04.png", new BMapGL.Size(40, 60), {
imageOffset: new BMapGL.Size(0, 0, 5),
});
var marker = new BMapGL.Marker(company_point, { icon: myIcon }); // 创建点位
marker.disableMassClear();
map.addOverlay(marker);
} else if (item.areaRank == "5") {
myIcon = new BMapGL.Icon("./top05.png", new BMapGL.Size(40, 60), {
imageOffset: new BMapGL.Size(0, 0, 5),
});
var marker = new BMapGL.Marker(company_point, { icon: myIcon }); // 创建点位
marker.disableMassClear();
map.addOverlay(marker);
}
// 公司名
let content = item.companyName;
let label = new BMapGL.Label(content, {
position: company_point, // 设置标注的地理位置
offset: new BMapGL.Size(-20, -50), // 设置标注的偏移量
});
label.setStyle({
backgroundColor: "#f9d2e4",
border: "0",
color: "#01847f",
fontSize: "16px",
cursor: "pointer",
});
label.disableMassClear();
map.addOverlay(label);
// 文本点击
label.addEventListener("click", function () {
map.clearOverlays(); // 为保证始终只有一个文本覆盖物弹出,每次创造文本覆盖物时,先清楚所有的文本覆盖物
// 注意 clearOverlays会清除地图所有的覆盖物所以要给不想清除的覆盖物加上disableMassClear以做到禁止删除
var point_text = new BMapGL.Label(); // 创建公司详情文本覆盖物
point_text.setStyle({
color: "blue",
borderRadius: "5px",
borderColor: "#ccc",
padding: "10px",
9 months ago
fontSize: "16px",
9 months ago
fontFamily: "微软雅黑",
backgroundColor: "#b5ebff",
transform: "translateX(-50%) translateY(calc(-100% - 10px))",
});
// 点位点击转处置弹窗
point_text.setPosition(
new BMapGL.Point(item.longitude, item.latitude)
);
point_text.setOffset(new BMapGL.Size(130, -10));
point_text.setStyle({
width: "340px",
height: "238px",
background: "url(../pbImg/dialogback.png) no-repeat",
backgroundSize: "100% 100%",
border: "0",
color: "#fff",
zIndex: 2000000000,
9 months ago
});
9 months ago
point_text.setContent(`
9 months ago
<div style='width:100%;display:flex;justify-content: space-between;align-items: center;'>
<h4 style='margin:12px;font-size: 14px;color: #FFE6D9;overflow: hidden;text-overflow: ellipsis;white-space: nowrap; cursor: pointer;'>${item.companyName}</h4>
<div class='closeBtn' style='background: url(../pbImg/close.png) no-repeat;width:20px;height:20px;background-size: 100% 100%;margin-right:10px; cursor: pointer;"'></div></div>
<div style='margin:0 auto;font-size: 14px;width:316px;height:108px;padding:0 12px;background: rgba(108,128,151,0.20);border: 1px solid rgba(73,84,97,1);'>
<h4 style='height:33%;opacity: 0.8;margin:0;line-height:38px;font-weight:300;'><span style="color:#D0DEEE;overflow: hidden;text-overflow: ellipsis;white-space: nowrap;">单位地址:</span>${item.companyAddress}</h4>
<div title="${item.levelIndexThree}" style='height:33%;opacity: 0.8;margin:0;line-height:38px;font-weight:300;overflow:hidden; text-overflow: ellipsis;white-space: nowrap'><span style="color:#D0DEEE;">安全负责人:</span>${item.emergencyContact}</div>
<h4 style='height:33%;opacity: 0.8;margin:0;line-height:38px;font-weight:300;'><span style="color:#D0DEEE;overflow: hidden;text-overflow: ellipsis;white-space: nowrap;">综合得分:</span>${item.score}</h4>
`);
9 months ago
map.addOverlay(point_text);
let closebtn = document.querySelector(".closeBtn");
closebtn.addEventListener("click", () => {
map.removeOverlay(point_text);
9 months ago
});
});
});
9 months ago
});
map.centerAndZoom(point, 14); // 初始化地图,设置中心点坐标和地图级别
map.enableScrollWheelZoom();
map.setMapType(BMAP_SATELLITE_MAP); // 卫星地图模式
9 months ago
</script>
</body>
</html>