Skip to content

Commit

Permalink
fix: Make sure map is initiated properly before trying to fit extent
Browse files Browse the repository at this point in the history
Happens when hslayers element misses display property defined in app and fallback value is added late
  • Loading branch information
FilipLeitner authored and raitisbe committed May 27, 2022
1 parent c4c7134 commit 1ffbb03
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions projects/hslayers/src/components/map/map.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1100,10 +1100,17 @@ export class HsMapService {
* @param extent - Extent provided
* @param app - App identifier
*/
fitExtent(extent: number[], app: string): void {
async fitExtent(extent: number[], app: string): Promise<void> {
const mapSize = this.getMap(app ?? DEFAULT).getSize();
if (!mapSize.every((p) => p > 0)) {
console.warn(
'Tried to fit extent but one of map dimensions were 0. Will wait a bit and try again!'
);
await new Promise((resolve) => setTimeout(resolve, 250));
}
this.getMap(app ?? DEFAULT)
.getView()
.fit(extent, {size: this.getMap(app ?? DEFAULT).getSize()});
.fit(extent, {size: mapSize});
}

/**
Expand Down

0 comments on commit 1ffbb03

Please sign in to comment.