Skip to content

Commit

Permalink
fix: check _map is assigned to avoid errors on often redraw from scratch
Browse files Browse the repository at this point in the history
  • Loading branch information
utilmind committed Nov 29, 2024
1 parent 10393d1 commit 747a6ae
Showing 1 changed file with 24 additions and 22 deletions.
46 changes: 24 additions & 22 deletions src/canvas-overlay.ts
Original file line number Diff line number Diff line change
Expand Up @@ -165,29 +165,31 @@ export class CanvasOverlay extends Layer {

_redraw(): void {
const { _map, canvas } = this;
const size = _map.getSize();
const bounds = _map.getBounds();
const zoomScale =
(size.x * 180) / (20037508.34 * (bounds.getEast() - bounds.getWest())); // resolution = 1/zoomScale
const zoom = _map.getZoom();
const topLeft = new LatLng(bounds.getNorth(), bounds.getWest());
const offset = this._unclampedProject(topLeft, 0);
if (canvas) {
this._userDrawFunc({
bounds,
canvas,
offset,
scale: Math.pow(2, zoom),
size,
zoomScale,
zoom,
});
}
if (_map) {
const size = _map.getSize();
const bounds = _map.getBounds();
const zoomScale =
(size.x * 180) / (20037508.34 * (bounds.getEast() - bounds.getWest())); // resolution = 1/zoomScale
const zoom = _map.getZoom();
const topLeft = new LatLng(bounds.getNorth(), bounds.getWest());
const offset = this._unclampedProject(topLeft, 0);
if (canvas) {
this._userDrawFunc({
bounds,
canvas,
offset,
scale: Math.pow(2, zoom),
size,
zoomScale,
zoom,
});
}

while (this._redrawCallbacks.length > 0) {
const callback = this._redrawCallbacks.shift();
if (callback) {
callback(this);
while (this._redrawCallbacks.length > 0) {
const callback = this._redrawCallbacks.shift();
if (callback) {
callback(this);
}
}
}

Expand Down

0 comments on commit 747a6ae

Please sign in to comment.