Skip to content
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

Allow multiple carto clients using Google Maps #2152

Merged
merged 9 commits into from
Jul 6, 2018

Conversation

rubenmoya
Copy link
Contributor

@rubenmoya rubenmoya commented Jun 26, 2018

Related to: #2132

Description

This PR allows to use multiple carto clients when using Google Maps.

We had a few problems:

  • We were assuming we only had one GMapsCartoDBLayerGroupView, and always using setAt(0, layer) which was overriding other layer groups added previously by other clients.
  • We were adding GoogleMapsMapType to the map.overlayMapTypes array, but checking for GMapsCartoDBLayerGroupView instances, so we never found them.
  • We were calling map.overlayMapTypes.push and telling our users to do the same, which lead to duplicated map types.
  • We were calling map.overlayMapTypes (in the example) for each layer, which works with Leaflet because it uses an object and internal layer ids, but not with google maps which just uses an array, we should document this somehow, clients have to call it once for each carto client / layer group.

I solved it by adding an internal id to both, GoogleMapsMapType and GMapsCartoDBLayerGroupView, and check that id instead of using indexOf(this).

It seems to be working, although map.overlayMapTypes can contain two different things depending on where it's being used (builder or public api).

I've also checked Leaflet, but since it works differently we don't have that problem.

Copy link
Contributor

@ivanmalagon ivanmalagon left a comment

Choose a reason for hiding this comment

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

In the end the solution is succint 👍

Just left a comment. Regarding unit tests, test the three methods you modified / created.

if (overlayIndex >= 0) {
this.gmapsMap.overlayMapTypes.removeAt(overlayIndex);
overlays.setAt(overlayIndex, overlays.getAt(overlayIndex));
Copy link
Contributor

Choose a reason for hiding this comment

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

This seems a bit strange since we're setting the overlay at the same exact place. I guess that setAt triggers something internally in Google Maps. If not, this has no much sense.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's basically a reload, before we were doing remoteAt 0 -> setAt 0, but just doing setAt works fine.

Copy link
Contributor

@jesusbotella jesusbotella left a comment

Choose a reason for hiding this comment

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

LGTM!

I have reviewed the new changes since ivan did the first CR and they look good.

@rjimenezda
Copy link
Contributor

I've tested the acceptance example as well as builder with gmaps and it seems like all's good in da hood

@rubenmoya rubenmoya merged commit a65e203 into master Jul 6, 2018
@rubenmoya rubenmoya deleted the 2132-gmaps-multiclient branch July 6, 2018 10:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants