在ArcGIS Viewer for Flex开发中,经常需要用到google map作为底图,我们不能通过ArcGIS Viewer for Flex - Application Builder轻易的引入google map 作为底图,需要通过程序重写TiledMapServiceLayer来扩展从而加载google map。

  

  这里有写好的GoogleMapLayer.as文件:

package com.esri.viewer
{
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());
} override public function get initialExtent():Extent
{
return new Extent(-20037508.342787, -20037508.342787, 20037508.342787, 20037508.342787, new SpatialReference());
} override public function get spatialReference():SpatialReference
{
return new SpatialReference();
} override public function get tileInfo():TileInfo
{
return _tileInfo;
} //获取矢量地图
override protected function getTileURL(level:Number, row:Number, col:Number):URLRequest
{
var s:String = "Galileo".substring(, (( * x + y) % ));
var url:String; //获取矢量地图
if(mapStyle == "Vector")
{
url = "http://mt"+(col%)+".google.com/vt/lyrs=m@158000000&hl=zh-CN&gl=cn&" +
"x=" + col + "&" +
"y=" + row + "&" +
"z=" + level+ "&" +
"s=" + s;
} //获取地形图
else if(mapStyle == "Terrain")
{
url = "http://mt"+(col%)+".google.cn/vt/lyrs=t@131,r@227000000&hl=zh-CN&gl=cn&" +
"x=" + col + "&" +
"y=" + row + "&" +
"z=" + level+ "&" +
"s=" + s;
} //获取影像地图
else if(mapStyle == "Image")
{
url = "http://mt"+(col%)+".google.com/vt/lyrs=s&hl=en&gl=en&" +
"x=" + col + "&" +
"y=" + row + "&" +
"z=" + level+ "&" +
"s=" + s;
} //获取道路等POI,和影像地图配合使用
else if(mapStyle == "POI")
{
url = "http://mt"+(col%)+".google.com/vt/imgtp=png32&lyrs=h@169000000&hl=zh-CN&gl=cn&" +
"x=" + col + "&" +
"y=" + row + "&" +
"z=" + level+ "&" +
"s=" + s;
} return new URLRequest(url);
} private function buildTileInfo():void
{
_tileInfo.height=;
_tileInfo.width=;
_tileInfo.origin=new MapPoint(-20037508.342787, 20037508.342787);
_tileInfo.spatialReference=new SpatialReference();
_tileInfo.lods = [
new LOD(, 156543.033928, 591657527.591555),
new LOD(, 78271.5169639999, 295828763.795777),
new LOD(, 39135.7584820001, 147914381.897889),
new LOD(, 19567.8792409999, 73957190.948944),
new LOD(, 9783.93962049996, 36978595.474472),
new LOD(, 4891.96981024998, 18489297.737236),
new LOD(, 2445.98490512499, 9244648.868618),
new LOD(, 1222.99245256249, 4622324.434309),
new LOD(, 611.49622628138, 2311162.217155),
new LOD(, 305.748113140558, 1155581.108577),
new LOD(, 152.874056570411, 577790.554289),
new LOD(, 76.4370282850732, 288895.277144),
new LOD(, 38.2185141425366, 144447.638572),
new LOD(, 19.1092570712683, 72223.819286),
new LOD(, 9.55462853563415, 36111.909643),
new LOD(, 4.77731426794937, 18055.954822),
new LOD(, 2.38865713397468, 9027.977411),
new LOD(, 1.19432856685505, 4513.988705),
new LOD(, 0.597164283559817, 2256.994353),
new LOD(, 0.298582141647617, 1128.497176)
];
}
}
}

  

  具体步骤如下:

  第一步:将文件GoogleMapLayer.as放到com.esri.viewer包下

  

  

  第二步:在MapManager.mxml文件中:

  (1)引入包com.esri.viewer.GoogleMapLayer。

  

  (2)在addLayerToMap函数中添加:

  

  第三步:在LayerCreator.as文件中

  (1)引入包com.esri.viewer.GoogleMapLayer:

  

  (2)在createLayer函数中添加:

else if (layerType == "googlemap")
{
return createGoogleLayer(layerCreationProperties);
}

  (3)添加函数createGoogleLayer:  

  private static function createGoogleLayer(layerCreationProperties:LayerCreationProperties):GoogleMapLayer
{
var googleLayer:GoogleMapLayer=new GoogleMapLayer();
googleLayer.name=layerCreationProperties.label;
if (layerCreationProperties.style)
{
googleLayer.mapStyle= layerCreationProperties.style;
}
googleLayer.id=layerCreationProperties.label;
googleLayer.alpha=layerCreationProperties.alpha;
googleLayer.visible=layerCreationProperties.visible; return googleLayer;
}

  第四步:在config.xml配置文件中添加basemaps: 

<basemaps>
<layer label="GoogleMapLayer" type="GoogleMap" icon="assets/images/birds.png" style="Terrain" visible="true"/>
</basemaps>

  运行结果:

  

ArcGIS Viewer for Flex中引入google map作底图的更多相关文章

  1. ArcGIS Viewer for Flex中引入google map作底图 (转)

    在ArcGIS Viewer for Flex开发中,经常需要用到google map作为底图,我们不能通过ArcGIS Viewer for Flex - Application Builder轻易 ...

  2. ArcGIS for Flex中引入google map作底图

    上篇文章到在ArcGIS View中引入google map,这里讲ArcGIS for Flex中引入google map作底图. 同样道理,以google map作底图,需要编写继承自TiledM ...

  3. 基于ArcGIS Viewer for Flex开发的一款跨平台的应用程序

    特点: 1.基于ArcGIS Viewer for Flex开发的一款跨平台的应用程序: -(IBAction) showTOC:(id)sender { if (_tocViewController ...

  4. Flex加载google地图、百度地图以及天地图作底图

    一  Flex加载Google地图作底图 (1)帮助类GoogleLayer.as /* * 根据输入的地图类型加载Google地图(by chenyuming) */ package Layers ...

  5. arcgis api for silverlight使用google map等多个在线地图

    原文 http://blog.csdn.net/leesmn/article/details/6820245 无可否认,google map实在是很漂亮.可惜对于使用arcgis api for si ...

  6. Google map API V3

    本文主要总结Google map API V3使用中最简单也是最常见的一些操作以及相关概念,如果需要更加详细的信息,请直接阅读Google提供的关于map的文档. google map api v3文 ...

  7. Android Google Map API使用的八个步骤

    本系列教程将分为两部分,第一部分是指导用户使用Mapview控件进行编程,其中包括了如何获得Google Map API,如何使用该API进行简单的开发,如何获得用户当前所在的位置.第二部分则包括如何 ...

  8. [小技巧] google map使用

    在网页中打开 google map 中,可以使用 shift + - 来缩小地图,shift + + 来放大地图.

  9. Flexviewer使用Google地图作为底图

    Flexviewer使用Google地图作为底图: 在使用google地图作底图前提是你需要在Flex中实现加载google地图的代码(网上一大堆,随便找), 在只加载google地图的情况下,成功显 ...

随机推荐

  1. warning: incompatible implicit declaration of built-in function ‘exit’

    出现这个错误,一般是程序中某个函数没有include相关的文件. EG. 出现这个错误是因为要使用exit()应该包含stdlib.h文件

  2. Python开发入门与实战4-模板页面

    4.Django基于模板页面 在前一章中,HTML是直接被硬编码在 Python views.py代码中,如下: from django.http import HttpResponse import ...

  3. Python的平凡之路(8)

    (本文是对平凡之路(7)的补充等) 一.动态导入模块 import importlib __import__('import_lib.metaclass') #这是解释器自己内部用的 #importl ...

  4. 配置ConvenientBanner时出现的问题

    ConvenientBanner: compile 'com.bigkoo:convenientbanner:2.0.5' 找不到依赖库 classpath 'com.jfrog.bintray.gr ...

  5. pads

    1安装和破解,这个网上很多资料,破解的时候比较麻烦一点,注意安装环境. 2无模命令 (pads特点就是快捷键操作) 参考http://www.cnblogs.com/asus119/archive/2 ...

  6. BZOJ 2286 树链剖分+DFS序+虚树+树形DP

    第一次学习虚树,就是把无关的点去掉.S里维护一条链即可. #include <iostream> #include <cstring> #include <cstdio& ...

  7. RC上电复位时间计算

    高电平复位电路图 V0 为电容上的初始电压值:V1 为电容最终可充到或放到的电压值:Vt 为t时刻电容上的电压值.则,    Vt="V0"+(V1-V0)* [1-exp(-t/ ...

  8. LeetCode-Group Anagrams

    Given an array of strings, group anagrams together. For example, given: ["eat", "tea& ...

  9. JS特殊函数(Function()构造函数、函数直接量)区别介绍

    函数定义 函数是由这样的方式进行声明的:关键字 function.函数名.一组参数,以及置于括号中的待执行代码. 函数的构造语法有这三种: 1.function functionName(arg0, ...

  10. 准确理解SO_REUSEADDR

          默认情况下,套接字不同一个正在使用的本地地址绑定到一起.但在少数情况下,仍有必要以这种方式,来实现对一个地址的重复利用.每个连接都是通过它的本地及远程地址的组合,"独一无二&qu ...