@cashub/ui 0.19.14 → 0.19.15

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.
package/map/GoogleMap.js CHANGED
@@ -291,7 +291,6 @@ var Map = function Map(_ref2) {
291
291
  lat: latitude,
292
292
  lng: longitude
293
293
  };
294
- map.panTo(coordinate);
295
294
  popup.setMap(map);
296
295
  popup.setPosition(coordinate);
297
296
  popup.setContent((0, _server.renderToString)(customPopup(location)));
@@ -58,6 +58,8 @@ var GoogleMapPopup = /*#__PURE__*/_createClass(function GoogleMapPopup(options)
58
58
 
59
59
  _defineProperty(_assertThisInitialized(_this), "offset", 16);
60
60
 
61
+ _defineProperty(_assertThisInitialized(_this), "justRendered", false);
62
+
61
63
  _this.containerDiv = document.createElement('div');
62
64
 
63
65
  _this.containerDiv.classList.add('google-popup-content-wrapper');
@@ -81,6 +83,7 @@ var GoogleMapPopup = /*#__PURE__*/_createClass(function GoogleMapPopup(options)
81
83
  key: "onAdd",
82
84
  value: function onAdd() {
83
85
  this.getPanes().floatPane.appendChild(this.containerDiv);
86
+ this.justRendered = true;
84
87
  }
85
88
  /** Called when the popup is removed from the map. */
86
89
 
@@ -89,6 +92,7 @@ var GoogleMapPopup = /*#__PURE__*/_createClass(function GoogleMapPopup(options)
89
92
  value: function onRemove() {
90
93
  if (this.containerDiv.parentElement) {
91
94
  this.containerDiv.parentElement.removeChild(this.containerDiv);
95
+ this.justRendered = false;
92
96
  }
93
97
  }
94
98
  /** Called each frame when the popup needs to draw itself. */
@@ -97,7 +101,13 @@ var GoogleMapPopup = /*#__PURE__*/_createClass(function GoogleMapPopup(options)
97
101
  key: "draw",
98
102
  value: function draw() {
99
103
  if (this.position) {
100
- var divPosition = this.getProjection().fromLatLngToDivPixel(this.position);
104
+ var divPosition = this.getProjection().fromLatLngToDivPixel(this.position); // On the first render, if we go beyond the map, pan the map
105
+
106
+ if (this.justRendered) {
107
+ this.fitMap();
108
+ this.justRendered = false;
109
+ }
110
+
101
111
  this.containerDiv.style.left = "".concat(divPosition.x, "px");
102
112
  this.containerDiv.style.top = "".concat(divPosition.y - this.offset, "px");
103
113
  }
@@ -118,6 +128,35 @@ var GoogleMapPopup = /*#__PURE__*/_createClass(function GoogleMapPopup(options)
118
128
  this.containerDiv.innerHTML = content;
119
129
  }
120
130
  }
131
+ }, {
132
+ key: "fitMap",
133
+ value: function fitMap() {
134
+ var projection = this.getProjection();
135
+ var _this$containerDiv = this.containerDiv,
136
+ offsetWidth = _this$containerDiv.offsetWidth,
137
+ offsetHeight = _this$containerDiv.offsetHeight;
138
+ var halfWidth = offsetWidth / 2;
139
+ var _this$containerDiv2 = this.containerDiv,
140
+ offsetTop = _this$containerDiv2.offsetTop,
141
+ offsetLeft = _this$containerDiv2.offsetLeft; // Calculate the coordinates of the four corners of the container
142
+ // because container use transform for position(-50%, -100%), so we need to subtract them
143
+
144
+ var topLeft = new window.google.maps.Point(offsetLeft - halfWidth, offsetTop - offsetHeight);
145
+ var topRight = new window.google.maps.Point(offsetLeft + offsetWidth - halfWidth, offsetTop - offsetHeight);
146
+ var bottomLeft = new window.google.maps.Point(offsetLeft - halfWidth, offsetTop + offsetHeight - offsetHeight);
147
+ var bottomRight = new window.google.maps.Point(offsetLeft + offsetWidth - halfWidth, offsetTop + offsetHeight - offsetHeight);
148
+ var northWest = projection.fromDivPixelToLatLng(topLeft);
149
+ var northEast = projection.fromDivPixelToLatLng(topRight);
150
+ var southWest = projection.fromDivPixelToLatLng(bottomLeft);
151
+ var southEast = projection.fromDivPixelToLatLng(bottomRight);
152
+ var popupBound = new window.google.maps.LatLngBounds();
153
+ popupBound.extend(northWest);
154
+ popupBound.extend(northEast);
155
+ popupBound.extend(southWest);
156
+ popupBound.extend(southEast);
157
+ popupBound.extend(this.position);
158
+ this.map.fitBounds(popupBound);
159
+ }
121
160
  }]);
122
161
 
123
162
  return MapPopup;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cashub/ui",
3
- "version": "0.19.14",
3
+ "version": "0.19.15",
4
4
  "private": false,
5
5
  "author": "CASHUB Team",
6
6
  "description": "CASHUB UI components library",