我正在加載自定義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