Fix the levels viewer: markers were drawn on whichever plan was showing
This commit is contained in:
@@ -437,8 +437,18 @@ function renderMarkers() {
|
||||
overlayLayers.forEach(layer => layer.remove())
|
||||
overlayLayers = []
|
||||
|
||||
// Markers belong to ONE level (ADR-017). This is the drawing being shown, and
|
||||
// anything positioned against a different one is not drawn on it.
|
||||
const drawnLevel = drawnLevelId() ?? null
|
||||
|
||||
props.machines.forEach(item => {
|
||||
if (item.mapx == null || item.mapy == null) return
|
||||
// A marker from another level, placed on THIS blueprint, looks entirely
|
||||
// correct and points at the wrong part of the building - so it is omitted
|
||||
// rather than approximated. A position with no level at all is omitted for
|
||||
// the same reason: the map editor lists both, badged, so they can be fixed
|
||||
// rather than silently misplaced here.
|
||||
if ((item.levelid ?? null) !== drawnLevel) return
|
||||
|
||||
// Transform coordinates (database Y is top-down, Leaflet is bottom-up)
|
||||
const leafletY = MAP_HEIGHT - item.mapy
|
||||
@@ -599,6 +609,31 @@ watch(() => props.theme, (newTheme) => {
|
||||
}
|
||||
})
|
||||
|
||||
// Switching level changes the drawing, the coordinate space AND which markers
|
||||
// belong on it. All three move together: the size is what marker coordinates
|
||||
// mean, so swapping the image without the bounds would place every marker
|
||||
// against the wrong scale, and keeping the markers would show the previous
|
||||
// floor's assets on this floor's plan.
|
||||
watch(() => drawnLevelId(), (levelid) => {
|
||||
if (!map || !imageOverlay) return
|
||||
|
||||
MAP_WIDTH = dimensionsFor(levelid).width
|
||||
MAP_HEIGHT = dimensionsFor(levelid).height
|
||||
const bounds = [[0, 0], [MAP_HEIGHT, MAP_WIDTH]]
|
||||
|
||||
const url = blueprintUrlFor(props.theme, levelid)
|
||||
// A level with no blueprint is left blank rather than showing the previous
|
||||
// one, which would be a floor plan labelled as somewhere it is not.
|
||||
imageOverlay.setUrl(url || '')
|
||||
imageOverlay.setBounds(bounds)
|
||||
|
||||
map.setMaxBounds(bounds)
|
||||
map.setView([MAP_HEIGHT / 2, MAP_WIDTH / 2], map.getZoom())
|
||||
|
||||
renderMarkers()
|
||||
loadOverlays()
|
||||
})
|
||||
|
||||
onMounted(async () => {
|
||||
// Load this facility's blueprint + dimensions before building the map so
|
||||
// bounds and coordinate math use the right size. Falls back to defaults.
|
||||
|
||||
Reference in New Issue
Block a user