1、添加wms服务,以国家天地图网站的wms服务为例:
function AddWMSLayer(LayerName,$this) {
var _WMSUrl = "http://zhfw.tianditu.com/gisserver/ZHFW/wms";
var layerGroup = SGWorld65.ProjectTree.FindItem("Layers");
if (layerGroup == "")
layerGroup = SGWorld65.ProjectTree.CreateGroup("Layers", "");
if (LayerName != null && LayerName != "") {
var itemidlayer = SGWorld65.ProjectTree.FindItem("Layers\\" + LayerName);
if (itemidlayer != "")
SGWorld65.ProjectTree.DeleteItem(itemidlayer);
var wmsStr = "[INFO]\rMPP=0.00000703125\rUrl=" + _WMSUrl + "?request=GetMap&Version=1.1.1&Service=WMS&SRS=EPSG:4326&BBOX=-180,-90,180,90&HEIGHT=512&WIDTH=1024&Layers=" + LayerName + "&Format=image/png";
var imagelayer = SGWorld65.Creator.CreateImageryLayer(LayerName, -180, 90, 180, -90, " + wmsStr + "]]> wms ", "gisplg.rct", layerGroup, "全国行政边界线");
imagelayer.UseNull = true;
imagelayer.NullValue = 0xffffff;
imagelayer.NullTolerance = 50;
imagelayer.FillStyle.Color.SetAlpha(0.6);
$this.attr("data-type",imagelayer.ID);
}
}
2、添加wmts服务,以国家天地图瓦片为例:
function AddWMTSLayer(type,$this){
if(!type){type="img";}
var ts = Math.floor(1+Math.random()*7);//随机请求天地图服务器,避免使用单一服务器导致持续性挂载
var wmtsBuffer = "[INFO]\r\nProtocolType=3\r\nMeters=0\r\nMPP=2.6822090148925781e-006\r\n"
+ "Url=http://t"+ts+".tianditu.com/"+type+"_c/wmts?request=GetTile&Version=1.0.0&Service=WMTS&Layer="+type+"&Style=default&Format=tiles&TileMatrixSet=c&TileMatrix=1&TileRow=0&TileCol=0\r\n"
+ "Layers="+type+"\r\nCapabilitiesUrl=http://t"+ts+".tianditu.com/"+type+"_c/wmts?\r\nxul=-180\r\nylr=-90\r\nxlr=180\r\nyul=90\r\nWMSCoordSys=urn:ogc:def:crs:EPSG::4490\r\n"
+ "WKT=GEOGCS[\"China Geodetic Coordinate System 2000\",DATUM[\"China_2000\",SPHEROID[\"CGCS2000\",6378137,298.257222101,AUTHORITY[\"EPSG\",\"1024\"]],AUTHORITY[\"EPSG\",\"1043\"]],PRIMEM[\"Greenwich\",0,AUTHORITY[\"EPSG\",\"8901\"]],UNIT[\"degree\",0.0174532925199433,AUTHORITY[\"EPSG\",\"9122\"]],AXIS[\"Latitude\",NORTH],AXIS[\"Longitude\",EAST],AUTHORITY[\"EPSG\",\"4490\"]]\r\n"
+ "TileInfo=00000395Ezrv.vR......A.A......A.....................2.l.....f...1V.V#f##3##lD#nC.....A.A......C..........A..........2.l.....f...1V.V#f##3##VD#pC.....A.A......G..........C..........2.l.....f...1V.V#f##3##FD#rC.....A.A......O..........G..........2.l.....f...1V.V#f##m##2D#tC.....A.A......e..........O..........2.l.....f...1V.V#f##m##lD#vC.....A.A......#..........e..........2.l.....f...1V.V#f##m##VD#xC.....A.A....D.#..........#..........2.l.....f...1V.W#f##m##FD#zC.....A.A....L.#.........A#..........2.l.....f...1V.W#f##W##2D#2C.....A.A....L.#A........C#..........2.l.....f...1V.W#f##W##lD#4C.....A.A....L.#C........C#A.........2.l.....f...1V.W#f##W##VD#6C.....A.A....L.#G........C#C.........2.l.....f...1V.W#f##W##FD#9C.....A.A....L.#O........C#G.........2.l.....f...1V.W#f##G##2H#.C.....A.A....L.#e........C#O.........2.l.....f...1V.W#f##G##lH#CC.....A.A....L.##........C#e.........2.l.....f...1V.W#f##G##VH#FC.....A.A....b.##........C##.........2.l.....f...1V.W#f##G##FH#IC.....A.A....8.##........G##.........2.l.....f...1V.W#f##3##2H0LC.....A.A....8.##.A......O##.........2.l.....f...1V.W#f##3##lH0OC.....A.A....8.##.C......O##A........2.l.....f...1V.V#f##3##VH0RC...w..x..y.z..1..2.3..4..5.w.v.w.w.w.x.w.y.w.z.w.1.w.2.w.3.w.4..\r\n";
var imagelayer = SGWorld65.Creator.CreateImageryLayer(type, -180, 90, 179.99999999954656, -89.99999999977328, "[ CDATA[" + wmtsBuffer + "]]>wmts ", "gisplg.rct", "", "天地图wmts服务");
$this.attr("data-type",imagelayer.ID);
}
其中的TileInfo不是乱码,是使用Skyline TerraBuilder浏览在线天地图时输出到配置文件中的瓦片服务参数信息,操作比较简单请自行研究。如果直接使用天地图瓦片,完全用我上面的示例就行。