Skip to content

Commit

Permalink
Merge pull request #165 from utilmind/master
Browse files Browse the repository at this point in the history
fix: check whether _map is assigned to avoid errors on often redraw from scratch
  • Loading branch information
charlieforward9 authored Dec 12, 2024
2 parents 291eabe + a95f1f0 commit 796eb4e
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 @@ -169,29 +169,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 796eb4e

Please sign in to comment.