Skip to content

Commit

Permalink
fix: improve zooming AB#24144
Browse files Browse the repository at this point in the history
  • Loading branch information
jannisvisser committed Oct 13, 2023
1 parent 330a0e5 commit 38fd1bb
Showing 1 changed file with 11 additions and 9 deletions.
20 changes: 11 additions & 9 deletions interfaces/IBF-dashboard/src/app/components/map/map.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ export class MapComponent implements AfterViewInit, OnDestroy {
: newLayer;

if (newLayer.viewCenter) {
this.map.fitBounds(this.mapService.state.bounds);
this.zoomToArea();
}
} else {
this.layers = [];
Expand Down Expand Up @@ -243,28 +243,30 @@ export class MapComponent implements AfterViewInit, OnDestroy {
const adminRegionsFiltered = JSON.parse(
JSON.stringify(adminRegionsLayer.data),
);
let zoomExtraOffset: number;
if (this.placeCode) {
adminRegionsFiltered.features = adminRegionsLayer.data?.features.filter(
(area) =>
area?.properties?.['placeCode'] === this.placeCode.placeCode,
area?.properties?.['placeCode'] === this.placeCode.placeCode ||
area?.properties?.['placeCodeParent'] ===
this.placeCode.placeCode,
);
zoomExtraOffset = 0.1;
} else {
adminRegionsFiltered.features = adminRegionsLayer.data?.features;
zoomExtraOffset = 0;
}
if (adminRegionsFiltered.features.length) {
const layerBounds = bbox(adminRegionsFiltered);
const layerWidth = layerBounds[2] - layerBounds[0];
const layerHeight = layerBounds[3] - layerBounds[1];
const zoomExtraOffset = 0.1; //10% margin of height and width on all sides
this.mapService.state.bounds = containsNumber(layerBounds)
? ([
[
layerBounds[1] - zoomExtraOffset,
layerBounds[0] - zoomExtraOffset,
layerBounds[1] - zoomExtraOffset * layerHeight,
layerBounds[0] - zoomExtraOffset * layerWidth,
],
[
layerBounds[3] + zoomExtraOffset,
layerBounds[2] + zoomExtraOffset,
layerBounds[3] + zoomExtraOffset * layerHeight,
layerBounds[2] + zoomExtraOffset * layerWidth,
],
] as LatLngBoundsLiteral)
: this.mapService.state.bounds;
Expand Down

0 comments on commit 38fd1bb

Please sign in to comment.