现在的位置: 首页 > 综合 > 正文

FlexViewer地图范围的自动缩放

2013年07月20日 ⁄ 综合 ⁄ 共 1221字 ⁄ 字号 评论关闭

 

      前段时间在FlexViewer框架上做点东西,有一个功能是根据多边形范围,让地图自动缩放。当时我的做法是根据polygon的x、y的最大最小值生成一个extent,然后map. extent=extent.expand(2);后来发现其实有一个更简单的办法。在FlexViewer中有一个UtilsClass的as文件,文件中有一个UtilsClass类,类中有zoomToGraphics这个静态方法,zoomToGraphics(map:Map,graphicsLayer_num:GraphicsLayer);两个参数的map,如果你的组件是基于basewidget的那么第一个参数直接写map就行,graphicsLayer_num就是存在你需要根据的点、线、面自动缩放图层;graphicsLayer_num图层的graphic对象可以是点线面,这样就可以根据你输入的图层上的graphics实现地图的缩放。

      由于后来需要根据多个graphicsLayer确定范围,我又在UtilsClass类添加了对zoomToGraphics方法进行修改,增加了一个新的方法layersZoomToGraphics。

        public static function layersZoomToGraphics(map:Map,graphicsLayer_arr:ArrayCollection):void{
   var graphicsProvider:ArrayCollection=new ArrayCollection;
   for(var i:int=0;i<graphicsLayer_arr.length;i++){
   
    var graphicsLayer:GraphicsLayer=graphicsLayer_arr[i] as GraphicsLayer;
    graphicsProvider.addAll(graphicsLayer.graphicProvider as ArrayCollection);
   }
    var graphicsExtent:Extent = GraphicUtil.getGraphicsExtent(graphicsProvider.toArray());
    if(graphicsExtent){
     map.extent = graphicsExtent;
     if (!map.extent.contains(graphicsExtent)){
      map.level--;
     }
    }
  }

该方法的第二个参数graphicsLayer_arr是一个存放着graphicsLayer的ArrayCollection。再调用该方法时,需要先把需要的graphicsLayer放到一个数组中。

flexbuilder中快捷键Ctrl+Shift+D+R可以输入文件的文字打开文件。

抱歉!评论已关闭.