原來這是transform()
我的自定義getURL函數中的邊界,和忘記clone()
他們第一個的問題。
this.layer = new OpenLayers.Layer.XYZ(
'layer description',
myBaseUrl + '&x=${x}&y=${y}&z=${z}',
{
name: 'layer name',
getURL: getMyTileUrl,
type: 'jpg',
minZoomLevel: 15,
maxZoomLevel: 18,
isBaseLayer: false,
transitionEffect: 'resize',
buffer: 3
}
);
function getMyTileUrl(bounds) {
bounds = bounds.transform(this.projection,"EPSG:4326");
// ...
return this.url + z + "/" + x + "/" + y + "." + this.type;
}
解決方案是在轉換它們之前克隆邊界。
function getMyTileUrl(bounds) {
bounds = bounds.clone().transform(this.projection,"EPSG:4326");
// ...
return this.url + z + "/" + x + "/" + y + "." + this.type;
}
忘記克隆邊界意味着我正在轉換該圖塊的「官方」邊界對象。下一次使用此邊界對象時,將確定當前加載的切片是否與新的切片邊界相交,以確定我們是應該移動某些切片還是將它們全部扔掉並獲取新切片。由於它們被轉換成了不同的投影,OpenLayers認爲當前裝載的瓷磚來自地球上完全不同的部分,所以它將它們扔掉並重新開始。