arcgis for js 3使用4490坐标系加载天地图

1,282 阅读2分钟

我以往使用arcgis for js 3.19加载天地图,使用的都是默认的坐标系:4326。现在因为客户提供的地图,都是4490的,没办法,只能全部使用4490,否则不同坐标系的图层,没办法叠在一起。

4490是CGCS2000坐标系的WKID,4326是WGS84的WKID。有关它们的区别与联系,请阅读尾部的参考文章。有说法称,4490比4326更适合我们多一些。

以下是加载天地图的完整代码,写成了arcgis插件的形式:

define(["dojo/_base/declare","esri/layers/tiled"],function(declare) {
	return declare(esri.layers.TiledMapServiceLayer, {
		constructor: function(path, option) {
			this.baseUrl = path;
			this.layerType = option ? option.mode : null;
			if(option.name){
				this.id = option.name;
			}
			this.tk = getTk(option);
			this.spatialReference = new esri.SpatialReference({
				wkid: 4490
			});
			this.initialExtent = (this.fullExtent = new esri.geometry.Extent(45.0, -27.0, 163.0,45.0,
				this.spatialReference));//中国及周边范围
			this.tileInfo = getTileInfo();
			this.loaded = true;
			this.onLoad(this);
			
			function getTk(option){
				var tk;
				
				if(option.tk){
					tk = option.tk;
				} else {
					console.error("欠缺天地图的TK!!!");
				}
				
				return tk;
			}
			function getTileInfo(){
				return new esri.layers.TileInfo({
					/*
						titleInfo可从图层中获取
					*/
					"dpi": 96,
					"rows": 256,
					"cols": 256,
					"compressionQuality": 0,
					"origin": {
						x: -180,
						y: 90
					},
					"spatialReference": {
						"wkid": 4490,
						"latestWkid": 4490
					},
					/*
						scale:比例尺 ,resolution:分辨率
					*/    
					"lods": [ 
						{ level: 0, resolution: 1.40625, scale: 590995197.14166909755553014475 },
						{
							"level": 1,
							"resolution": 0.7031250000000002,
							"scale": 2.9549759305875003E8
						},
						{
							"level": 2,
							"resolution": 0.3515625000000001,
							"scale": 1.4774879652937502E8
						},
						{
							"level": 3,
							"resolution": 0.17578125000000006,
							"scale": 7.387439826468751E7
						},
						{
							"level": 4,
							"resolution": 0.08789062500000003,
							"scale": 3.6937199132343754E7
						},
						{
							"level": 5,
							"resolution": 0.043945312500000014,
							"scale": 1.8468599566171877E7
						},
						{
							"level": 6,
							"resolution": 0.021972656250000007,
							"scale": 9234299.783085939
						},
						{
							"level": 7,
							"resolution": 0.010986328125000003,
							"scale": 4617149.891542969
						},
						{
							"level": 8,
							"resolution": 0.005493164062500002,
							"scale": 2308574.9457714846
						},
						{
							"level": 9,
							"resolution": 0.002746582031250001,
							"scale": 1154287.4728857423
						},
						{
							"level": 10,
							"resolution": 0.0013732910156250004,
							"scale": 577143.7364428712
						},
						{
							"level": 11,
							"resolution": 6.866455078125002E-4,
							"scale": 288571.8682214356
						},
						{
							"level": 12,
							"resolution": 3.433227539062501E-4,
							"scale": 144285.9341107178
						},
						{
							"level": 13,
							"resolution": 1.7166137695312505E-4,
							"scale": 72142.9670553589
						},
						{
							"level": 14,
							"resolution": 8.583068847656253E-5,
							"scale": 36071.48352767945
						},
						{
							"level": 15,
							"resolution": 4.2915344238281264E-5,
							"scale": 18035.741763839724
						},
						{
							"level": 16,
							"resolution": 2.1457672119140632E-5,
							"scale": 9017.870881919862
						},
						{
							"level": 17,
							"resolution": 1.0728836059570316E-5,
							"scale": 4508.935440959931
						},
						{
							"level": 18,
							"resolution": 5.364418029785158E-6,
							"scale": 2254.4677204799655
						}
					]
				});            
			}
		}, //end of constructor
		baseUrl: null,
		layerType: null,
		tk: null,
		id:null,
		getTileUrl: function (level, row, col) {
			return this.baseUrl 
				+ "?SERVICE=WMTS&REQUEST=GetTile&VERSION=1.0.0&STYLE=default&TILEMATRIXSET=c&FORMAT=tiles"
				+ "&LAYER=" + this.layerType 
				+ "&TILEMATRIX=" + level 
				+ "&TILEROW=" + row 
				+ "&TILECOL=" + col 
				+ "&tk=" + this.tk;
		}
	});
});

代码中,

"lods": [ 
			{ level: 0, resolution: 1.40625, scale: 590995197.14166909755553014475 },
			{
				"level": 1,
				"resolution": 0.7031250000000002,
				"scale": 2.9549759305875003E8
			},

这部分比较神秘。我也不能确定这是啥,但从许多4490图层的信息来看,这应该是一种类似地图切片的方案或比例尺之类。你看,以下是一幅4490坐标系的底图:
在这里插入图片描述
里面的数字与代码中是一样的。不过它的Level 0对应了代码中的Level 1。只有代码中这样设置,天地图才能加载得出来。不清楚是什么原因。也许当前(2021年4月)版本的天地图就是这样子的。

参考文章
GIS开发扫盲贴–地理坐标系

wkid=4326, 4490,cgcs2000,坐标系总结(高德爬取的坐标叠加到84上是什么样)