center of map not being same when the width of agm-map is changed.
I am trying to reduce the width of map on some event as, $('agm-map').css("width","10%") when this is done, the center of map is not getting change. As the agm-marker is present on center of map, i am not able to see it in the center of my newly render map(i.e, the map with smaller size)
my map covering the whole viewport:

when width is redued,

cant see the agm-marker now. is there any possibility we can change the width by not changing the zoom property.
Thanks in advance. Please help on this.
Pretty sure this would be a problem with the standard usage of Google maps (without the Angular wrapper via this module). I don't think there's anything that we can (or even should) do about this. You can listen to the event of resizing (since for now that's probably the most common way of determining if an element's width has changed, although there are obvious exceptions here) and re-trigger the values for the map's center coordinates.
On Tue, Feb 6, 2018 at 7:51 PM, siddiq-rehman [email protected] wrote:
I am trying to reduce the width of map on some event as, $('agm-map').css("width","10%") when this is done, the center of map is not getting change. As the agm-marker is present on center of map, i am not able to see it in the center of my newly render map(i.e, the map with smaller size)
my map covering the whole viewport:
[image: image] https://user-images.githubusercontent.com/22259730/35877887-a243f6aa-0b9c-11e8-8d36-1c77e84f2b3a.png
when width is redued, [image: image] https://user-images.githubusercontent.com/22259730/35877921-be5c729a-0b9c-11e8-9b27-2150ee9c4fa3.png
cant see the agm-marker now. is there any possibility we can change the width by not changing the zoom property.
Thanks in advance. Please help on this.
— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/SebastianM/angular-google-maps/issues/1309, or mute the thread https://github.com/notifications/unsubscribe-auth/AHTnkQO0As1SUDWy3JUc0kpKWcYCegHbks5tSJ9IgaJpZM4R7jDH .
It was helpful for me #987
As part of your template:
<agm-map
[latitude]="latitude"
[longitude]="longitude"
[scrollwheel]="true"
[zoom]="zoom"
(idle)="idle()"
(centerChange)="centerChange($event)"
id="AgmMap"
#AgmMap>
<agm-marker [latitude]="latitude" [longitude]="longitude" [markerClickable]="true"></agm-marker>
</agm-map>
In the TS:
public latitude: number;
public longitude: number;
private centerLat: number;
private centerLng: number;
public zoom: number;
private changeLat: number;
private changeLng: number;
@HostListener('window:resize')
onWindowResize() {
this.onResize();
}
onResize() {
// resize the container for the google map
this.renderer.setElementStyle(
this.wrapper.nativeElement, 'height',
(window.innerHeight) + 'px'
);
// recenters the map to the resized area.
this.agmMap.triggerResize().then(() => this.agmMap._mapsWrapper.setCenter({lat: this.centerLat, lng: this.centerLng}));
}
// idle fires after paning or zooming is done. This is where we want to capture the center of the map.
// This way if the user resizes, the center is preserved.
idle() {
this.centerLat = this.changeLat;
this.centerLng = this.changeLng;
}
// this event fires whenever the center is changed. Panning, zooming, or resizing change the center.
centerChange(event: any) {
if (event) {
this.changeLat = event.lat;
this.changeLng = event.lng;
}
}
Of course this is what I do for window resize, you can base it off a container resize event too.
Hi @timcblank,
On resize map center is getting auto adjusted. But when i reduce the width of outer div, the div is getting resized, but the map is not getting resized.
If you are using a container then you may need to check for the resize event for the container instead.
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.