Arcgis Flex显示GoogleMap二维地图,卫星地图

View Code
  1 package GoogleMap {
2 import com.esri.ags.SpatialReference;
3 import com.esri.ags.geometry.Extent;
4 import com.esri.ags.geometry.MapPoint;
5 import com.esri.ags.layers.TiledMapServiceLayer;
6 import com.esri.ags.layers.supportClasses.LOD;
7 import com.esri.ags.layers.supportClasses.TileInfo;
8
9 import flash.net.URLRequest;
10
11 import mx.collections.ArrayCollection;
12 import mx.controls.Alert;
13
14 /**
15 * Google切图图层
16 * yjq
17 */
18 public class GoogleTilesMapServiceLayer extends TiledMapServiceLayer{
19 function GoogleTilesMapServiceLayer(){
20 buildTileInfo();
21 setLoaded(true);
22 }
23
24 /**
25 * 二维普通地图url
26 */
27 private var _baseUrl:String = "http://mt2.google.cn/vt/v=w2.116&hl=zh-CN&gl=cn&s=";//&x=0&y=1&z=2
28
29 /**
30 * 卫星地图地图要素Url
31 */
32 private var _satelliteFeatureUrl:String = "http://mt3.google.cn/vt/imgtp=png32&lyrs=h@174000000&hl=zh-CN&gl=cn&src=app&s=Galileo";
33
34 /**
35 * 卫星地图的底图
36 */
37 private var _satelliteUrl:String = "http://mt3.google.cn/vt/lyrs=s@106&hl=zh-CN&gl=cn&src=app&s=Ga";
38
39 /**
40 * 设置显示卫星地图上的地图要素
41 *
42 */
43 public function setDisplaySatelliteFeature():void{
44 //设置当前显示卫星地图上地图要素
45 _mapType = 0;
46 _baseUrl = _satelliteFeatureUrl;
47 }
48
49 /**
50 * 地图显示方式
51 * 0:普通二维地图 1:卫星地图
52 */
53 private var _mapType:int = 0;
54
55
56 /**
57 * 地图显示方式
58 * 0:普通二维地图 1:卫星地图
59 */
60 public function get mapType():int{
61 return _mapType;
62 }
63
64 private var _satellitFeatureLayer:GoogleTilesMapServiceLayer = null;
65
66 [Bindable]
67 /**
68 * 地图显示方式
69 * 0:普通二维地图 1:卫星地图
70 */
71 public function set mapType(value:int):void{
72 _mapType = value;
73 if(_mapType<0||_mapType>1){
74 _mapType = 0;
75 }
76 if(_mapType==1){//如果是卫星地图,则还要显示其上的地理要素
77 _satellitFeatureLayer = new GoogleTilesMapServiceLayer();
78 _satellitFeatureLayer.setDisplaySatelliteFeature();
79 var currentLayerIndx:int = (this.map.layers as ArrayCollection).getItemIndex(this);
80 this.map.addLayer(_satellitFeatureLayer,currentLayerIndx+1);
81 }else if(_satellitFeatureLayer!=null){
82 this.map.removeLayer(_satellitFeatureLayer);
83 _satellitFeatureLayer = null;
84 }
85 this.refresh();
86 }
87
88 private var _tileInfo:TileInfo = new TileInfo();
89 override public function get tileInfo():TileInfo{
90 return _tileInfo;
91 }
92
93
94 override public function get units():String{
95 return "esriDecimalDegrees";
96 }
97
98 /**
99 * 分图范围
100 */
101 override public function get fullExtent():Extent{
102 return new Extent(-22041257.773878, -32673939.6727517, 22041257.773878, 20851350.0432886, new SpatialReference(102113));
103 }
104
105 /**
106 * 初使范围
107 */
108 override public function get initialExtent():Extent {
109 return new Extent(-22041257.773878, -32673939.6727517, 22041257.773878, 20851350.0432886, new SpatialReference(102113));
110 }
111
112 /**
113 *空间参考
114 */
115 override public function get spatialReference():SpatialReference{
116 return new SpatialReference(102113);//空间参考
117 }
118
119
120 /**
121 * 得到切片url
122 * @param level 显示级别
123 * @param row 行
124 * @param col 列
125 * @return
126 *
127 */
128 override protected function getTileURL(level:Number, row:Number, col:Number):URLRequest{
129 var url:String = null;
130 if(_mapType==0){
131 url = _baseUrl
132 }else if(_mapType==1){
133 url = _satelliteUrl;
134 }
135 url = url+"&x="+col+"&y="+row+"&z="+level;
136 return new URLRequest(url);
137 }
138
139 /**
140 *初使化切片信息
141 */
142 private function buildTileInfo():void{
143 _tileInfo.height=256;//切片大小
144 _tileInfo.width=256;
145 _tileInfo.origin=new MapPoint(-20037508.342787, 20037508.342787);//坐标每户的开始坐标,参照WGS_1984
146 _tileInfo.spatialReference=new SpatialReference(102113);
147
148 _tileInfo.lods = [ //比例尺 :比例级别,切片分辨雍,比例尺
149 new LOD(0, 156543.03392800014, 591657527.591555),
150 new LOD(1, 78271.516963999937, 295828763.79577702),
151 new LOD(2, 39135.758482000092, 147914381.89788899),
152 new LOD(3, 19567.879240999919, 73957190.948944002),
153 new LOD(4, 9783.9396204999593, 36978595.474472001),
154 new LOD(5, 4891.9698102499797, 18489297.737236001),
155 new LOD(6, 2445.9849051249898, 9244648.8686180003),
156 new LOD(7, 1222.9924525624949, 4622324.4343090001),
157 new LOD(8, 611.49622628138, 2311162.217155),
158 new LOD(9, 305.748113140558, 1155581.108577),
159 new LOD(10, 152.874056570411, 577790.554289),
160 new LOD(11, 76.4370282850732, 288895.277144),
161 new LOD(12, 38.2185141425366, 144447.638572),
162 new LOD(13, 19.1092570712683, 72223.819286),
163 new LOD(14, 9.55462853563415, 36111.909643),
164 new LOD(15,4.7773142679493699, 18055.954822),
165 new LOD(16, 2.3886571339746849, 9027.9774109999998),
166 new LOD(17, 1.1943285668550503, 4513.9887049999998),
167 new LOD(18, 0.59716428355981721, 2256.994353),
168 new LOD(19, 0.29858214164761665, 1128.4971760000001)
169 ];
170
171 }
172 }
173 }

测试页面

View Code
 1 <?xml version="1.0" encoding="utf-8"?>
2 <s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
3 xmlns:s="library://ns.adobe.com/flex/spark"
4 xmlns:mx="library://ns.adobe.com/flex/mx" minWidth="955" minHeight="600" xmlns:esri="http://www.esri.com/2008/ags" xmlns:GoogleMap="GoogleMap.*">
5 <fx:Declarations>
6 <!-- 将非可视元素(例如服务、值对象)放在此处 -->
7 </fx:Declarations>
8 <s:VGroup left="10" top="10" bottom="10" right="10">
9 <s:ComboBox id="mapType_cmb" labelField="name" >
10 <s:ArrayCollection>
11 <fx:Array>
12 <fx:Object name="普通二维地图" />
13 <fx:Object name="卫星地图" />
14 </fx:Array>
15 </s:ArrayCollection>
16 </s:ComboBox>
17 <esri:Map width="100%" height="100%" >
18 <GoogleMap:GoogleTilesMapServiceLayer mapType="{mapType_cmb.selectedIndex}" />
19 </esri:Map>
20 </s:VGroup>
21 </s:Application>



posted @ 2012-03-15 21:59  如坐夕阳  Views(1000)  Comments(0Edit  收藏  举报