-
Notifications
You must be signed in to change notification settings - Fork 24
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fitBounds not supported? #36
Comments
If you are trying to keep an overlay the same size regardless of zoom, see here: We just called it bounds, and the boundaries are typically a small x/y grouping of numbers indicating in all directions of how to size the overlay at all times. The demo code has one overlay with a fixed size definition as well: |
He was talking about this : https://github.com/SebastianM/angular-google-maps/blob/master/docs/content/guides/implement-auto-fit-bounds.md With these feature, you can put juste put markers on the map and it will set the center and the zoom level automaticaly. It's so awesome ! In agm-marker, in ngOnChange, if latitude or longitude change, they just emit new values on a subject |
Hi, Thanks! |
There is a quick workaround in the line of what @JulienBourgain suggested: wrapping the The custom component would look like: import { FitBoundsAccessor, FitBoundsDetails } from '@agm/core';
import { Component, forwardRef, Input, OnInit } from '@angular/core';
import { BehaviorSubject, Observable } from 'rxjs';
@Component({
selector: 'app-map-bounds',
template: ` <ng-content></ng-content> `,
providers: [{ provide: FitBoundsAccessor, useExisting: forwardRef(() => MapBoundsComponent) }],
})
export class MapBoundsComponent implements OnInit, FitBoundsAccessor {
@Input() latitude: number;
@Input() longitude: number;
fitBoundsDetails$ = new BehaviorSubject<FitBoundsDetails>(null);
getFitBoundsDetails$(): Observable<FitBoundsDetails> {
return this.fitBoundsDetails$.asObservable();
}
ngOnInit() {
const latLng: google.maps.LatLngLiteral = { lat: this.latitude, lng: this.longitude };
this.fitBoundsDetails$.next({ latLng });
}
} And then you would use it to wrap markers in the template where you define the map: <agm-map [fitBounds]="true" style="height:400px;">
<app-map-bounds [agmFitBounds]="true" *ngFor="let marker of markers" [latitude]="marker.latitude" [longitude]="marker.longitude">
<agm-overlay [latitude]="marker.latitude" [longitude]="marker.longitude">
<! -- Your content... -->
</agm-overlay>
</app-map-bounds>
</agm-map> |
@d-silvas you have just made my day |
You can just create a marker collection that is not visible.
|
Hey
Looks like fitBounds is not supported as I am adding new overlays after the map was loaded and nothing happens?
Am I correct that it is not supported?
Thanks
Nick
The text was updated successfully, but these errors were encountered: