2025-12-04 10:16:16 +08:00

94 lines
2.7 KiB
JavaScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

const branchData = {
name: '渤海银行合肥分行营业部',
position: { lat: 31.878989, lng: 117.277125 },
address: '合肥市庐阳区北一环濉溪路269号',
phone: '0551-65278203 0551-65278552',
hours: '工作日: 9:00-12:00 14:00-17:00'
};
// 初始化地图
const map = new TMap.Map("map-container", {
center: new TMap.LatLng(branchData.position.lat, branchData.position.lng),
zoom: 17,
mapStyleId: 'style1',
});
// 添加 Marker
const markerLayer = new TMap.MultiMarker({
map: map,
styles: {
marker: new TMap.MarkerStyle({
width: 40,
height: 40,
anchor: { x: 20, y: 20 },
src: "./img/CBHB-marker.webp"
})
},
geometries: [{
id: "marker1",
styleId: "marker",
position: new TMap.LatLng(branchData.position.lat, branchData.position.lng),
properties: {
title: branchData.name
}
}]
});
// 控件
const branchInfo = document.getElementById('branch-info');
const branchName = document.getElementById('branch-name');
const branchAddress = document.getElementById('branch-address');
const branchPhone = document.getElementById('branch-phone');
const branchHours = document.getElementById('branch-hours');
const navigateBtn = document.getElementById('navigate-btn');
const closeBtn = document.getElementById('close-btn');
// 显示信息卡
function showBranchInfo() {
branchName.textContent = branchData.name;
branchAddress.textContent = `${branchData.address}`;
branchPhone.innerHTML = branchData.phone
.split(',')
.map(num => `<a href="tel:${num.trim()}">${num.trim()}</a>`)
.join('');
branchHours.textContent = `${branchData.hours}`;
branchInfo.classList.remove('hidden');
setTimeout(() => {
branchInfo.classList.add('active');
}, 10);
}
// Marker 点击
markerLayer.on("click", showBranchInfo);
// 页面加载显示卡片
showBranchInfo();
// 微信导航跳转逻辑
navigateBtn.addEventListener('click', function (e) {
e.preventDefault();
e.stopPropagation();
const isInWeChat = typeof wx !== 'undefined' && wx.openLocation;
if (isInWeChat) {
// 微信环境:用 JS-SDK 打开导航
wx.ready(function () {
wx.openLocation({
latitude: branchData.position.lat,
longitude: branchData.position.lng,
name: branchData.name,
address: branchData.address,
scale: 17
});
});
wx.error(function (err) {
console.error("微信JS-SDK调用失败", err);
alert("微信JS-SDK调用失败请确认从微信中打开本页");
});
}
});