如何重新加载/刷新Google地图图块图层? [英] How to reload/refresh a Google Maps tile layer?

查看:179
本文介绍了如何重新加载/刷新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);

这篇关于如何重新加载/刷新Google地图图块图层?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆