Skip to content
This repository was archived by the owner on Jun 23, 2025. It is now read-only.

feat(core): auto fitBounds#1389

Merged
sebholstein merged 11 commits into
masterfrom
auto-fit-bounds2
Sep 22, 2018
Merged

feat(core): auto fitBounds#1389
sebholstein merged 11 commits into
masterfrom
auto-fit-bounds2

Conversation

@sebholstein

Copy link
Copy Markdown
Owner

New API in favour of #868:

turn on auto fitbounds:

<agm-map [fitBounds]="true"></agm-map>

add the agmFitBoundsdirective to all elements you want to include in the bounds:

```html
<agm-map [fitBounds]="true">
  <agm-marker [agmFitBounds]="true"></agm-marker>
</agm-map>

@sebholstein sebholstein mentioned this pull request Apr 30, 2018
@jimmykane

Copy link
Copy Markdown

He is back !

@sebholstein sebholstein force-pushed the auto-fit-bounds2 branch 4 times, most recently from 4450a48 to 4179f9a Compare May 1, 2018 11:37
@delberthsoto

Copy link
Copy Markdown

Hi, im using AGM and i wonder if you can tell me how can i add this changes to the last version that i have installed 1.0.0-beta.2

Comment thread packages/core/services/fit-bounds.ts Outdated
this.bounds$ = from(loader.load()).pipe(
flatMap(() => this._includeInBounds$),
skipWhile(() => this._emitPaused),
// debounce(() => this._boundsChangeDebounceTime$),

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

_boundsChangeDebounceTime$ is not needed, right?

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no only fitbounds, thank you!

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@boogie77 it's not finished yet

@zegmonteiro

Copy link
Copy Markdown

Really wanting to use this feature!

@ed-jimmy

ed-jimmy commented Jun 1, 2018

Copy link
Copy Markdown

+1

@appsetor

appsetor commented Jun 2, 2018

Copy link
Copy Markdown

how to use this?

@ed-jimmy

ed-jimmy commented Jun 2, 2018

Copy link
Copy Markdown

@appsetor not available yet. To work with bounds go look at #719

when assigning "fitBounds" to the "agm-map" directive you need to pass it a value of type LatLngBounds. You can see the docs right here...

https://angular-maps.com/api-docs/agm-core/components/AgmMap.html#fitBounds

to create such value do what @tscislo did in #719. His answer is a little dated, so my code looks like this...

import { MapsAPILoader } from '@agm/core';

constructor(private mapsAPILoader: MapsAPILoader, private _deviceService: DeviceService) { }

ngOnInit(): void {

    let body = this.deviceListCommand.getPostRequest();//get all devices starting out

    this._deviceService.getDevices(body)
        .subscribe(
            (response: IDevice[]) => {
                this.markers = response;
                this.setBounds();
            },
            error => console.log(error)
        );
}

setBounds(): void {
    //wait until google map api loads
    this.mapsAPILoader.load().then(() => {
            this.latlngBounds = new window['google'].maps.LatLngBounds();
            this.markers.forEach((marker) => {
                this.latlngBounds.extend(new window['google'].maps.LatLng(marker.LastLatitude, marker.LastLongitude))
            })
    })
}

I make a call to get a list of objects, then for each I add to latlngBounds and on my template I have this

<agm-map [latitude]="lat" [longitude]="lng" [fitBounds]="latlngBounds" [zoom]="zoom">

            <agm-marker *ngFor="let m of markers"
                        [latitude]="m.LastLatitude" 
                        [longitude]="m.LastLongitude">

                <agm-info-window>
                    <strong>{{m.DeviceName}}</strong>
                </agm-info-window>

            </agm-marker>      

</agm-map>

@sebholstein sebholstein force-pushed the auto-fit-bounds2 branch 3 times, most recently from a6efee2 to 6770c9f Compare June 3, 2018 17:54
@arkD

arkD commented Jun 4, 2018

Copy link
Copy Markdown

this is by far the best answer i have seen @ed-jimmy, I was really struggling with this because of old examples. Thanks You!

@codecov

codecov Bot commented Jun 5, 2018

Copy link
Copy Markdown

Codecov Report

Merging #1389 into master will increase coverage by 0.59%.
The diff coverage is 36.36%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #1389      +/-   ##
==========================================
+ Coverage   28.36%   28.95%   +0.59%     
==========================================
  Files          30       32       +2     
  Lines        1361     1454      +93     
  Branches      185      197      +12     
==========================================
+ Hits          386      421      +35     
- Misses        973     1031      +58     
  Partials        2        2
Impacted Files Coverage Δ
packages/core/services/google-maps-types.ts 0% <ø> (ø) ⬆️
packages/core/core.module.ts 0% <0%> (ø) ⬆️
packages/core/directives/map.ts 0% <0%> (ø) ⬆️
packages/core/directives/fit-bounds.ts 0% <0%> (ø)
packages/core/services/fit-bounds.ts 100% <100%> (ø)
packages/core/directives/marker.ts 35.1% <44.44%> (+0.22%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 89b6e5c...27f9025. Read the comment docs.

@ed-jimmy

ed-jimmy commented Jun 5, 2018

Copy link
Copy Markdown

@arkD I'm glad I could help! It looks like the commits @SebastianM made were a success. So let's wait and see when the changes are applied and we can use the new method, which is a lot better!

@sebholstein

Copy link
Copy Markdown
Owner Author

@ed-jimmy tests and docs are WIP right now. After that, it's ready

@DanPride

Copy link
Copy Markdown

When will this be merged ? Fantastic improvment. Thanks

@Dimmalice

Copy link
Copy Markdown

Any plans to release this? Because we want to use it.

@creatiolabsmx

Copy link
Copy Markdown

and how use the function [agmFitBounds]="true" in agm-circle

@ghost ghost deleted the auto-fit-bounds2 branch September 17, 2019 11:27
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.