fix: canvas回map内+position:relative避免错位
_ensureFlowLayer: canvas作为#saMap子元素, position:absolute;top:0;left:0, resize事件同步尺寸 不再需要在map外部计算偏移 Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -2759,32 +2759,19 @@ let _trafficCanvasCtx = null;
|
||||
|
||||
function _ensureFlowLayer() {
|
||||
if (!SA.map) return null;
|
||||
if (_trafficFlowLayer) return _trafficFlowLayer;
|
||||
// Insert canvas AFTER map container, positioned to cover the map
|
||||
if (_trafficFlowLayer && _trafficFlowLayer.parentNode) return _trafficFlowLayer;
|
||||
const mapEl = SA.map.getContainer();
|
||||
const c = document.createElement('canvas');
|
||||
c.id = 'saTrafficCanvasOverlay';
|
||||
c.style.cssText = 'position:absolute; top:0; left:0; pointer-events:none; z-index:99999;';
|
||||
// Insert after map container in DOM
|
||||
mapEl.parentNode.insertBefore(c, mapEl.nextSibling);
|
||||
// Size to match map
|
||||
c.style.cssText = 'position:absolute;top:0;left:0;pointer-events:none;z-index:10000;';
|
||||
mapEl.appendChild(c);
|
||||
const size = SA.map.getSize();
|
||||
c.width = size.x; c.height = size.y;
|
||||
c.style.width = size.x + 'px'; c.style.height = size.y + 'px';
|
||||
// Position overlay over map
|
||||
const mapRect = mapEl.getBoundingClientRect();
|
||||
const parentRect = mapEl.parentNode.getBoundingClientRect();
|
||||
c.style.left = (mapRect.left - parentRect.left) + 'px';
|
||||
c.style.top = (mapRect.top - parentRect.top) + 'px';
|
||||
// Update on map changes
|
||||
SA.map.on('resize move zoomend', () => {
|
||||
SA.map.on('resize', () => {
|
||||
const s = SA.map.getSize();
|
||||
c.width = s.x; c.height = s.y;
|
||||
c.style.width = s.x + 'px'; c.style.height = s.y + 'px';
|
||||
const mr = mapEl.getBoundingClientRect();
|
||||
const pr = mapEl.parentNode.getBoundingClientRect();
|
||||
c.style.left = (mr.left - pr.left) + 'px';
|
||||
c.style.top = (mr.top - pr.top) + 'px';
|
||||
});
|
||||
_trafficCanvasCtx = c.getContext('2d');
|
||||
_trafficFlowLayer = c;
|
||||
|
||||
Reference in New Issue
Block a user