地图上嵌入图片 - ArcGIS for FLEX API

 


要实现图片嵌入到地图中,并随着地图的放大缩小而跟着变化。


GoogleAPI提供了map.addOverlay(new GroundOverlay(...));可以轻松实现。

但查看ArcGIS for FLEX API

ArcGISImageServiceLayer
ArcGISDynamicMapServiceLayer
ArcGISTiledMapServiceLayer
(这些都是加载ArcGIS发布的服务)

也可以继承TiledMapServiceLayer加载Google或者其他的切片服务

但是要加载一张单纯的可放大缩小的图片,需要用GraphicsLayer

见如下代码:

 

<pre class="java" name="code">//添加layer,设置PictureFillSymbol
graphicsLayer = new GraphicsLayer();
var graphic:Graphic = new Graphic();
var polygon:Polygon  = new Polygon();
var ring:Array = new Array();
ring.push(new MapPoint(11131949,6446276));
ring.push(new MapPoint(11131949,-6706));
ring.push(new MapPoint(16697924,-6706));
ring.push(new MapPoint(16697924,6446276));
ring.push(new MapPoint(11131949,6446276));
polygon.addRing(ring);
graphic.geometry = polygon;
var fillSymbol:PictureFillSymbol = new PictureFillSymbol((event.target as LoaderInfo).content,251,251,1,1,0,0,0.001,null);
graphic.symbol = fillSymbol;
graphicsLayer.add(graphic);
myMap.addLayer(seaAreaLayer);

 

GraphicsLayer的symble设置为PictureFillSymbol,可以看到我把PictureFillSymbol的旋转角度参数angle设成0.001,这是因为flash player11的一个bug,angle默认为0会使图片无法显示
目前为止地图上可以显示一张图片,由于PictureFillSymbol的内容是平铺的,所以图片还不能随地图放大缩小。
接下来监听ZOOM事件,每次ZOOM_START都重新计算图片大小和位置

myMap.addEventListener(ZoomEvent.ZOOM_START,ZOOM_STARTHandler);  


 

<pre class="java" name="code">// 地图zoom事件,动态改变图片的大小和偏移
private function ZOOM_STARTHandler(e:ZoomEvent):void
{
var extent:Extent = (((graphicsLayer.graphicProvider as ArrayCollection).getItemAt(0) as Graphic).geometry as Polygon).extent;
var resolution:Number = myMap.lods[myMap.level].resolution;
var width:Number = extent.width/resolution;
var height:Number = extent.height/resolution;
(((
graphicsLayer.graphicProvider as ArrayCollection).getItemAt(0) as Graphic).symbol as PictureFillSymbol).width = width;
(((
graphicsLayer.graphicProvider as ArrayCollection).getItemAt(0) as Graphic).symbol as PictureFillSymbol).height = height;
(((
graphicsLayer.graphicProvider as ArrayCollection).getItemAt(0) as Graphic).symbol as PictureFillSymbol).xoffset = width/2;
(((
graphicsLayer.graphicProvider as ArrayCollection).getItemAt(0) as Graphic).symbol as PictureFillSymbol).yoffset = height/2;
}

效果如下:



 



 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值