我们一直在使用Openlayers 2扩展类OpenLayers.Layer.Grid
。
现在,我们想升级到OL3。 OL3中OpenLayers.Layer.Grid
的等价物是什么?我应该使用哪一堂课?
Openlayers 2扩展课程如下:
OpenLayers.Layer.ABC = OpenLayers.Class(OpenLayers.Layer.Grid, {
size: null,
isBaseLayer: true,
standardTileSize: 256,
tileOriginCorner: "tl",
numberOfTiers: 0,
tileCountUpToTier: null,
tierSizeInTiles: null,
tierImageSize: null,
initialize: function(name, url, size, options) {
this.initializeZoomify(size);
OpenLayers.Layer.Grid.prototype.initialize.apply(this, [
name, url, size, options
]);
},
initializeZoomify: function( size ) {
var imageSize = size.clone();
this.size = size.clone();
var tiles = new OpenLayers.Size(
Math.ceil( imageSize.w / this.standardTileSize ),
Math.ceil( imageSize.h / this.standardTileSize )
);
this.tierSizeInTiles = [tiles];
this.tierImageSize = [imageSize];
while (imageSize.w > this.standardTileSize ||
imageSize.h > this.standardTileSize ) {
imageSize = new OpenLayers.Size(
Math.floor( imageSize.w / 2 ),
Math.floor( imageSize.h / 2 )
);
tiles = new OpenLayers.Size(
Math.ceil( imageSize.w / this.standardTileSize ),
Math.ceil( imageSize.h / this.standardTileSize )
);
this.tierSizeInTiles.push( tiles );
this.tierImageSize.push( imageSize );
}
this.tierSizeInTiles.reverse();
this.tierImageSize.reverse();
this.numberOfTiers = this.tierSizeInTiles.length;
var resolutions = [1];
this.tileCountUpToTier = [0];
for (var i = 1; i < this.numberOfTiers; i++) {
resolutions.unshift(Math.pow(2, i));
this.tileCountUpToTier.push(
this.tierSizeInTiles[i-1].w * this.tierSizeInTiles[i-1].h +
this.tileCountUpToTier[i-1]
);
}
if (!this.serverResolutions) {
this.serverResolutions = resolutions;
}
},
destroy: function() {
OpenLayers.Layer.Grid.prototype.destroy.apply(this, arguments);
this.tileCountUpToTier.length = 0;
this.tierSizeInTiles.length = 0;
this.tierImageSize.length = 0;
},
clone: function (obj) {
if (obj == null) {
obj = new OpenLayers.Layer.ABC(this.name,
this.url,
this.size,
this.options);
}
obj = OpenLayers.Layer.Grid.prototype.clone.apply(this, [obj]);
return obj;
},
getURL: function (bounds) {
bounds = this.adjustBounds(bounds);
var res = this.getServerResolution();
var x = Math.round((bounds.left - this.tileOrigin.lon) / (res * this.tileSize.w));
var y = Math.round((this.tileOrigin.lat - bounds.top) / (res * this.tileSize.h));
var z = this.getZoomForResolution( res );
var path="";
var level = this.numberOfTiers - z - 1;
var sliceStringIndex = this.url.indexOf("&slice");
var layerTypeIndex = this.url.indexOf("&layerType");
var stackIndex = this.url.indexOf("&stack");
var jsonIndex = this.url.indexOf("&json");
var slice = this.url.substring(sliceStringIndex,layerTypeIndex).replace("&slice=", "");
var layerType = this.url.substring(layerTypeIndex,stackIndex).replace("&layerType=", "");
var stack;
stack = this.url.substring(stackIndex,jsonIndex).replace("&stack=", "");
var newUrl = this.url.substring(0, sliceStringIndex);
var prog = ['TILE 0 ' + stack + ' ' + level + ' ' + slice + ' ' + x + ' ' + y + ' none 10 1'];
var url = newUrl;
url = this.selectUrl(path, url);
url += '&prog=' + encodeURIComponent(prog.join('\n'));
return url;
},
getImageSize: function() {
return this.tileSize;
if (arguments.length > 0) {
var bounds = this.adjustBounds(arguments[0]);
var res = this.getServerResolution();
var x = Math.round((bounds.left - this.tileOrigin.lon) / (res * this.tileSize.w));
var y = Math.round((this.tileOrigin.lat - bounds.top) / (res * this.tileSize.h));
var z = this.getZoomForResolution( res );
var w = this.standardTileSize;
var h = this.standardTileSize;
if (x == this.tierSizeInTiles[z].w -1 ) {
var w_1 = this.tierImageSize[z].w % this.standardTileSize;
if(w_1 != 0)
w = w_1;
}
if (y == this.tierSizeInTiles[z].h -1 ) {
var h_1 = this.tierImageSize[z].h % this.standardTileSize;
if(h_1 != 0)
h = h_1;
}
return (new OpenLayers.Size(w, h));
} else {
return this.tileSize;
}
},
setMap: function(map) {
OpenLayers.Layer.Grid.prototype.setMap.apply(this, arguments);
this.tileOrigin = new OpenLayers.LonLat(this.map.maxExtent.left,
this.map.maxExtent.top);
},
CLASS_NAME: "OpenLayers.Layer.ABCLayer"
});