cesium 加载4490坐标系

1.修改 ArcGisMapServerImageryProvider.js 源码

读取切片元数据时增加支持 wkid 4490 坐标系的判断,同时将切片信息也传

1
2
3
4
5
6
7
if (data.fullExtent.spatialReference.wkid === 4490) {
that._tilingScheme = new GeographicTilingScheme({
ellipsoid: imageryProviderBuilder.ellipsoid,
tileInfo: data.tileInfo, // 传入tileInfo,用于后面GeographicTilingScheme的计算
});
//SmartEarth 修改
}

fullExtent 范围增加 wkid 4490 坐标系判断

1
2
3
4
5
6
7
8
9
10
11
if (data.fullExtent.spatialReference.wkid === 4490) {
/** Geoworld Add **/
// SmartEarth 修改
that._rectangle = Rectangle.fromDegrees(
data.fullExtent.xmin,
data.fullExtent.ymin,
data.fullExtent.xmax,
data.fullExtent.ymax
);
// SmartEarth 修改
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
function metadataSuccess(data, imageryProviderBuilder) {
const tileInfo = data.tileInfo;
if (!defined(tileInfo)) {
imageryProviderBuilder.useTiles = false;
} else {
imageryProviderBuilder.tileWidth = tileInfo.rows;
imageryProviderBuilder.tileHeight = tileInfo.cols;

if (tileInfo.spatialReference.wkid === 102100 || tileInfo.spatialReference.wkid === 102113) {
imageryProviderBuilder.tilingScheme = new WebMercatorTilingScheme({
ellipsoid: imageryProviderBuilder.ellipsoid,
});
} else if (data.tileInfo.spatialReference.wkid === 4326) {
imageryProviderBuilder.tilingScheme = new GeographicTilingScheme({
ellipsoid: imageryProviderBuilder.ellipsoid,
});
/** Geoworld **/
//SmartEarth 修改
} else if (data.fullExtent.spatialReference.wkid === 4490) {
that._tilingScheme = new GeographicTilingScheme({
ellipsoid: imageryProviderBuilder.ellipsoid,
tileInfo: data.tileInfo, // 传入tileInfo,用于后面GeographicTilingScheme的计算
});
//SmartEarth 修改
} else {
const message = `Tile spatial reference WKID ${data.tileInfo.spatialReference.wkid} is not supported.`;
throw new RuntimeError(message);
}
imageryProviderBuilder.maximumLevel = data.tileInfo.lods.length - 1;

if (defined(data.fullExtent)) {
if (
defined(data.fullExtent.spatialReference) &&
defined(data.fullExtent.spatialReference.wkid)
) {
if (
data.fullExtent.spatialReference.wkid === 102100 ||
data.fullExtent.spatialReference.wkid === 102113
) {
const projection = new WebMercatorProjection();
const extent = data.fullExtent;
const sw = projection.unproject(
new Cartesian3(
Math.max(
extent.xmin,
-imageryProviderBuilder.tilingScheme.ellipsoid.maximumRadius * Math.PI
),
Math.max(
extent.ymin,
-imageryProviderBuilder.tilingScheme.ellipsoid.maximumRadius * Math.PI
),
0.0
)
);
const ne = projection.unproject(
new Cartesian3(
Math.min(
extent.xmax,
imageryProviderBuilder.tilingScheme.ellipsoid.maximumRadius * Math.PI
),
Math.min(
extent.ymax,
imageryProviderBuilder.tilingScheme.ellipsoid.maximumRadius * Math.PI
),
0.0
)
);
imageryProviderBuilder.rectangle = new Rectangle(
sw.longitude,
sw.latitude,
ne.longitude,
ne.latitude
);
} else if (data.fullExtent.spatialReference.wkid === 4326) {
imageryProviderBuilder.rectangle = Rectangle.fromDegrees(
data.fullExtent.xmin,
data.fullExtent.ymin,
data.fullExtent.xmax,
data.fullExtent.ymax
);
} else if (data.fullExtent.spatialReference.wkid === 4490) {
/** Geoworld Add **/
// SmartEarth 修改
that._rectangle = Rectangle.fromDegrees(
data.fullExtent.xmin,
data.fullExtent.ymin,
data.fullExtent.xmax,
data.fullExtent.ymax
);
// SmartEarth 修改
} else {
const extentMessage = `fullExtent.spatialReference WKID ${data.fullExtent.spatialReference.wkid} is not supported.`;
throw new RuntimeError(extentMessage);
}
}
} else {
imageryProviderBuilder.rectangle = imageryProviderBuilder.tilingScheme.rectangle;
}

imageryProviderBuilder.useTiles = true;
}

if (defined(data.copyrightText) && data.copyrightText.length > 0) {
if (defined(imageryProviderBuilder.credit)) {
imageryProviderBuilder.tileCredits = [new Credit(data.copyrightText)];
} else {
imageryProviderBuilder.credit = new Credit(data.copyrightText);
}
}
}

2.修改 GeographicTilingScheme 类

1
2
3
4
/** Geoworld Add **/
//SmartEarth 修改
this._tileInfo = options.tileInfo;
//SmartEarth 修改

修改切片矩阵计算获取行列号 xy 值的原型方法 getNumberOfXTilesAtLevel 和 getNumberOfYTilesAtLevel

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
GeographicTilingScheme.prototype.getNumberOfXTilesAtLevel = function (level) {
// return this._numberOfLevelZeroTilesX << level;
/** Geoworld Add **/
//SmartEarth 修改
if (!defined(this._tileInfo)) {
return this._numberOfLevelZeroTilesX << level;
}
const currentMatrix = this._tileInfo.lods.filter(function (item) {
return item.level === level;
});
const currentResolution = currentMatrix[0].resolution;
return Math.round(360 / (this._tileInfo.rows * currentResolution));
//SmartEarth 修改
};

/**
* 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) {
// return this._numberOfLevelZeroTilesY << level;
//SmartEarth 修改
if (!defined(this._tileInfo)) {
return this._numberOfLevelZeroTilesY << level;
}
// 使用切片矩阵计算
const currentMatrix = this._tileInfo.lods.filter(function (item) {
return item.level === level;
});
const currentResolution = currentMatrix[0].resolution;
return Math.round(180 / (this._tileInfo.cols * currentResolution));
//SmartEarth 修改
};

3.修改 Ellipsoid 类,定义 2000 椭球参数

1
2
3
4
5
6
7
8
9
10
11
/**
* An Ellipsoid instance initialized to the CGCS2000 standard.
*
* @type {Ellipsoid}
* @constant
*/
/** Geoworld Add **/
Ellipsoid.CGCS2000 = Object.freeze(
// eslint-disable-next-line no-loss-of-precision
new Ellipsoid(6378137.0, 6378137.0, 6356752.31414035585)
);

使用

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
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),
});
作者

wangyawei

发布于

2025-03-21

更新于

2025-03-21

许可协议