Flex 下兼容谷歌,百度地图服务
来源:互联网 发布:人物设定本子淘宝 编辑:程序博客网 时间:2024/04/29 21:36
最近一段时间一直在研究FlexViewer框架,使用各种地图服务作为地图显示上边叠加自己的一些要素,网上找了N久终于完成了底图的叠加,主要就是重写TiledMapServiceLayer的getTileURL,buildTileInfo方法.不多说直接贴代码!
百度跟谷歌的wkid不一致,这一点很悲剧。
谷歌:
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.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="";
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;
//获取矢量地图
if(mapType == "map")
{
url = "http://mt"+(col%4)+".google.cn/vt/lyrs=m@158000000&hl=zh-CN&gl=cn&" +
"x=" + col + "&" +
"y=" + row + "&" +
"z=" + level+ "&" +
"s=" + s;
}
else if(mapType == "image")//获取影像地图
{
url = "http://mt"+(col%4)+".google.cn/vt/lyrs=s@121&hl=zh-CN&gl=CN&src=api&" +
"x=" + col + "&" +
"y=" + row + "&" +
"z=" + level+ "&" +
"s=" + s;
}
else if(mapType == "poi")//获取道路POI
{
url = "http://mt"+(col%4)+".google.cn/vt/imgtp=png32&lyrs=h@169000000&hl=zh-CN&gl=cn&" +
"x=" + col + "&" +
"y=" + row + "&" +
"z=" + level+ "&" +
"s=" + s;
}
else if(mapType == "topography"){//地形
url = "http://mt"+(col%4)+".google.cn/vt/lyrs=t@129,r@183000000&hl=zh-CN&gl=cn&src=app&" +
"x=" + col + "&" +
"y=" + row + "&" +
"z=" + level+ "&" +
"s=" + s;
}else if(mapType == "real"){//植被map
url = "http://mt"+(col%4)+".googleapis.com/vt/lyrs=m@196000000&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 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)
];
}
}
}
百度:
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.LOD;
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
}
//----------------------------------
// 全屏范围
//----------------------------------
override public function get fullExtent():Extent
{
return new Extent(-cornerCoordinate, -cornerCoordinate, cornerCoordinate, cornerCoordinate, 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);
}
//----------------------------------
// 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/u=x="+numX+";y="+ numY + ";z=" + zoom + ";v=013;type=web&fm=44";
}
else if (mapType == "image")
{
url = "http://q"+num+".baidu.com/it/u=x="+numX+";y="+numY+";z="+zoom+";v=009;type=sate&fm=46";
}
else if (mapType == "poi")
{
url = "http://q"+num+".baidu.com/it/u=x="+numX+";y="+numY+";z="+zoom+";v=013;type=trans&fm=47";
}
return new URLRequest(url);
}
//--------------------------------------------------------------------------
//
// 自定义方法,定义地图缩放等级
//
//--------------------------------------------------------------------------
private function buildTileInfo():void
{
_tileInfo.height=256;
_tileInfo.width=256;
_tileInfo.origin=new MapPoint(-cornerCoordinate, cornerCoordinate);
_tileInfo.spatialReference=new SpatialReference(_wkid);
_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)
];
}
}
}
PS:相关技术只作为爱好,如想作为商业用途,请与相关公司联系!!!
- Flex 下兼容谷歌,百度地图服务
- Flexviewer兼容谷歌,百度,天地图等地图作为地图展示
- 百度地图 搜索服务
- 百度地图flex例子测试
- 谷歌地图服务
- 谷歌地图、百度地图偏移解决方法
- 离线谷歌卫星地图加载服务中间件调用示例 For Flex
- 使用百度地图(下)
- 百度地图【下】
- js使用百度地图服务
- ArcGIS Server Flex API接入百度地图
- IOS 地图导航(其中包括苹果地图、百度地图、高德地图、谷歌地图)
- Arcgis for flex 调用百度地图与Google地图
- Flex加载google地图、百度地图以及天地图作底图
- Flex加载google地图、百度地图以及天地图作底图
- Flex离线地图和在线谷歌地图实现
- Flex离线地图和在线谷歌地图实现<完整版>
- android下百度地图开发
- 利用Python和GDAL实现图像批处理
- dump bitmap(位图索引)内部研究
- vim 编码识 别与乱码处理
- 解决:Failed to fetch URL http://dl-ssl.google.com/android/repository/addons_list.xml, reason: connect
- 《程序员应该掌握的实用编程技能》
- Flex 下兼容谷歌,百度地图服务
- vi常用命令
- Android中JNI高级应用 - 本地C代码中创建Java对象及本地JNI对象的保存 .
- GDAL附带工具
- android开发,给手机一个更好的未来
- FI2
- 可变形参 va_arg介绍
- openlog、syslog和closelog函数
- 苹果扩大其北卡罗莱纳州燃料电池发电场规模