如何重新加载/刷新Google地图图块图层?
我有一个图块图层,我想删除该图块图层并替换为Google Maps中的另一个图层.我的图块层是在MapOptions中使用GetTileUrl定义的,以调用函数.
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.
当我尝试执行此操作时,只会在平移地图时加载新图层.我想我需要从Google的缓存中删除旧的磁贴(就像我关闭浏览器缓存一样,这种情况仍然会发生).
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.
我是否需要将地图设置为null并重新初始化所有内容?还是可以重新加载地图图块图层?
Do I need to set the map to null and reinitialize everything? Or can I just reload my map tile layer?
当我更改图层时,瓦片加载的URL会发生变化-因此我猜测添加伪参数不会帮助我.
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.
该代码相当长(并且其中包含其他内容),但是如果您想查看实际的代码,可以转到 JusticeMap.org
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);
我需要将jmapMapType存储在全局变量中.
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);