Arcgis Server api for javascript加载天地图(转)
Posted on 2013-08-23 17:38 tianya10319 阅读(1811) 评论(0) 编辑 收藏 举报原理
在API中,使用ArcGISTileMapServiceLayer 来加载瓦片地图,除了天地图之外,GOOGLE和BING的地图也采用这种方法进行加载。使用该地图类型加载,需要对几个地方进行修改:
1、空间坐标系(this.spatialReference)
2、地图范围(this.initialExtent)
3、瓦片地图信息(this.tileInfo),这里需要对 esri.layers.TileInfo进行定义。其中包括了瓦片行列的数量("rows“,“clos”),坐标系("spatialreference"),不同等级的比例尺("lods")
4.重写getTileUrl方法,以便API正确的获取所需的瓦片。
天地图分析(转载自http://www.giser.net/?p=119)
天地图是中国区域内数据资源最全的地理信息服务网站,同时将为公众提供权威、可信、统一的地理信息服务,在我国的公共服务平台建设中将起到重要作用,那么为了在其他系统中使用天地图的地图服务,就很有必要对天地图的切图schema研究一番。
下面就把天地图切图schema的主要参数列举一下:
1 参考系 :wgs84 (4326)
2 切图原点(-180,90)
3 切图范围(-180,-90,180,90)
4 切图级别18级,比例尺和分辨率分别为:
{“level” : 1, “resolution” : 0.3515625, “scale” : 147748799.285417},
{“level” : 2, “resolution” : 0.17578125, “scale” : 73874399.6427087},
{“level” : 3, “resolution” : 0.087890625, “scale” : 36937199.8213544},
{“level” : 4, “resolution” : 0.0439453125, “scale” : 18468599.9106772},
{“level” : 5, “resolution” : 0.02197265625, “scale” : 9234299.95533859},
{“level” : 6, “resolution” : 0.010986328125, “scale” : 4617149.97766929},
{“level” : 7, “resolution” : 0.0054931640625, “scale” : 2308574.98883465},
{“level” : 8, “resolution” : 0.00274658203125, “scale” : 1154287.49441732},
{“level” : 9, “resolution” : 0.001373291015625, “scale” : 577143.747208662},
{“level” : 10, “resolution” : 0.0006866455078125, “scale” : 288571.873604331},
{“level” : 11, “resolution” : 0.00034332275390625, “scale” : 144285.936802165},
{“level” : 12, “resolution” : 0.000171661376953125, “scale” : 72142.9684010827},
{“level” : 13, “resolution” : 8.58306884765629E-05, “scale” : 36071.4842005414},
{“level” : 14, “resolution” : 4.29153442382814E-05, “scale” : 18035.7421002707},
{“level” : 15, “resolution” : 2.14576721191407E-05, “scale” : 9017.87105013534},
{“level” : 16, “resolution” : 1.07288360595703E-05, “scale” : 4508.93552506767},
{“level” : 17, “resolution” : 5.36441802978515E-06, “scale” : 2254.467762533835},
{“level” : 18, “resolution” : 2.68220901489258E-06, “scale” : 1127.2338812669175}
5 切图参数:
格式:png
大小:256*256
dpi:96
6 服务器个数:8个,分别为:
http://tile0.tianditu.com/
http://tile1.tianditu.com/
http://tile2.tianditu.com/
http://tile3.tianditu.com/
http://tile4.tianditu.com/
http://tile5.tianditu.com/
http://tile6.tianditu.com/
http://tile7.tianditu.com/
7 切片请求方式:REST
8 切片请求地址http://tile0.tianditu.com/DataServer?T=AB0512_Anno&X=1&Y=0&L=2
其中x为列数,y为行数,l为级别
代码(转载自http://www.cnblogs.com/gisvip/archive/2012/03/25/2417229.html)
dojo.declare(
"TDTLayer"
, esri.layers.TiledMapServiceLayer, {
constructor:
function
() {
this
.spatialReference =
new
esri.SpatialReference({ wkid:4326 });
this
.initialExtent = (
this
.fullExtent =
new
esri.geometry.Extent(-180.0, -90.0, 180.0, 90.0,
this
.spatialReference));
this
.tileInfo =
new
esri.layers.TileInfo({
"rows"
: 256,
"cols"
: 256,
"compressionQuality"
: 0,
"origin"
: {
"x"
: -180,
"y"
: 90
},
"spatialReference"
: {
"wkid"
: 4326
},
"lods"
: [
{
"level"
: 0,
"resolution"
: 0.703125,
"scale"
: 295497593.05875003},
{
"level"
: 1,
"resolution"
: 0.3515625,
"scale"
: 147748796.52937502},
{
"level"
: 2,
"resolution"
: 0.17578125,
"scale"
: 73874398.264687508},
{
"level"
: 3,
"resolution"
: 0.087890625,
"scale"
: 36937199.132343754},
{
"level"
: 4,
"resolution"
: 0.0439453125,
"scale"
: 18468599.566171877},
{
"level"
: 5,
"resolution"
: 0.02197265625,
"scale"
: 9234299.7830859385},
{
"level"
: 6,
"resolution"
: 0.010986328125,
"scale"
: 4617149.8915429693},
{
"level"
: 7,
"resolution"
: 0.0054931640625,
"scale"
: 2308574.9457714846},
{
"level"
: 8,
"resolution"
: 0.00274658203125,
"scale"
: 1154287.4728857423},
{
"level"
: 9,
"resolution"
: 0.001373291015625,
"scale"
: 577143.73644287116},
{
"level"
: 10,
"resolution"
: 0.0006866455078125,
"scale"
: 288571.86822143558},
{
"level"
: 11,
"resolution"
: 0.00034332275390625,
"scale"
: 144285.93411071779},
{
"level"
: 12,
"resolution"
: 0.000171661376953125,
"scale"
: 72142.967055358895},
{
"level"
: 13,
"resolution"
: 8.58306884765625e-005,
"scale"
: 36071.483527679447},
{
"level"
: 14,
"resolution"
: 4.291534423828125e-005,
"scale"
: 18035.741763839724},
{
"level"
: 15,
"resolution"
: 2.1457672119140625e-005,
"scale"
: 9017.8708819198619},
{
"level"
: 16,
"resolution"
: 1.0728836059570313e-005,
"scale"
: 4508.9354409599309},
{
"level"
: 17,
"resolution"
: 5.3644180297851563e-006,
"scale"
: 2254.4677204799655}
]
});
this
.loaded =
true
;
this
.onLoad(
this
);
},
getTileUrl:
function
(level, row, col) {
var
levelMap =
""
;
if
(level<10){
levelMap =
"A0512_EMap"
;
}
else
if
(level<12){
levelMap =
"B0627_EMap1112"
;
}
else
if
(level<17){
levelMap =
"siwei0608"
;
}
"X="
+ col +
"&"
+
"Y="
+ row +
"&"
+
"L="
+ (level*1+1);
}
});
dojo.declare(
"TDTAnnoLayer"
, esri.layers.TiledMapServiceLayer, {
constructor:
function
() {
this
.spatialReference =
new
esri.SpatialReference({ wkid:4326 });
this
.initialExtent = (
this
.fullExtent =
new
esri.geometry.Extent(-180.0, -90.0, 180.0, 90.0,
this
.spatialReference));
this
.tileInfo =
new
esri.layers.TileInfo({
"rows"
: 256,
"cols"
: 256,
"compressionQuality"
: 0,
"origin"
: {
"x"
: -180,
"y"
: 90
},
"spatialReference"
: {
"wkid"
: 4326
},
"lods"
: [
{
"level"
: 0,
"resolution"
: 0.703125,
"scale"
: 295497593.05875003},
{
"level"
: 1,
"resolution"
: 0.3515625,
"scale"
: 147748796.52937502},
{
"level"
: 2,
"resolution"
: 0.17578125,
"scale"
: 73874398.264687508},
{
"level"
: 3,
"resolution"
: 0.087890625,
"scale"
: 36937199.132343754},
{
"level"
: 4,
"resolution"
: 0.0439453125,
"scale"
: 18468599.566171877},
{
"level"
: 5,
"resolution"
: 0.02197265625,
"scale"
: 9234299.7830859385},
{
"level"
: 6,
"resolution"
: 0.010986328125,
"scale"
: 4617149.8915429693},
{
"level"
: 7,
"resolution"
: 0.0054931640625,
"scale"
: 2308574.9457714846},
{
"level"
: 8,
"resolution"
: 0.00274658203125,
"scale"
: 1154287.4728857423},
{
"level"
: 9,
"resolution"
: 0.001373291015625,
"scale"
: 577143.73644287116},
{
"level"
: 10,
"resolution"
: 0.0006866455078125,
"scale"
: 288571.86822143558},
{
"level"
: 11,
"resolution"
: 0.00034332275390625,
"scale"
: 144285.93411071779},
{
"level"
: 12,
"resolution"
: 0.000171661376953125,
"scale"
: 72142.967055358895},
{
"level"
: 13,
"resolution"
: 8.58306884765625e-005,
"scale"
: 36071.483527679447},
{
"level"
: 14,
"resolution"
: 4.291534423828125e-005,
"scale"
: 18035.741763839724},
{
"level"
: 15,
"resolution"
: 2.1457672119140625e-005,
"scale"
: 9017.8708819198619},
{
"level"
: 16,
"resolution"
: 1.0728836059570313e-005,
"scale"
: 4508.9354409599309},
{
"level"
: 17,
"resolution"
: 5.3644180297851563e-006,
"scale"
: 2254.4677204799655}
]
});
this
.loaded =
true
;
this
.onLoad(
this
);
},
getTileUrl:
function
(level, row, col) {
"X="
+ col +
"&"
+
"Y="
+ row +
"&"
+
"L="
+ (level*1+1);
}
});
把以上代码保存为lib.layer.js
在要调用的页面加入引用
<script type="text/javascript" language="Javascript" src="lib.layer.js"></script>
在初始化函数中
var basemap = new TDTLayer();
var annolayer= new TDTAnnoLayer();
map.addLayer(basemap);
map.addLayer(annolayer);