fix(html-layer): keep HTML overlays aligned when the viewer container has an offset - #223
fix(html-layer): keep HTML overlays aligned when the viewer container has an offset#223FenjuFu wants to merge 1 commit into
Conversation
… has an offset HtmlLayer positioned DOM overlays by adding viewer.getOffset() (the container's viewport rect) to the canvas-relative coordinates returned by Cesium.SceneTransforms.worldToWindowCoordinates(). When the container was not at the top-left of the page (a container with a fixed height, or nested in an iframe), this shifted every overlay by the container offset. It only looked correct for a full-screen container at viewport (0,0). - Drop the getOffset() addition in HtmlLayer; the window coordinates are already canvas-relative. - Give .viewer-layers an explicit box that overlaps the canvas so absolutely positioned overlays resolve against a canvas-aligned ancestor regardless of the outer container. pointer-events is disabled on the pane and re-enabled on its children so map interaction is preserved. Fixes dvt3d#212 Signed-off-by: FenjuFu <[email protected]>
|
Verified locally against a dc-sdk v5.0.0 build. Repro: the viewer container is placed below a 200px header, so Before (current
After (this PR): the offset addition is gone and
pointer-events: the change follows the standard overlay-pane pattern (pane |
What
Fixes #212 —
HtmlLayeroverlays drift vertically when the viewer container has an offset in the page (a container with a fixed height, or nested in an iframe). The issue does not occur in v2.x.Root cause
HtmlLayerpositions its DOM overlays fromCesium.SceneTransforms.worldToWindowCoordinates(), which already returns canvas-relative pixels. It then addsviewer.getOffset()— the container'sgetBoundingClientRect().left/top, i.e. its viewport position:The overlays are
position: absolute.div-iconelements inside.viewer-layers. When the container fills the screen at viewport(0,0),getOffset()is~{0,0}and the extra term is invisible. Once the container sits lower in the page (e.g.height: 95px),rect.topgrows and every overlay is pushed down by the container offset — the reported symptom..viewer-layersalso has no positioning of its own, so the overlays lacked a canvas-aligned positioned ancestor and thegetOffset()term was only compensating by coincidence at the origin.Change
HtmlLayer.js: drop thegetOffset()addition; the window coordinates are already canvas-relative.viewer.scss: give.viewer-layersan explicit box that overlaps the canvas so absolutely positioned overlays resolve against a canvas-aligned ancestor regardless of the outer container.pointer-eventsis disabled on the pane and re-enabled on its children so map interaction is preserved.Together these make HTML overlays independent of where the viewer container sits in the page (fixed height, nested, iframe), which is the expected behaviour described in the issue.
Verification note
This was derived from source analysis and restores the pre-v5 behaviour. I could not run a full local build to verify in a browser, so please double-check the
pointer-eventschange against the other panes mounted onlayerContainer(WindLayer,HeatMapLayer,ChartLayer) to confirm their interaction is unaffected. Happy to adjust.