From acad9c59448953376f5c2e6580e0926a3a67e0b7 Mon Sep 17 00:00:00 2001 From: Chandler Swift Date: Fri, 2 Feb 2024 21:46:21 -0600 Subject: [PATCH] Clean up HLS stream Without this, it will continue loading chunks in the background. --- layers/dot-cams/index.js | 1 + main.js | 15 +++++++++------ 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/layers/dot-cams/index.js b/layers/dot-cams/index.js index 166d5b5..1d5ee46 100644 --- a/layers/dot-cams/index.js +++ b/layers/dot-cams/index.js @@ -62,6 +62,7 @@ for (let [state, url] of Object.entries(allStates)) { var hls = new Hls(); hls.loadSource(view.src); hls.attachMedia(video); + vectorLayer.destroyPopupCallback = () => hls.destroy(); } // iDevice support, untested (only works in Safari; required for iPhones) else if (video.canPlayType('application/vnd.apple.mpegurl')) { diff --git a/main.js b/main.js index 24f87ab..73fc3f4 100644 --- a/main.js +++ b/main.js @@ -23,12 +23,6 @@ const popupOverlay = new Overlay({ }, }); -closer.onclick = function () { - popupOverlay.setPosition(undefined); - closer.blur(); - return false; -}; - const contextMenu = new ContextMenu({ width: 170, defaultItems: false, @@ -147,6 +141,15 @@ map.on('click', function (evt) { } popupOverlay.setPosition(evt.coordinate); + + closer.onclick = function (){ + popupOverlay.setPosition(undefined); + if (layer.hasOwnProperty('destroyPopupCallback')) { + layer.destroyPopupCallback(feature); + } + closer.blur(); + return false; + }; }); new ResizeObserver(() => map.updateSize()).observe(document.getElementById("map"));