@sigma/layer-maplibre 3.0.0-beta.8 → 3.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -79,12 +79,11 @@ function graphToLatlng(map, coords) {
79
79
  * BBOX sync : map to sigma
80
80
  */
81
81
  function syncSigmaWithMap(sigma, map) {
82
- var mapBound = map.getBounds();
83
-
84
82
  // Compute sigma center
85
- var center = sigma.viewportToFramedGraph(sigma.graphToViewport(latlngToGraph(map, mapBound.getCenter())));
83
+ var center = sigma.viewportToFramedGraph(sigma.graphToViewport(latlngToGraph(map, map.getCenter())));
86
84
 
87
85
  // Compute sigma ratio
86
+ var mapBound = map.getBounds();
88
87
  var northEast = sigma.graphToViewport(latlngToGraph(map, mapBound.getNorthEast()));
89
88
  var southWest = sigma.graphToViewport(latlngToGraph(map, mapBound.getSouthWest()));
90
89
  var viewportBoundDimension = {
@@ -142,7 +141,8 @@ function bindMaplibreLayer(sigma, opts) {
142
141
  var prevSigmaSettings = sigma.getSettings();
143
142
 
144
143
  // Creating map container
145
- var mapContainer = sigma.createLayer("layer-leaflet", "div", {
144
+ var mapLayerName = "layer-maplibre";
145
+ var mapContainer = sigma.createLayer(mapLayerName, "div", {
146
146
  style: {
147
147
  position: "absolute",
148
148
  inset: "0"
@@ -210,8 +210,29 @@ function bindMaplibreLayer(sigma, opts) {
210
210
  // When sigma is resize, we need to update the graph coordinate (the ref has changed)
211
211
  // and recompute the zoom bounds
212
212
  function fnOnResize() {
213
- updateGraphCoordinates(sigma.getGraph());
214
- fnSyncSigmaWithMap();
213
+ // Avoid sync map with sigma while we do the resize
214
+ // otherwise there is a sideeffect...
215
+ sigma.off("afterRender", fnSyncMapWithSigma);
216
+ var center = map.getCenter();
217
+
218
+ // Ask the map to resize
219
+ map.once("resize", function () {
220
+ // NB: resize can change the center of the map, and we want to keep it
221
+ map.setCenter(center);
222
+
223
+ // Map ref has changed, we need to update the graph coordinates
224
+ updateGraphCoordinates(sigma.getGraph());
225
+
226
+ // Do the sync
227
+ fnSyncSigmaWithMap();
228
+
229
+ // Re-enable the map sync with sigma in the next frame
230
+ setTimeout(function () {
231
+ fnSyncMapWithSigma();
232
+ sigma.on("afterRender", fnSyncMapWithSigma);
233
+ }, 0);
234
+ });
235
+ map.resize();
215
236
  }
216
237
 
217
238
  // Clean up function to remove everything
@@ -220,7 +241,7 @@ function bindMaplibreLayer(sigma, opts) {
220
241
  isKilled = true;
221
242
  map.off("moveend", fnSyncSigmaWithMap);
222
243
  map.remove();
223
- mapContainer.remove();
244
+ sigma.killLayer(mapLayerName);
224
245
  sigma.off("afterRender", fnSyncMapWithSigma);
225
246
  sigma.off("resize", fnOnResize);
226
247
 
@@ -79,12 +79,11 @@ function graphToLatlng(map, coords) {
79
79
  * BBOX sync : map to sigma
80
80
  */
81
81
  function syncSigmaWithMap(sigma, map) {
82
- var mapBound = map.getBounds();
83
-
84
82
  // Compute sigma center
85
- var center = sigma.viewportToFramedGraph(sigma.graphToViewport(latlngToGraph(map, mapBound.getCenter())));
83
+ var center = sigma.viewportToFramedGraph(sigma.graphToViewport(latlngToGraph(map, map.getCenter())));
86
84
 
87
85
  // Compute sigma ratio
86
+ var mapBound = map.getBounds();
88
87
  var northEast = sigma.graphToViewport(latlngToGraph(map, mapBound.getNorthEast()));
89
88
  var southWest = sigma.graphToViewport(latlngToGraph(map, mapBound.getSouthWest()));
90
89
  var viewportBoundDimension = {
@@ -142,7 +141,8 @@ function bindMaplibreLayer(sigma, opts) {
142
141
  var prevSigmaSettings = sigma.getSettings();
143
142
 
144
143
  // Creating map container
145
- var mapContainer = sigma.createLayer("layer-leaflet", "div", {
144
+ var mapLayerName = "layer-maplibre";
145
+ var mapContainer = sigma.createLayer(mapLayerName, "div", {
146
146
  style: {
147
147
  position: "absolute",
148
148
  inset: "0"
@@ -210,8 +210,29 @@ function bindMaplibreLayer(sigma, opts) {
210
210
  // When sigma is resize, we need to update the graph coordinate (the ref has changed)
211
211
  // and recompute the zoom bounds
212
212
  function fnOnResize() {
213
- updateGraphCoordinates(sigma.getGraph());
214
- fnSyncSigmaWithMap();
213
+ // Avoid sync map with sigma while we do the resize
214
+ // otherwise there is a sideeffect...
215
+ sigma.off("afterRender", fnSyncMapWithSigma);
216
+ var center = map.getCenter();
217
+
218
+ // Ask the map to resize
219
+ map.once("resize", function () {
220
+ // NB: resize can change the center of the map, and we want to keep it
221
+ map.setCenter(center);
222
+
223
+ // Map ref has changed, we need to update the graph coordinates
224
+ updateGraphCoordinates(sigma.getGraph());
225
+
226
+ // Do the sync
227
+ fnSyncSigmaWithMap();
228
+
229
+ // Re-enable the map sync with sigma in the next frame
230
+ setTimeout(function () {
231
+ fnSyncMapWithSigma();
232
+ sigma.on("afterRender", fnSyncMapWithSigma);
233
+ }, 0);
234
+ });
235
+ map.resize();
215
236
  }
216
237
 
217
238
  // Clean up function to remove everything
@@ -220,7 +241,7 @@ function bindMaplibreLayer(sigma, opts) {
220
241
  isKilled = true;
221
242
  map.off("moveend", fnSyncSigmaWithMap);
222
243
  map.remove();
223
- mapContainer.remove();
244
+ sigma.killLayer(mapLayerName);
224
245
  sigma.off("afterRender", fnSyncMapWithSigma);
225
246
  sigma.off("resize", fnOnResize);
226
247
 
@@ -75,12 +75,11 @@ function graphToLatlng(map, coords) {
75
75
  * BBOX sync : map to sigma
76
76
  */
77
77
  function syncSigmaWithMap(sigma, map) {
78
- var mapBound = map.getBounds();
79
-
80
78
  // Compute sigma center
81
- var center = sigma.viewportToFramedGraph(sigma.graphToViewport(latlngToGraph(map, mapBound.getCenter())));
79
+ var center = sigma.viewportToFramedGraph(sigma.graphToViewport(latlngToGraph(map, map.getCenter())));
82
80
 
83
81
  // Compute sigma ratio
82
+ var mapBound = map.getBounds();
84
83
  var northEast = sigma.graphToViewport(latlngToGraph(map, mapBound.getNorthEast()));
85
84
  var southWest = sigma.graphToViewport(latlngToGraph(map, mapBound.getSouthWest()));
86
85
  var viewportBoundDimension = {
@@ -138,7 +137,8 @@ function bindMaplibreLayer(sigma, opts) {
138
137
  var prevSigmaSettings = sigma.getSettings();
139
138
 
140
139
  // Creating map container
141
- var mapContainer = sigma.createLayer("layer-leaflet", "div", {
140
+ var mapLayerName = "layer-maplibre";
141
+ var mapContainer = sigma.createLayer(mapLayerName, "div", {
142
142
  style: {
143
143
  position: "absolute",
144
144
  inset: "0"
@@ -206,8 +206,29 @@ function bindMaplibreLayer(sigma, opts) {
206
206
  // When sigma is resize, we need to update the graph coordinate (the ref has changed)
207
207
  // and recompute the zoom bounds
208
208
  function fnOnResize() {
209
- updateGraphCoordinates(sigma.getGraph());
210
- fnSyncSigmaWithMap();
209
+ // Avoid sync map with sigma while we do the resize
210
+ // otherwise there is a sideeffect...
211
+ sigma.off("afterRender", fnSyncMapWithSigma);
212
+ var center = map.getCenter();
213
+
214
+ // Ask the map to resize
215
+ map.once("resize", function () {
216
+ // NB: resize can change the center of the map, and we want to keep it
217
+ map.setCenter(center);
218
+
219
+ // Map ref has changed, we need to update the graph coordinates
220
+ updateGraphCoordinates(sigma.getGraph());
221
+
222
+ // Do the sync
223
+ fnSyncSigmaWithMap();
224
+
225
+ // Re-enable the map sync with sigma in the next frame
226
+ setTimeout(function () {
227
+ fnSyncMapWithSigma();
228
+ sigma.on("afterRender", fnSyncMapWithSigma);
229
+ }, 0);
230
+ });
231
+ map.resize();
211
232
  }
212
233
 
213
234
  // Clean up function to remove everything
@@ -216,7 +237,7 @@ function bindMaplibreLayer(sigma, opts) {
216
237
  isKilled = true;
217
238
  map.off("moveend", fnSyncSigmaWithMap);
218
239
  map.remove();
219
- mapContainer.remove();
240
+ sigma.killLayer(mapLayerName);
220
241
  sigma.off("afterRender", fnSyncMapWithSigma);
221
242
  sigma.off("resize", fnOnResize);
222
243
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sigma/layer-maplibre",
3
- "version": "3.0.0-beta.8",
3
+ "version": "3.0.0",
4
4
  "description": "A plugin to set a geographical map in background",
5
5
  "main": "dist/sigma-layer-maplibre.cjs.js",
6
6
  "module": "dist/sigma-layer-maplibre.esm.js",
@@ -45,5 +45,5 @@
45
45
  },
46
46
  "./package.json": "./package.json"
47
47
  },
48
- "gitHead": "8edd2ee8dad222bac99439feed321d55896bb61e"
48
+ "gitHead": "f0187cb13da41310bf375caf7105db2f18bc89d2"
49
49
  }