需要加载利用arcgis for server 10.2发布的wkid为4490的瓦片图。
cesium版本号:1.58
1. cesium 加载arcgis瓦片图流程
1)创建ArcGisMapServerImageryProvider实例
ArcGisMapServerImageryProvider的_useTiles属性会被初始化为true;
2)通过json接口获取服务信息
在接口调用成功后,调用metadataSuccess(data)内部方法,在该方法中:
if (tileInfo.spatialReference.wkid === 102100 ||
tileInfo.spatialReference.wkid === 102113) {
that._tilingScheme = new WebMercatorTilingScheme({ ellipsoid : options.ellipsoid });
} else if (data.tileInfo.spatialReference.wkid === 4326) {
that._tilingScheme = new GeographicTilingScheme({ ellipsoid : options.ellipsoid });
} else if(data.fullExtent.spatialReference.wkid === 4490){
that._tilingScheme = new GeographicTilingScheme({
ellipsoid : options.ellipsoid,
tileInfo:data.tileInfo
});
}
3)buildImageResource方法创建切片信息
4)_tilingScheme计算要获取的切片的x,y和level
2. 修改ArcGisMapServerImageryProvider传入dataInfo
function metadataSuccess(data) {
var tileInfo = data.tileInfo;
if (!defined(tileInfo)) {
that._useTiles = false;
} else {
that._tileWidth = tileInfo.rows;
that._tileHeight = tileInfo.cols;
if (tileInfo.spatialReference.wkid === 102100 ||
tileInfo.spatialReference.wkid === 102113) {
that._tilingScheme = new WebMercatorTilingScheme({ ellipsoid : options.ellipsoid });
} else if (data.tileInfo.spatialReference.wkid === 4326) {
that._tilingScheme = new GeographicTilingScheme({ ellipsoid : options.ellipsoid });
} else if(data.fullExtent.spatialReference.wkid === 4490){
that._tilingScheme = new GeographicTilingScheme({
ellipsoid : options.ellipsoid,
tileInfo:data.tileInfo // 传入tileInfo,用于后面GeographicTilingScheme的计算
});
}
3. 修改GeographicTilingScheme使用切片矩阵计算x,y
GeographicTilingScheme.prototype.getNumberOfXTilesAtLevel = function(level) {
if (!defined(this._tileInfo)) {
return this._numberOfLevelZeroTilesX << level
} else { // 使用切片矩阵计算
var currentMatrix = this._tileInfo.lods.filter(function(item) {
return item.level === level
})
var currentResolution = currentMatrix[0].resolution
return Math.round(360 / (this._tileInfo.rows * currentResolution))
}
}
/**
* Gets the total number of tiles in the Y direction at a specified level-of-detail.
*
* @param {Number} level The level-of-detail.
* @returns {Number} The number of tiles in the Y direction at the given level.
*/
GeographicTilingScheme.prototype.getNumberOfYTilesAtLevel = function(level) {
if (!defined(this._tileInfo)) {
return this._numberOfLevelZeroTilesY << level
} else { // 使用切片矩阵计算
var currentMatrix = this._tileInfo.lods.filter(function(item) {
return item.level === level
})
var currentResolution = currentMatrix[0].resolution
return Math.round(180 / (this._tileInfo.cols * currentResolution))
}
}
3. 创建4490椭球体和切片方案
var cgs2000Ellipsolid = new Cesium.Ellipsoid(6378137.0, 6378137.0, 6356752.31414035585)
var myGeographicTilingScheme = new Cesium.GeographicTilingScheme({
ellipsoid: cgs2000Ellipsolid,
rectangle: Cesium.Rectangle.fromDegrees(-180, -90, 180, 90),
numberOfLevelZeroTilesX: 4,
numberOfLevelZeroTilesY: 2
})
var esriWMTS = new Cesium.ArcGisMapServerImageryProvider({
url: 'http://Ip:6080/arcgis/rest/services/jssl_vector_L3_L17/MapServer',
layer: 'jssl_vector_L3_L17',
tilingScheme: myGeographicTilingScheme,
rectangle: myRectangle,
minimumLevel: 0,
ellipsoid: cgs2000Ellipsolid,
maximumLevel: 14
})
var cgs2000GeographicProj = new Cesium.GeographicProjection(cgs2000Ellipsolid)
var viewer = new Cesium.Viewer('cesiumContainer', {
animation: false,
geocoder: false,
timeline: false,
navigationHelpButton: false,
baseLayerPicker: false,
mapProjection: cgs2000GeographicProj,
imageryProvider: esriWMTS
})
viewer.camera.flyTo({
destination: Cesium.Cartesian3.fromDegrees(119.56156642831284, 32.419457329767326, 272683)
})
这样就可以了