Aaron Kreider
Aaron Kreider

Reputation: 1819

How to reload/refresh a Google Maps tile layer?

I've got a tile layer that I want to remove and replace with another one in Google Maps. My tile layer is defined in MapOptions using GetTileUrl to call a function.

For instance, I want to be able to remove a county layer and replace it with a census tract one.

When I try to do this it only loads the new layer when I pan the map. I think I need to remove the old tiles from Google's cache (as if I turn browser caching turned off this still happens).

I've tried the map "resize" event, but it doesn't work.

Do I need to set the map to null and reinitialize everything? Or can I just reload my map tile layer?

When I change the layer, the URL for the tile loading changes - so I'm guessing that adding a fake parameter won't help me.

The code is pretty long (and has extra stuff in it), but if you want to see this in action you can go to JusticeMap.org

var jmapMapType = new google.maps.ImageMapType(jmapTypeOptions);
map.overlayMapTypes.push(jmapMapType);

Upvotes: 1

Views: 1974

Answers (1)

Aaron Kreider
Aaron Kreider

Reputation: 1819

I needed to store the jmapMapType in a global variable.

Then I can remove it, and add it back. This reloads the tiles:

map.overlayMapTypes.removeAt(0);
map.overlayMapTypes.push(jmapMapType);

Upvotes: 4

Related Questions