Skip to content

Commit

Permalink
[layer-leaflet/maplibre] fix issue on sigma's container resizing
Browse files Browse the repository at this point in the history
When the container height/width changed (programmatically, ie not a resize event), the map layer was not updated or badly.
By creating the map's container via the sigma API and by invalidate the
map's size, the issue is fixed.
  • Loading branch information
sim51 committed Nov 19, 2024
1 parent fc0c08d commit 15b6887
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
9 changes: 6 additions & 3 deletions packages/layer-leaflet/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,11 @@ export default function bindLeafletLayer(
const prevSigmaSettings = sigma.getSettings();

// Creating map container
const mapContainer = document.createElement("div");
mapContainer.classList.add("sigma-layer-leaflet");
mapContainer.setAttribute("style", "position: absolute; inset: 0; z-index: 0");
const mapContainer = sigma.createLayer("layer-leaflet", "div", {
style: { position: "absolute", inset: "0", zIndex: "0" },
// 'edges' is the first sigma layer
beforeLayer: "edges",
});
sigma.getContainer().prepend(mapContainer);

// Initialize the map
Expand Down Expand Up @@ -104,6 +106,7 @@ export default function bindLeafletLayer(
// When sigma is resize, we need to update the graph coordinate (the ref has changed)
// and recompute the zoom bounds
function fnOnResize() {
map.invalidateSize();
updateGraphCoordinates(sigma.getGraph());
fnSyncSigmaWithMap();
setSigmaRatioBounds(sigma, map);
Expand Down
8 changes: 5 additions & 3 deletions packages/layer-maplibre/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,11 @@ export default function bindMaplibreLayer(
const prevSigmaSettings = sigma.getSettings();

// Creating map container
const mapContainer = document.createElement("div");
mapContainer.classList.add("sigma-layer-maplibre");
mapContainer.setAttribute("style", "position: absolute; inset: 0");
const mapContainer = sigma.createLayer("layer-leaflet", "div", {
style: { position: "absolute", inset: "0" },
// 'edges' is the first sigma layer
beforeLayer: "edges",
});
sigma.getContainer().prepend(mapContainer);

// Initialize the map
Expand Down

0 comments on commit 15b6887

Please sign in to comment.