我正在加载自定义PNG瓷砖到谷歌地图上,似乎性能正在杀死iOS Safari中的应用程序,并使其抓取大多数其他浏览器。我相信这是由于瓦片数量正在加载到地图上(加载73个伊利诺伊州县,瓦片数量取决于缩放级别)以及iOS提供给Safari的有限内存量。谷歌地图imageMapType崩溃iOS Safari
首先,我只,通过使用google.maps.LatLngBounds.intersects
function createBoundedTileLayer(sourceUrl, bounds) {
var imageMapType = new google.maps.ImageMapType({
getTileUrl: function (coord, zoom) {
var tileBounds = getTileBounds(coord, zoom);
if (bounds.intersects(tileBounds)) {
return app.stringFormat(sourceUrl, coord.x, coord.y, zoom);
}
return null;
},
tileSize: new google.maps.Size(256, 256),
isPng: true,
opacity: 0.7
});
return imageMapType;
}
function getTileBounds(coord, zoom) {
var mapSize = Math.pow(2, zoom);
var west = ((coord.x * 360)/mapSize) - 180;
var east = (((coord.x + 1) * 360)/mapSize) - 180;
var efactor = Math.exp((0.5 - coord.y/mapSize) * 4 * Math.PI);
var north = (Math.asin((efactor - 1)/(efactor + 1))) * (180/Math.PI);
efactor = Math.exp((0.5 - (coord.y + 1)/mapSize) * 4 * Math.PI);
var south = (Math.asin((efactor - 1)/(efactor +1))) * (180/Math.PI);
return new google.maps.LatLngBounds(new google.maps.LatLng(south, west), new google.maps.LatLng(north, east));
}
创造,我有,而不是想检索屏幕上的每一个平铺图像的瓷砖新imageMapType覆盖其次,我为“桌面”浏览器,我同时加载所有的瓷砖,它不会崩溃(只是当我缩放或平移地图时才抓取)。对于移动浏览器,为了停止崩溃行为,我一次只能为5个县加载足够的磁贴,使用setTimeout 2000毫秒,然后加载5个县,直到加载所有73个县。
有没有人在Google地图中使用过这个问题? 在此先感谢!
也许您需要查看服务器端的Google Maps Engine,但不会为JavaScript虚拟机使用太多的RAM。 – xmux 2014-09-29 13:48:52
@xmux,自从评论以来,我对Google Maps Engine的了解并不多,我需要推动我的瓷砖到谷歌服务器,然后他们将被加载?这是一个准确的评估? – AaronBastian 2014-09-29 21:12:42
您可以将图块上传/上传到Google地图引擎,甚至可以向他们提供位置信息。这很简单,然后你需要搜索GME API,这样你就可以得到图层了 – xmux 2014-09-30 06:34:08