@unovis/ts 1.6.5-topojson.9 → 1.6.5

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.
@@ -69,7 +69,7 @@ export declare class TopoJSONMap<AreaDatum, PointDatum = GenericDataRecord, Link
69
69
  _onZoom(event: D3ZoomEvent<SVGGElement, unknown>): void;
70
70
  _onZoomEnd(): void;
71
71
  private _runCollisionDetection;
72
- _onZoomHandler(transform: ZoomTransform, isMouseEvent: boolean, isExternalEvent: boolean): void;
72
+ _onZoomHandler(transform: ZoomTransform, isMouseEvent: boolean, isExternalEvent: boolean, isResizeEvent?: boolean): void;
73
73
  zoomIn(increment?: number): void;
74
74
  zoomOut(increment?: number): void;
75
75
  setZoom(zoomLevel: number): void;
@@ -174,10 +174,7 @@ class TopoJSONMap extends ComponentCore {
174
174
  }
175
175
  }
176
176
  _renderBackground() {
177
- renderBackground(this._backgroundRect, {
178
- bleed: { left: this.bleed.left, top: this.bleed.top },
179
- onClick: () => this._collapseExpandedCluster(),
180
- });
177
+ renderBackground(this._backgroundRect, this.bleed.left, this.bleed.top, () => this._collapseExpandedCluster());
181
178
  }
182
179
  _renderGroups(duration) {
183
180
  const transformString = this._transform.toString();
@@ -811,10 +808,25 @@ class TopoJSONMap extends ComponentCore {
811
808
  const prevTranslate = this._projection.translate();
812
809
  this._projection.fitExtent([[0, 0], [this._width, this._height]], this._featureCollection);
813
810
  this._initialScale = this._projection.scale();
814
- this._center = [
815
- this._projection.translate()[0] * this._center[0] / prevTranslate[0],
816
- this._projection.translate()[1] * this._center[1] / prevTranslate[1],
817
- ];
811
+ // If a point is selected, center the view on it after resize
812
+ if (this._selectedPoint) {
813
+ const coords = this._selectedPoint.geometry.coordinates;
814
+ const pos = this._projection(coords);
815
+ const projTranslate = this._projection.translate();
816
+ if (pos) {
817
+ const k = this._currentZoomLevel;
818
+ this._center = [
819
+ this._width / 2 - (pos[0] - projTranslate[0]) * k,
820
+ this._height / 2 - (pos[1] - projTranslate[1]) * k,
821
+ ];
822
+ }
823
+ }
824
+ else {
825
+ this._center = [
826
+ this._projection.translate()[0] * this._center[0] / prevTranslate[0],
827
+ this._projection.translate()[1] * this._center[1] / prevTranslate[1],
828
+ ];
829
+ }
818
830
  this._applyZoom();
819
831
  this._isResizing = false;
820
832
  this._prevWidth = this._width;
@@ -829,8 +841,9 @@ class TopoJSONMap extends ComponentCore {
829
841
  (_b = (_a = this.g.node()) === null || _a === void 0 ? void 0 : _a.parentElement) === null || _b === void 0 ? void 0 : _b.style.setProperty('--vis-map-current-zoom-level', String(this._currentZoomLevel));
830
842
  return; // To prevent double render because of binding zoom behaviour
831
843
  }
832
- const isMouseEvent = event.sourceEvent !== undefined;
844
+ const isMouseEvent = !!event.sourceEvent;
833
845
  const isExternalEvent = !(event === null || event === void 0 ? void 0 : event.sourceEvent) && !this._isResizing;
846
+ const isResizeEvent = this._isResizing && !(event === null || event === void 0 ? void 0 : event.sourceEvent);
834
847
  this._isZooming = true;
835
848
  // Clear any pending zoom end timeout
836
849
  if (this._zoomEndTimeoutId) {
@@ -844,7 +857,7 @@ class TopoJSONMap extends ComponentCore {
844
857
  this._collapsedClusterPointIds = null;
845
858
  }
846
859
  window.cancelAnimationFrame(this._animFrameId);
847
- this._animFrameId = window.requestAnimationFrame(this._onZoomHandler.bind(this, event.transform, isMouseEvent, isExternalEvent));
860
+ this._animFrameId = window.requestAnimationFrame(this._onZoomHandler.bind(this, event.transform, isMouseEvent, isExternalEvent, isResizeEvent));
848
861
  if (isMouseEvent) {
849
862
  // Update the center coordinate so that the next call to _applyZoom()
850
863
  // will zoom with respect to the current view
@@ -877,13 +890,13 @@ class TopoJSONMap extends ComponentCore {
877
890
  collidePointBottomLabels(pointBottomLabels, duration);
878
891
  });
879
892
  }
880
- _onZoomHandler(transform, isMouseEvent, isExternalEvent) {
893
+ _onZoomHandler(transform, isMouseEvent, isExternalEvent, isResizeEvent = false) {
881
894
  const scale = transform.k / this._initialScale || 1;
882
895
  const center = this._projection.translate();
883
896
  this._transform = zoomIdentity
884
897
  .translate(transform.x - center[0] * scale, transform.y - center[1] * scale)
885
898
  .scale(scale);
886
- const customDuration = isExternalEvent
899
+ const customDuration = (isExternalEvent || isResizeEvent)
887
900
  ? this.config.zoomDuration
888
901
  : (isMouseEvent ? 0 : null);
889
902
  // Call render functions that depend on this._transform
@@ -897,11 +910,13 @@ class TopoJSONMap extends ComponentCore {
897
910
  zoomIn(increment = 0.5) {
898
911
  if (this._isZooming)
899
912
  return;
913
+ this._resetExpandedCluster();
900
914
  this.setZoom(this._currentZoomLevel + increment);
901
915
  }
902
916
  zoomOut(increment = 0.5) {
903
917
  if (this._isZooming)
904
918
  return;
919
+ this._resetExpandedCluster();
905
920
  this.setZoom(this._currentZoomLevel - increment);
906
921
  }
907
922
  setZoom(zoomLevel) {
@@ -930,6 +945,7 @@ class TopoJSONMap extends ComponentCore {
930
945
  fitView() {
931
946
  var _a, _b, _c, _d, _e;
932
947
  const { config } = this;
948
+ this._resetExpandedCluster();
933
949
  if (config.mapFitToPoints) {
934
950
  // When mapFitToPoints is enabled, fitView should refit the projection to the points
935
951
  // and reset the zoom level relative to that fitted scale.