openlayers加载天地图代码
2015-03-25 09:33
429 查看
基于openlayers扩展,加载天地图数据源。
首先是TDTLayer.js文件
调用方法(可能有些废代码,但是效果能出来)
效果如下
首先是TDTLayer.js文件
OpenLayers.Layer.TDTServer = [ "http://tile0.tianditu.com/DataServer?", "http://tile1.tianditu.com/DataServer?", "http://tile2.tianditu.com/DataServer?", "http://tile3.tianditu.com/DataServer?", "http://tile4.tianditu.com/DataServer?", "http://tile5.tianditu.com/DataServer?", "http://tile6.tianditu.com/DataServer?", "http://tile7.tianditu.com/DataServer?" ]; OpenLayers.Layer.TDTLayer = OpenLayers.Class(OpenLayers.Layer.Grid, { isBaseLayer: true, zoomOffset: 2, //0.3515625, //maxResolution: 0.3515625, //maxResolution: 360 / 256, format: 'image/png', initialize: function(name, url, layername, options) { this.layername = layername; OpenLayers.Layer.Grid.prototype.initialize.apply(this, [name, url, {}, options]); }, clone: function (obj) { if (obj == null) { obj = new OpenLayers.Layer.TDTLayer(this.name, this.url, this.layername, this.getOptions()); } obj = OpenLayers.Layer.Grid.prototype.clone.apply(this, [obj]); return obj; }, getLayerName: function(tileZ){ return this.layername; }, getURL: function(bounds) { var res = this.map.getResolution(); var tileX = Math.round((bounds.left - this.maxExtent.left) / (res * this.tileSize.w)); var tileY = Math.round((this.maxExtent.top - bounds.top) / (res * this.tileSize.h)); var tileZ = this.map.getZoom() + this.zoomOffset; var path = OpenLayers.String.format("T=${T}&X=${X}&Y=${Y}&L=${L}", {'T': this.getLayerName(tileZ),'X': tileX, 'Y': tileY, 'L': tileZ}); var url = this.url; if (url instanceof Array) { url = this.selectUrl(path, url); } return url + path; }, addTile:function(bounds, position) { var url = this.getURL(bounds); return new OpenLayers.Tile.Image(this, position, bounds, url, this.tileSize); }, CLASS_NAME: "OpenLayers.Layer.TDTLayer" }); function calcResolutions (lvstart, lvend){ var maxResolution = 360 / 256; var res = new Array(); for(var i=lvstart; i<=lvend; i++){ res.push( maxResolution / Math.pow( 2, i)); } return res; }; /* 天地图全球遥感数据 */ OpenLayers.Layer.TDTRSLayer = OpenLayers.Class(OpenLayers.Layer.TDTLayer, { labelLayer: null, initialize: function(name, options) { // var levels = 18 || options.levels; options = OpenLayers.Util.extend({ projection: "EPSG:4326" // resolutions: calcResolutions(2, levels) }, options); OpenLayers.Layer.TDTLayer.prototype.initialize.apply(this, [name, OpenLayers.Layer.TDTServer, null, options]); }, setVisibility: function(visible){ OpenLayers.Layer.TDTLayer.prototype.setVisibility.apply(this, [visible]); if(this.showLabel){ this.showLabelLayer(visible); } }, showLabelLayer: function(visible){ if(!this.labelLayer && this.map){ this.labelLayer= new OpenLayers.Layer.TDTRSDMLayer("Label",{ isBaseLayer : false, singleTile : false , displayInLayerSwitcher: false }); this.map.addLayer(this.labelLayer); } this.labelLayer.setVisibility(visible 4000 ); }, getLayerName: function(tileZ){ if(tileZ >= 0 && tileZ <= 10){ return "sbsm0210";//http://tile0.tianditu.com/services/sbsm0210/GetCapabilities } else if(tileZ >= 11 && tileZ <= 13){ return "e" + tileZ; //http://tile0.tianditu.com/services/e11/GetCapabilities //http://tile0.tianditu.com/services/e12/GetCapabilities //http://tile0.tianditu.com/services/e12/GetCapabilities } else if(tileZ == 14){ return "eastdawnall"; //http://tile0.tianditu.com/services/eastdawnall/GetCapabilities } else if(tileZ >= 15 && tileZ <= 18){ return "sbsm1518"; //http://tile0.tianditu.com/services/sbsm1518/GetCapabilities //return "AP0115_SWHK"; //http://tile0.tianditu.com/services/AP0115_SWHK/GetCapabilities } return this.layername; }, clone: function (obj) { if (obj == null) { obj = new OpenLayers.Layer.TDTRSLayer(this.name, this.getOptions()); } obj = OpenLayers.Layer.TDTLayer.prototype.clone.apply(this, [obj]); return obj; }, CLASS_NAME: "OpenLayers.Layer.TDTRSLayer" }); /* 天地图影像地名数据 */ OpenLayers.Layer.TDTRSDMLayer = OpenLayers.Class(OpenLayers.Layer.TDTLayer, { initialize: function(name, options) { //var levels = 18 || options.levels; options = OpenLayers.Util.extend({ projection: "EPSG:4326" //resolutions: calcResolutions(2, levels) }, options); OpenLayers.Layer.TDTLayer.prototype.initialize.apply(this, [name, OpenLayers.Layer.TDTServer, null, options]); }, getLayerName: function(tileZ){ //1-10 //http://tile0.tianditu.com/services/AB0512_Anno/GetCapabilities //中文地名注记 //1-10 //http://tile0.tianditu.com/services/AB0106_AnnoE/GetCapabilities //英文地名注记 if(tileZ >= 1 && tileZ <= 10){ return "A0610_ImgAnno"; //1-10 //http://tile0.tianditu.com/services/A0610_ImgAnno/GetCapabilities //中文地名注记 //1-10 //http://tile0.tianditu.com/services/A0104_ImgAnnoE/GetCapabilities //英文地名注记 } else if(tileZ >= 11 && tileZ <= 14){ return "B0530_eImgAnno"; } else if(tileZ >= 15 && tileZ <= 18){ return "siweiAnno68"; } //11-14 //http://tile0.tianditu.com/services/B0530_eImgAnno/GetCapabilities //15-18 //http://tile0.tianditu.com/services/siweiAnno68/GetCapabilities return this.layername; }, clone: function (obj) { if (obj == null) { obj = new OpenLayers.Layer.TDTRSDMLayer(this.name, this.getOptions()); } obj = OpenLayers.Layer.TDTLayer.prototype.clone.apply(this, [obj]); return obj; }, CLASS_NAME: "OpenLayers.Layer.TDTRSDMLayer" }); /* 天地图区划地名数据 */ OpenLayers.Layer.TDTQHDMLayer = OpenLayers.Class(OpenLayers.Layer.TDTLayer, { initialize: function(name, options) { //var levels = 10 || options.levels; options = OpenLayers.Util.extend({ projection: "EPSG:4326" // resolutions: calcResolutions(2, levels) }, options); OpenLayers.Layer.TDTLayer.prototype.initialize.apply(this, [name, OpenLayers.Layer.TDTServer, null, options]); }, getLayerName: function(tileZ){ //1-10 //http://tile0.tianditu.com/services/AB0512_Anno/GetCapabilities //中文地名注记 //1-10 //http://tile0.tianditu.com/services/AB0106_AnnoE/GetCapabilities //英文地名注记 if(tileZ >= 1 && tileZ <= 10){ return "A0610_ImgAnno"; //1-10 //http://tile0.tianditu.com/services/A0610_ImgAnno/GetCapabilities //中文地名注记 //1-10 //http://tile0.tianditu.com/services/A0104_ImgAnnoE/GetCapabilities //英文地名注记 }/* else if(tileZ >= 11 && tileZ <= 14){ return "B0530_eImgAnno"; } else if(tileZ >= 15 && tileZ <= 18){ return "siweiAnno68"; } */ //11-14 //http://tile0.tianditu.com/services/B0530_eImgAnno/GetCapabilities //15-18 //http://tile0.tianditu.com/services/siweiAnno68/GetCapabilities return this.layername; }, clone: function (obj) { if (obj == null) { obj = new OpenLayers.Layer.TDTDMLayer(this.name, this.getOptions()); } obj = OpenLayers.Layer.TDTLayer.prototype.clone.apply(this, [obj]); return obj; }, CLASS_NAME: "OpenLayers.Layer.TDTQHDMLayer" }); /* 天地图全球区划数据 */ OpenLayers.Layer.TDTQHLayer = OpenLayers.Class(OpenLayers.Layer.TDTLayer, { labelLayer: null, initialize: function(name, options) { // var levels = 18 || options.levels; options = OpenLayers.Util.extend({ projection: "EPSG:4326" // resolutions: calcResolutions(2, levels) }, options); OpenLayers.Layer.TDTLayer.prototype.initialize.apply(this, [name, OpenLayers.Layer.TDTServer, null, options]); }, setVisibility: function(visible){ OpenLayers.Layer.TDTLayer.prototype.setVisibility.apply(this, [visible]); if(this.showLabel){ this.showLabelLayer(visible); } }, showLabelLayer: function(visible){ if(!this.labelLayer && this.map){ this.labelLayer= new OpenLayers.Layer.TDTQHDMLayer("Label",{ isBaseLayer : false, singleTile : false , displayInLayerSwitcher: false }); this.map.addLayer(this.labelLayer); } this.labelLayer.setVisibility(visible); }, getLayerName: function(tileZ){ if(tileZ >= 1 && tileZ <= 10){ return "A0512_EMap"; } else if(tileZ >= 11 && tileZ <= 12){ return "B0627_EMap1112"; } else if(tileZ >= 13 && tileZ <= 18){ return "siwei0608"; } //1-10 //http://tile0.tianditu.com/services/A0512_EMap/GetCapabilities //11-12 //http://tile0.tianditu.com/services/B0627_EMap1112/GetCapabilities //13-18 //http://tile0.tianditu.com/services/siwei0608/GetCapabilities return this.layername; }, clone: function (obj) { if (obj == null) { obj = new OpenLayers.Layer.TDTQHLayer(this.name, this.getOptions()); } obj = OpenLayers.Layer.TDTLayer.prototype.clone.apply(this, [obj]); return obj; }, CLASS_NAME: "OpenLayers.Layer.TDTQHLayer" });
调用方法(可能有些废代码,但是效果能出来)
map = new OpenLayers.Map(mapdiv, mapOptions); map.tlayer = new OpenLayers.Layer.TDTLayer("影像图", "http://t5.tianditu.com/DataServer?" ,'vec_c', { topLevel: 1, bottomLevel: 18, //maxExtent: (new OpenLayers.Bounds(-180, -90, 180, 90)).transform(new OpenLayers.Projection("EPSG:4326"),map.getProjectionObject()), mirrorUrls:["http://t0.tianditu.com/DataServer","http://t1.tianditu.com/DataServer","http://t2.tianditu.com/DataServer","http://t3.tianditu.com/DataServer","http://t4.tianditu.com/DataServer","http://t5.tianditu.com/DataServer","http://t6.tianditu.com/DataServer","http://t7.tianditu.com/DataServer"], isBaseLayer : true, }); map.addLayer(map.tlayer);
效果如下
相关文章推荐
- [置顶] OpenLayers 3 之 加载天地图
- Openlayers加载腾讯、高德、天地图
- 可扩展的world wind 加载谷歌、天地图、必应地图等等的代码
- Openlayers离线加载天地图
- OpenLayers 加载山东天地图(WMTS)
- (转)Openlayers 2.X加载天地图
- openlayers加载天地图WMTS服务
- OpenLayers 3 之 加载天地图
- Openlayers3加载天地图
- OpenLayers 3 加载WMTS天地图
- Openlayers3加载天地图
- 使用openlayers 3 在线加载天地图及GeoServer发布的地图
- Openlayers 2.X加载天地图
- Openlayers离线加载天地图
- arcgis api for javascript v3.21加载天地图代码示例
- Code maturity level options 代码成熟度选项 [*]Prompt for development and/or incomplete code/drivers 显示尚在开发中或尚未完成的代码与驱动.除非你是测试人员或者开发者,否则请勿选择 我是开发者,所以选[*] Loadable module support 可加载模块支持 [*]Enable loadable module support 内核编译配置选项简介 (2.4.20-8
- flash加载图片代码
- IE和Firefox中的dom加载完成执行代码(defer)
- 页面加载完成再执行js代码
- 在安装 Windows 过程中出现“Ntkrnlmp.exe Could Not Be Loaded. The Error Code Is 7”(无法加载 Ntkrnlmp.exe。错误代码是 7)错误消息