Fix source popup closing immediately after opening
Problem: Source markers were being recreated on every WebSocket update (every second), which destroyed any open popups. Solution: Modified updateSourceMarkers() to: - Only remove markers for sources that no longer exist - Update existing markers in-place instead of recreating them - Preserve open popups by updating content instead of recreating markers - Only create new markers when sources are actually added This ensures that clicking on a source marker opens a popup that stays open for user interaction, similar to aircraft popups. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
parent
da1b181666
commit
5a4f9e2e20
1 changed files with 41 additions and 18 deletions
|
|
@ -333,27 +333,50 @@ class SkyView {
|
|||
}
|
||||
|
||||
updateSourceMarkers() {
|
||||
// Clear existing source markers
|
||||
this.sourceMarkers.forEach(marker => this.map.removeLayer(marker));
|
||||
this.sourceMarkers.clear();
|
||||
// Remove markers for sources that no longer exist
|
||||
const currentSourceIds = new Set(this.sourcesData.keys());
|
||||
for (const [id, marker] of this.sourceMarkers) {
|
||||
if (!currentSourceIds.has(id)) {
|
||||
this.map.removeLayer(marker);
|
||||
this.sourceMarkers.delete(id);
|
||||
}
|
||||
}
|
||||
|
||||
// Add source markers
|
||||
// Update or create markers for current sources
|
||||
for (const [id, source] of this.sourcesData) {
|
||||
if (source.latitude && source.longitude) {
|
||||
const marker = L.circleMarker([source.latitude, source.longitude], {
|
||||
radius: source.active ? 10 : 6,
|
||||
fillColor: source.active ? '#00d4ff' : '#666666',
|
||||
color: '#ffffff',
|
||||
weight: 2,
|
||||
fillOpacity: 0.8,
|
||||
className: 'source-marker'
|
||||
}).addTo(this.map);
|
||||
if (this.sourceMarkers.has(id)) {
|
||||
// Update existing marker
|
||||
const marker = this.sourceMarkers.get(id);
|
||||
|
||||
marker.bindPopup(this.createSourcePopupContent(source), {
|
||||
maxWidth: 300
|
||||
});
|
||||
// Update marker style if status changed
|
||||
marker.setStyle({
|
||||
radius: source.active ? 10 : 6,
|
||||
fillColor: source.active ? '#00d4ff' : '#666666',
|
||||
fillOpacity: 0.8
|
||||
});
|
||||
|
||||
this.sourceMarkers.set(id, marker);
|
||||
// Update popup content if it's open
|
||||
if (marker.isPopupOpen()) {
|
||||
marker.setPopupContent(this.createSourcePopupContent(source));
|
||||
}
|
||||
} else {
|
||||
// Create new marker
|
||||
const marker = L.circleMarker([source.latitude, source.longitude], {
|
||||
radius: source.active ? 10 : 6,
|
||||
fillColor: source.active ? '#00d4ff' : '#666666',
|
||||
color: '#ffffff',
|
||||
weight: 2,
|
||||
fillOpacity: 0.8,
|
||||
className: 'source-marker'
|
||||
}).addTo(this.map);
|
||||
|
||||
marker.bindPopup(this.createSourcePopupContent(source), {
|
||||
maxWidth: 300
|
||||
});
|
||||
|
||||
this.sourceMarkers.set(id, marker);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue