扩展TiledMapServiceLayer agslib 是免费的可以进行扩张,加载天地图、google地图,geoserver wmts服务。
1.重载TiledMapServiceLayer接口类实现geoserver wmts瓦片地图的加载
package com.components { import com.esri.ags.SpatialReference; import com.esri.ags.Units; import com.esri.ags.geometry.Extent; import com.esri.ags.geometry.MapPoint; import com.esri.ags.layers.TiledMapServiceLayer; import com.esri.ags.layers.supportClasses.LOD; import com.esri.ags.layers.supportClasses.TileInfo; import flash.net.URLRequest; import mx.collections.ArrayCollection; import mx.controls.Alert; import mx.rpc.events.FaultEvent; import mx.rpc.events.ResultEvent; import mx.rpc.http.HTTPService; /** * WMTSLayer */ public class WMTSLayer extends TiledMapServiceLayer { public var gridset:String = ""; public var layer:String = ""; public var _baseURL:String = "http://192.168.1.1:8083/geoserver/gwc/service/wmts"; public var xmin:Number = 122.85820097944764; public var ymin:Number = 34.41033139891784; public var xmax:Number = 149.85820097944764; public var ymax:Number = 48.41033139891784; public var _tileInfo:TileInfo = new TileInfo(); public function WMTSLayer() { super(); buildTileInfo(); setLoaded(true); // Map will only use loaded layers } private var _fullExtent:Extent = new Extent( 147.85820097944764,34.41033139891784,149.85820097944764,48.41033139891784, new SpatialReference(4326)); /** * @private */ override public function get fullExtent():Extent { return _fullExtent; } private var _initialExtent:Extent = new Extent( 122.85820097944764,34.41033139891784,149.85820097944764,48.41033139891784, new SpatialReference(4326)); /** * @private */ override public function get initialExtent():Extent { return _initialExtent; } private var _spatialReference:SpatialReference = new SpatialReference(4326); override public function get spatialReference():SpatialReference { return _spatialReference; } /** * @private */ override public function get tileInfo():TileInfo { return _tileInfo; } override public function get units():String { return Units.DECIMAL_DEGREES; } override protected function getTileURL(level:Number, row:Number, col:Number):URLRequest { var url:String = _baseURL + "?SERVICE=WMTS&VERSION=1.0.0&REQUEST=GetTile" + "&LAYER=mywork:mygroup" + "&STYLE=null" + "&FORMAT=image/jpeg" + "&TILEMATRIXSET=myGridset" + "&TILEMATRIX=myGridset:" + level + "&TILEROW=" + row + "&TILECOL=" + col ; return new URLRequest(url); } public function buildTileInfo():void { _tileInfo.dpi = 96; _tileInfo.spatialReference = new SpatialReference(4326); _tileInfo.height = 256; _tileInfo.width = 256; _tileInfo.format = "image/jpeg"; _tileInfo.origin = new MapPoint(117.85820097944764,38.41033139891784);// map origin = new MapPoint(xmin,ymax) _tileInfo.lods= [ //通过设置geoserver 的gridset 可以获取 根据bounds生成 new LOD(0,0.0078125,3106012.5779373213), new LOD(1,0.00390625,1553006.2889686606), new LOD(2,0.001953125,776503.1444843303), new LOD(3,0.0009765625,388251.57224216516), new LOD(4,0.00048828125,194125.78612108258), new LOD(5,0.000244140625,97062.89306054129), new LOD(6,0.0001220703125,48531.446530270645), new LOD(7,0.00006103515625,24265.723265135322), new LOD(8,0.000030517578125,12132.861632567661), new LOD(9,0.0000152587890625,6066.430816283831), new LOD(10,0.0000076293945312,3033.2154081220365), new LOD(11,0.0000038146972656,1516.6077040610182), new LOD(12,0.0000019073486328,758.3038520305091), new LOD(13,0.0000009536743164,379.15192601525456) //中国地图 // new LOD(0,0.02197265625,8735660.375448715), // new LOD(1,0.010986328125,4367830.1877243575), // new LOD(2,0.0054931640625,2183915.0938621787), // new LOD(3,0.00274658203125,1091957.5469310894), // new LOD(4,0.001373291015625,545978.7734655447), // new LOD(5,0.0006866455078125,272989.38673277234), // new LOD(6,0.0003433227539062,136494.69336638617), // new LOD(7,0.0001716613769531,68247.34668319309), // new LOD(8,0.0000858306884766,34123.67334159654), // new LOD(9,0.0000429153442383,17061.83667079827), // new LOD(10,0.0000214576721191,8530.918335399136), // new LOD(11,0.0000107288360596,4265.459167699568), // new LOD(12,0.0000053644180298,2132.729583849784), // new LOD(13,0.0000026822090149,1066.364791924892) ]; } } }
2.重载TiledMapServiceLayer接口类实现google地图的加载
import com.esri.ags.SpatialReference; import com.esri.ags.geometry.Extent; import com.esri.ags.geometry.MapPoint; import com.esri.ags.layers.TiledMapServiceLayer; import com.esri.ags.layers.supportClasses.LOD; import com.esri.ags.layers.supportClasses.TileInfo; import flash.net.URLRequest; //扩展TiledMapServiceLayer图层实现加载google地图 public class GoogleMapLayer extends TiledMapServiceLayer { private var _tileInfo:TileInfo=new TileInfo(); private var _baseURL:String=""; public var mapStyle:String=""; public function GoogleMapLayer() { super(); buildTileInfo(); setLoaded(true); } override public function get fullExtent():Extent { return new Extent(-20037508.342787, -20037508.342787, 20037508.342787, 20037508.342787, new SpatialReference(102113)); } override public function get initialExtent():Extent { return new Extent(-20037508.342787, -20037508.342787, 20037508.342787, 20037508.342787, new SpatialReference(102113)); } override public function get spatialReference():SpatialReference { return new SpatialReference(102113); } override public function get tileInfo():TileInfo { return _tileInfo; } //获取矢量地图 override protected function getTileURL(level:Number, row:Number, col:Number):URLRequest { var s:String = "Galileo".substring(0, ((3 * x + y) % 8)); var url:String; url = "http://mt"+(col%4)+".google.cn/vt/lyrs=t@128,r@177000000&hl=zh-CN&gl=cn&" + "x=" + col + "&" + "y=" + row + "&" + "z=" + level+ "&" + "s=" + s; return new URLRequest(url); } private function buildTileInfo():void { _tileInfo.height=256; _tileInfo.width=256; _tileInfo.origin=new MapPoint(-20037508.342787, 20037508.342787); _tileInfo.spatialReference=new SpatialReference(102113); _tileInfo.lods = [ new LOD(0, 156543.033928, 591657527.591555), new LOD(1, 78271.5169639999, 295828763.795777), new LOD(2, 39135.7584820001, 147914381.897889), new LOD(3, 19567.8792409999, 73957190.948944), new LOD(4, 9783.93962049996, 36978595.474472), new LOD(5, 4891.96981024998, 18489297.737236), new LOD(6, 2445.98490512499, 9244648.868618), new LOD(7, 1222.99245256249, 4622324.434309), new LOD(8, 611.49622628138, 2311162.217155), new LOD(9, 305.748113140558, 1155581.108577), new LOD(10, 152.874056570411, 577790.554289), new LOD(11, 76.4370282850732, 288895.277144), new LOD(12, 38.2185141425366, 144447.638572), new LOD(13, 19.1092570712683, 72223.819286), new LOD(14, 9.55462853563415, 36111.909643), new LOD(15, 4.77731426794937, 18055.954822), new LOD(16, 2.38865713397468, 9027.977411), new LOD(17, 1.19432856685505, 4513.988705), new LOD(18, 0.597164283559817, 2256.994353), new LOD(19, 0.298582141647617, 1128.497176) ]; } }