谷歌地图v3:如何强制重新加载瓷砖 [英] Google maps v3: how to force reloading of tiles

查看:86
本文介绍了谷歌地图v3:如何强制重新加载瓷砖的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经遇到了令人讨厌的问题。我开始测试我的谷歌地图代码与较慢的互联网连接,它不再像它想象的那样工作了。



问题是当我在地图上做动画时,我正在监听tilesloaded事件,因为连接速度很慢一些瓷砖可能会挂起并且不加载..地图上会有灰色瓷砖,我的程序不会继续,因为它会等待它加载。



我使用了萤火虫控制台以捕获错误,并说:

图片损坏或被截断: https://mts0.googleapis.com/vt? lyrs = m @ 183000000& src = apiv3& hl = fi-FI& x = 18706& y = 8527& z = 15& s = Galil& style = api%7Csmartmaps

我将其粘贴到浏览器,并从那里找到丢失的图像。帮助它!它存在但有时不会加载:)

所以问题是,如何强制在一段时间后重新加载丢失的图块或所有图块时间,据我所知没有这样的事件,如果一些瓷砖不能被加载会触发?并且似乎控制台上出现的错误并不总是给出。我也尝试过使用谷歌地图的闲置事件,但它不会等待要加载的图块,并且会使程序继续为滞后。 (不是我想要的东西。)



我也使用 google.maps.event.trigger(my_map,'resize'); code>但它似乎有帮助。



编辑:

刷新整页不是一个选项,因为我会失去我的变量值等,这种慢加载是很难测试,但出现在平移到地图上的某个特定点,这是迄今为止瓷砖需要重新加载。



有什么想法?提前thnx!

解决方案

在JavaScript地图响应浏览器调整大小,并加载缺少的瓷砖,所以你需要的是火浏览器事件调整大小

  var evt = document.createEvent('UIEvents'); 
evt.initUIEvent('resize',true,false,window,0);
window.dispatchEvent(evt);


I have come accross pretty annoying problem. I started to test my google maps code with slower internet connection and it doesnt pretty much work anymore like it suppose to.

The problem is that I am listening "tilesloaded" event when Im doing animations on map BUT because connection is slow some tiles might hang and doesnt load.. there will be gray tile middle of the map and my program wont continue because it waits it to be loaded.

I used firebug console to catch error and it said:

Image corrupt or truncated: https://mts0.googleapis.com/vt?lyrs=m@183000000&src=apiv3&hl=fi-FI&x=18706&y=8527&z=15&s=Galil&style=api%7Csmartmaps

I pasted that to browser and found the missing tile image from there. darn it! It exists but sometimes doesnt load :)

So the question is that how I can force reloading of missing tiles or all tiles after some period of time, as far as I know there is no such event which will be triggered if some tile cant be loaded? and it seems that error which appeared to console are not given always. I also tried using "idle" event of google maps but it doesnt wait tiles to be loaded and will make program continue as laggy. (not someting what I want.)

I am also using google.maps.event.trigger(my_map, 'resize'); but it doenst seem to help.

Edit:

Refreshing full page is not an option because I would lose values of my variables etc. and this slow loading is hard to test but occurs when panning to some specific point on map which is so far that tiles needs to be reloaded.

Any ideas? Thnx in advance!

解决方案

in javascript map responds on browser resize, and loads missing tiles, so all what you need is fire browser event "resize"

var evt = document.createEvent('UIEvents');
evt.initUIEvent('resize', true, false,window,0);
window.dispatchEvent(evt);

这篇关于谷歌地图v3:如何强制重新加载瓷砖的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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