我们在用OpenLayers客户端来实施的天地图项目、山西平台项目等都遇到一个浏览效果不佳的问题,即已经给图层赋了transitionEffect属性为resize,仍然只有在地图的前面几级有过度效果(1-10级),这样在11级以后的浏览过程中,如果网速不够快,有瓦片不能及时显示出来,就会出现地图显示区域有很多空白,这样浏览的效果就很差。
现在我们来解决这个问题:
首先我们把这个过度效果相关的代码找出来,红色字是OpenLayers原先的代码,蓝色字是我修改后的代码,黄底字是关键位置。
OpenLayers/lib/OpenLayers/Tile/Image.js
/**
* Method: startTransition 开始显示过度效果
* This method is invoked on tiles that are backBuffers for tiles in the
* grid. The grid tile is about to be cleared and a new tile source
* loaded. This is where the transition effect needs to be started
* to provide visual continuity.
*/
* Method: startTransition 开始显示过度效果
* This method is invoked on tiles that are backBuffers for tiles in the
* grid. The grid tile is about to be cleared and a new tile source
* loaded. This is where the transition effect needs to be started
* to provide visual continuity.
*/
startTransition: function() {
// backBufferTile has to be valid and ready to use
if (!this.backBufferTile || !this.backBufferTile.imgDiv) {
return;
}
// backBufferTile has to be valid and ready to use
if (!this.backBufferTile || !this.backBufferTile.imgDiv) {
return;
}
// calculate the ratio of change between the current resolution of the
// backBufferTile and the layer. If several animations happen in a
// row, then the backBufferTile will scale itself appropriately for
// each request.
var ratio = 1;
if (this.backBuffer
// backBufferTile and the layer. If several animations happen in a
// row, then the backBufferTile will scale itself appropriately for
// each request.
var ratio = 1;
if (this.backBuffer