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

add a getter for the map wrapper in the map directive#311

Closed
alexweber wants to merge 2 commits into
sebholstein:masterfrom
alexweber:hotfix-get-wrapper
Closed

add a getter for the map wrapper in the map directive#311
alexweber wants to merge 2 commits into
sebholstein:masterfrom
alexweber:hotfix-get-wrapper

Conversation

@alexweber
Copy link
Copy Markdown
Contributor

@alexweber alexweber commented May 3, 2016

Allow the GoogleMapsAPIWrapper instance used in the directive to be retrieved.

Since the provider is overridden per map instance, I haven't found a way to access the same GoogleMapsAPIWrapper instance as injecting it into my component gives me a new instance, even if provided at the app bootstrap level.

I get that with multiple maps on the page we really don't want only a single api wrapper to be available, hence the provider on the directive level, however, it would be incredibly useful to gain access to that api wrapper instance in order to call getMap() on it and so on.

@GitCop
Copy link
Copy Markdown

GitCop commented May 3, 2016

There were the following issues with your Pull Request

  • Commit: a5e38f6
    • Commits must be in the following format: %{type}(%{scope}): %{description}

Contribution guidelines are available at https://github.com/SebastianM/angular2-google-maps/blob/master/CONTRIBUTING.md


This message was auto-generated by https://gitcop.com

@alexweber
Copy link
Copy Markdown
Contributor Author

alexweber commented May 3, 2016

@SebastianM Test fails seem to be because of unrelated tslint errors, fixing those too.

});
}

get wrapper(): GoogleMapsAPIWrapper { return this._mapsWrapper; }
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@SebastianM This is the only real change in this PR

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

@alexweber I don't understand the need for this. You can already get the GoogleMapsAPIWrapper when you create a custom component and inject it in the constructor.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@SebastianM Yes, but it's not the same instance of the GoogleMapsAPIWrapper as the one used by the map. If you call getMap or anything else on it it fails. This is because the provider is specified in the map component....

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Yeah, you have to place your custom component inside the compontent. This is a conscious design decision.

@alexweber
Copy link
Copy Markdown
Contributor Author

@SebastianM Ah, thanks! I finally get it now... I can just create any directive, place it inside the map and inject the wrapper to get access to it. I see now how this promotes a cleaner way to interact with the map, good job! 👍

@alexweber alexweber closed this Jun 9, 2016
@NileshMoradiya
Copy link
Copy Markdown

@alexweber can you share the code?

@Ldnz
Copy link
Copy Markdown

Ldnz commented Feb 8, 2018

your code may looks like following
in component view:

<agm-map appGmap class="angular-google-map-container">

and then in appGmap directive:

`export class GmapDirective implements OnInit {

constructor(private mapWrapper: GoogleMapsAPIWrapper) { }

ngOnInit() {
this.mapWrapper.setMapOptions({ styles: MapStyles });
}
}`

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.

5 participants