@sigma/layer-maplibre 3.0.0-beta.9 → 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 = {
@@ -211,8 +210,29 @@ function bindMaplibreLayer(sigma, opts) {
211
210
  // When sigma is resize, we need to update the graph coordinate (the ref has changed)
212
211
  // and recompute the zoom bounds
213
212
  function fnOnResize() {
214
- updateGraphCoordinates(sigma.getGraph());
215
- 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();
216
236
  }
217
237
 
218
238
  // Clean up function to remove everything
@@ -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 = {
@@ -211,8 +210,29 @@ function bindMaplibreLayer(sigma, opts) {
211
210
  // When sigma is resize, we need to update the graph coordinate (the ref has changed)
212
211
  // and recompute the zoom bounds
213
212
  function fnOnResize() {
214
- updateGraphCoordinates(sigma.getGraph());
215
- 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();
216
236
  }
217
237
 
218
238
  // Clean up function to remove everything
@@ -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 = {
@@ -207,8 +206,29 @@ function bindMaplibreLayer(sigma, opts) {
207
206
  // When sigma is resize, we need to update the graph coordinate (the ref has changed)
208
207
  // and recompute the zoom bounds
209
208
  function fnOnResize() {
210
- updateGraphCoordinates(sigma.getGraph());
211
- 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();
212
232
  }
213
233
 
214
234
  // Clean up function to remove everything
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sigma/layer-maplibre",
3
- "version": "3.0.0-beta.9",
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": "fc828dcb6e14282f323f2f1c62987444f9cf0c6f"
48
+ "gitHead": "f0187cb13da41310bf375caf7105db2f18bc89d2"
49
49
  }