fix: close stale map info windows
This commit is contained in:
@@ -56,6 +56,7 @@ const PROVINCE_BY_PLATE_PREFIX = {
|
||||
|
||||
let map = null;
|
||||
let markerList = [];
|
||||
let infoWindowList = [];
|
||||
let is3DPitch = true;
|
||||
let currentMode = 'vehicle';
|
||||
let currentTheme = 'theme-white';
|
||||
@@ -239,6 +240,7 @@ function stationNodes() {
|
||||
function renderAMapMarkers() {
|
||||
if (!map || !dashboard) return;
|
||||
markerList.forEach(marker => marker.remove()); markerList = [];
|
||||
infoWindowList.forEach(infoWindow => infoWindow.close()); infoWindowList = [];
|
||||
const nodes = currentMode === 'vehicle' ? vehicleNodes() : stationNodes();
|
||||
const dict = i18n[currentLang];
|
||||
for (const node of nodes) {
|
||||
@@ -253,6 +255,7 @@ function renderAMapMarkers() {
|
||||
content: `<div class="map-info-window"><strong>${escapeHTML(node.name)}</strong><div>${escapeHTML(node.detail || '')}</div>${isVehicleNode ? `<div>${dict.onlineText}: ${node.online}/${node.count} · ${formatNumber(node.dist, 1)} km</div>` : ''}</div>`,
|
||||
offset: new AMap.Pixel(0, -32)
|
||||
});
|
||||
infoWindowList.push(infoWindow);
|
||||
marker.on('mouseover', () => infoWindow.open(map, node.lnglat));
|
||||
marker.on('mouseout', () => infoWindow.close());
|
||||
if (node.kind === 'vehicleProvince') marker.on('click', () => map.setZoomAndCenter(7.2, node.lnglat));
|
||||
|
||||
Reference in New Issue
Block a user