You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
fix(map): patch Popup.prototype instead of the maplibre namespace (#1509)
Globe popup occlusion was installed by replacing `maplibregl.Popup` with a
subclass. That relies on the namespace being a mutable object, which is only
true of MapLibre v5's CJS/UMD default export. A v6 ESM module namespace is
sealed, so the assignment throws at map construction:
TypeError: Cannot assign to property 'Popup' of [object Module]
and the map canvas never mounts (#1489, blocker 3).
Patch `Popup.prototype.addTo` instead. The namespace binding is frozen but the
`Popup` class it exposes is an ordinary mutable object, and `addTo` is the one
prototype method every popup passes through on its way onto a map
(`Marker#togglePopup` routes through it too). The wrap runs before MapLibre's
own `_update()`/`_updateOpacity()`, so the first painted frame is correct.
`_updateOpacity` is assigned as an instance arrow inside the Popup constructor,
so it shadows the prototype and still has to be wrapped per instance.
This keeps the behavior identical and widens coverage, since the namespace swap
never reached:
- plugins that `import { Popup } from "maplibre-gl"` by name and call
`new Popup()` — `maplibre-gl-raster` and our own reverse-geocode plugin both
do, so their popups had no occlusion at all
- popups or `extends maplibregl.Popup` subclasses created before install ran
Also fix a second v6 break in the same file that fails silently. v6 stopped
having `Map extend Camera`, so `map.transform` is gone and its own Popup reads
`_map._camera.transform`. The occlusion mirror read `_map.transform`, which is
`undefined` under v6 — optional-chained, so no error, the check just never runs
and back-of-globe popups stay visible. Both locations are now resolved in one
documented helper.
Verified against real maplibre-gl 5.24.0 and 6.0.0 module objects, and in a
browser on the running app: a popup at [180, 0] with the camera at [0, 0] under
the globe projection is hidden and restores when the globe is rotated to face
it.
0 commit comments