Recently, I have been studying the FlexViewer framework. I have used various map services as some elements on top of the Map Display. After finding N on the Internet for a long time, I have finally completed the superposition of the basemap, mainly by rewriting TiledMapServiceLayer.Gettileurl,BuildtileinfoMethod. Do not directly paste the code!
Baidu and Google's wkid are inconsistent, which is a tragedy.
Google:
Package
{
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. levels;
Import com. esri. ags. layers. supportClasses. TileInfo;
Import flash.net. URLRequest;
// Extends the TiledMapServiceLayer layer to load google Maps.
Public class GoogleMapLayer extends TiledMapServiceLayer
{
Private var _ tileInfo: TileInfo = new TileInfo ();
Private VaR _ baseurl: String = "";
Private VaR _ initialextent: extent;
Private VaR _ wkid: Int = 102113;
Public var maptype: String = "map ";
Public Function googlemaplayer (initialextent: extent = NULL)
{
Super ();
_ Initialextent = initialextent;
Buildtileinfo ();
Setloaded (true );
}
Override public function get fullextent (): Extent
{
Return new extent (-20037508.342787,-20037508.342787, 20037508.342787, 20037508.342787, new spatialreference (_ wkid ));
}
Override public function get initialextent (): Extent
{
If (_ initialextent)
Return _ initialextent;
Return fullextent;
}
Override public function get spatialreference (): spatialreference
{
Return new spatialreference (_ wkid );
}
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;
// Obtain the vector map
If (mapType = "map ")
{
Url = "http: // mt" + (col % 4) + ".google.cn/vt/lyrs?m@15800?&hl=zh-cn&gl=cn&" +
"X =" + col + "&" +
"Y =" + row + "&" +
"Z =" + level + "&" +
"S =" + S;
}
Else if (maptype = "image") // get the image map
{
Url = "http: // MT" + (COL % 4) + ".google.cn/vt/lyrs=s@121&hl;zh-cn≷cn&src=api&" +
"X =" + Col + "&" +
"Y =" + row + "&" +
"Z =" + level + "&" +
"S =" + S;
}
Else if (maptype = "Poi") // obtain the road poi
{
Url = "http: // MT" + (COL % 4) + ".google.cn/vt/imgtp?png32&lyrs=h@16900?&hl=zh-cn&gl=cn&" +
"X =" + Col + "&" +
"Y =" + row + "&" +
"Z =" + level + "&" +
"S =" + s;
}
Else if (mapType = "topography") {// terrain
Url = "http: // mt" + (col % 4) + ".google.cn/vt/lyrs%t@129,r@18300?&hl=zh-cn&gl=cn&src=app &"
+
"X =" + col + "&" +
"Y =" + row + "&" +
"Z =" + level + "&" +
"S =" + s;
} Else if (mapType = "real") {// vegetation map
Url = "http: // mt" + (col % 4) + ".googleapis.com/vt/lyrs?m@19600?&hl=zh-cn&src=api&" +
"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 (_ wkid );
_ Tileinfo. lods = [
New D3S (0, 156543.033928, 591657527.591555 ),
New D3S (1, 78271.5169639999, 295828763.795777 ),
New D3S (2, 39135.7584820001, 147914381.897889 ),
New d3's (3, 19567.8792409999, 73957190.948944 ),
New D3S (4, 9783.93962049996, 36978595.474472 ),
New D3S (5, 4891.96981024998, 18489297.737236 ),
New D3S (6, 2445.98490512499, 9244648.868618 ),
New D3S (7, 1222.99245256249, 4622324.434309 ),
New Cutting (8,611.49622628138, 2311162.217155 ),
New Cutting (9,305.748113140558, 1155581.108577 ),
New Cutting (10,152.874056570411, 577790.554289 ),
New D3S (11, 76.4370282850732, 288895.277144 ),
New D3S (12, 38.2185141425366, 144447.638572 ),
New D3S (13, 19.1092570712683, 72223.819286 ),
New D3S (14, 9.55462853563415, 36111.909643 ),
New D3S (15, 4.77731426794937, 18055.954822 ),
New D3S (16, 2.38865713397468, 9027.977411 ),
New Cutting (17, 1.19432856685505, 4513.988705 ),
New Cutting (18, 0.597164283559817, 2256.994353 ),
New D3S (19, 0.298582141647617, 1128.497176)
];
}
}
}
Baidu:
Package
{
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. levels;
Import com. esri. ags. layers. supportClasses. TileInfo;
Import flash.net. URLRequest;
Import flashx. textLayout. formats. Float;
Public class BaiduTiledMapServiceLayer extends TiledMapServiceLayer
{
Private VaR _ tileinfo: tileinfo = new tileinfo ();
Private VaR _ wkid: Int = 102100; // 102100;
Private var cornercoordinate: Number = 20037508.3427892;
Public var maptype: String = "map ";
Private VaR _ initialextent: extent;
Public Function baidutiledmapservicelayer ()
{
Super ();
Buildtileinfo (); // to create our hardcoded tileinfo
Setloaded (true); // map will only use loaded Layers
}
//----------------------------------
// Full screen range
//----------------------------------
Override public function get fullExtent (): Extent
{
Return new Extent (-cornerCoordinate,-cornerCoordinate, new SpatialReference (_ wkid ));
}
//----------------------------------
// Initialization range
//----------------------------------
Override public function get initialExtent (): Extent
{
If (_ initialExtent)
Return _ initialExtent;
Return fullExtent;
}
//----------------------------------
// Spatial reference system
//----------------------------------
Override public function get spatialReference (): SpatialReference
{
Return new SpatialReference (_ wkid );
}
//----------------------------------
// TileInfo
//----------------------------------
Override public function get tileInfo (): TileInfo
{
Return _ tileInfo;
}
//--------------------------------------------------------------------------
Override protected function getTileURL (level: Number, row: Number, col: Number): URLRequest
{
Var zoom: int = level-1;
Var offsetX: int = Math. pow (2, zoom) as int;
Var offsetY: int = offsetX-1;
Var numX: int = col-offsetX;
Var numY: int = (-row) + offsetY;
Zoom = level + 1;
Var num: int = (col + row) % 8 + 1;
Var url: String = null;
If (mapType = "map ")
{
Url = "http: // q" + num + ".baidu.com/it/uw.x=" + numX + "; y =" + numY + "; z =" + zoom + "; v = 013; type = web & fm = 44 ";
}
Else if (mapType = "image ")
{
Url = "http: // Q" + num + ".baidu.com/it/uw.x=" + numx + "; y =" + numy + "; Z =" + zoom + "; V = 009; type = sate & fm = 46 ";
}
Else if (maptype = "Poi ")
{
Url = "http: // Q" + num + ".baidu.com/it/uw.x=" + numx + "; y =" + numy + "; Z =" + zoom + "; V = 013; type = trans & fm = 47 ";
}
Return new URLRequest (URL );
}
//--------------------------------------------------------------------------
//
// Custom method to define the map zoom level
//
//--------------------------------------------------------------------------
Private function buildtileinfo (): void
{
_ Tileinfo. Height = 256;
_ Tileinfo. width = 256;
_ Tileinfo. Origin = new mappoint (-cornercoordinate, cornercoordinate );
_ Tileinfo. spatialreference = new spatialreference (_ wkid );
_ Tileinfo. lods = [
New D3S (0, 156543.033928, 591657527.591555 ),
New D3S (1, 78271.5169639999, 295828763.795777 ),
New D3S (2, 39135.7584820001, 147914381.897889 ),
New d3's (3, 19567.8792409999, 73957190.948944 ),
New D3S (4, 9783.93962049996, 36978595.474472 ),
New D3S (5, 4891.96981024998, 18489297.737236 ),
New D3S (6, 2445.98490512499, 9244648.868618 ),
New D3S (7, 1222.99245256249, 4622324.434309 ),
New Cutting (8,611.49622628138, 2311162.217155 ),
New Cutting (9,305.748113140558, 1155581.108577 ),
New Cutting (10,152.874056570411, 577790.554289 ),
New D3S (11, 76.4370282850732, 288895.277144 ),
New D3S (12, 38.2185141425366, 144447.638572 ),
New D3S (13, 19.1092570712683, 72223.819286 ),
New D3S (14, 9.55462853563415, 36111.909643 ),
New D3S (15, 4.77731426794937, 18055.954822 ),
New D3S (16, 2.38865713397468, 9027.977411 ),
New Cutting (17, 1.19432856685505, 4513.988705 ),
New Cutting (18, 0.597164283559817, 2256.994353 ),
New D3S (19, 0.298582141647617, 1128.497176)
];
}
}
}
PS: related technologies are only used as hobbies. If you want to use them for commercial purposes, contact the relevant company !!!