/**第一种:地图为静态地图,不因主屏地图比例尺的改变而改变。
*调用方法:绑定主屏map,给予鹰眼显示的图层。
**/
代码如下:
<?xml version="1.0" encoding="utf-8"?>
<s:BorderContainer xmlns:esri="http://www.esri.com/2008/ags" xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx"
>
<fx:Script>
<![CDATA[
import com.esri.ags.Graphic;
import com.esri.ags.events.ExtentEvent;
import com.esri.ags.events.MapMouseEvent;
import com.esri.ags.geometry.Extent;
import com.esri.ags.geometry.MapPoint;
import com.esri.ags.layers.GraphicsLayer;
import com.esri.ags.symbols.SimpleFillSymbol;
import com.esri.ags.symbols.SimpleLineSymbol;
public var mapXml:XML;
private var overviewMode:String;
private var graphicLineSym:SimpleLineSymbol = new SimpleLineSymbol("solid", 0xFF0000, 0.8, 3);
private var graphicPolySym:SimpleFillSymbol = new SimpleFillSymbol(null, 0xFF0000, 0.01, graphicLineSym);
private var graphicsLayer:GraphicsLayer;
private var ovGraphic:Graphic;
private var xOff:Number;
private var yOff:Number;
[Bindable]
public var map:Map=new Map();
public function ini():void
{
if (mapXml)
{
var mapType:String=mapXml.@mapType;
var mapUrl:String=mapXml.@url;
var initextent:String=mapXml.@initextent;
var fullextent:String=mapXml.@fullExtent;
var cacheMap:CacheMap=new CacheMap();
cacheMap._fullextent=fullextent;
var extArr1:Array=fullextent.split(",");
var extent:Extent=new Extent(Number(extArr1[0]), Number(extArr1[1]),
Number(extArr1[2]), Number(extArr1[3]));
cacheMap._baseURL=mapUrl;
cacheMap.getXml();
ovMap.extent=extent;
// ovMap.zoomSliderVisible=true;
ovMap.addLayer(cacheMap);
graphicsLayer = new GraphicsLayer();
graphicsLayer.symbol = graphicPolySym;
ovMap.addLayer(graphicsLayer);
ovGraphic = new Graphic();
ovGraphic.geometry = map.extent;
ovGraphic.addEventListener(MouseEvent.MOUSE_DOWN, mouseDownHandler);
ovGraphic.addEventListener(MouseEvent.MOUSE_UP, mouseUpHandler);
graphicsLayer.add(ovGraphic);
map.addEventListener(ExtentEvent.EXTENT_CHANGE, setOverviewExtent);
updateOverviewExtent();
}
}
private function setOverviewExtent(event:ExtentEvent):void
{
ovGraphic.geometry = map.extent;
if (overviewMode == "dynamic")
ovMap.extent = map.extent.expand(3);
}
private function updateOverviewExtent():void
{
ovGraphic.geometry = map.extent;
if (overviewMode == "dynamic")
ovMap.extent = map.extent.expand(3);
}
private function mouseDownHandler(event:MouseEvent):void
{
var ext:Extent = ovGraphic.geometry as Extent;
var mPt:MapPoint = ovMap.toMapFromStage(event.stageX, event.stageY);
xOff = ext.center.x - mPt.x;
yOff = ext.center.y - mPt.y;
ovGraphic.addEventListener(MouseEvent.MOUSE_MOVE, mouseMoveHandler);
}
private function mouseMoveHandler(event:MouseEvent):void
{
var mPt:MapPoint = ovMap.toMapFromStage(event.stageX, event.stageY);
var tempX:Number = mPt.x + xOff;
var tempY:Number = mPt.y + yOff;
var ext:Extent = ovGraphic.geometry as Extent;
var newext:Extent = new Extent(tempX - ext.width / 2, tempY - ext.height/ 2, tempX + ext.width / 2, tempY + ext.height / 2);
ovGraphic.geometry = newext;
if (!event.buttonDown)
ovGraphic.removeEventListener(MouseEvent.MOUSE_MOVE, mouseMoveHandler);
}
private function mouseUpHandler(event:MouseEvent):void
{
map.extent = ovGraphic.geometry as Extent;
ovGraphic.removeEventListener(MouseEvent.MOUSE_MOVE, mouseMoveHandler);
}
private function widgetOpenedHandler(event:Event):void
{
map.addEventListener(ExtentEvent.EXTENT_CHANGE, setOverviewExtent);
setTimeout(updateOverviewExtent, 1000);
}
private function widgetClosedHandler(event:Event):void
{
map.removeEventListener(ExtentEvent.EXTENT_CHANGE, setOverviewExtent);
}
private function widgetMinimizedHandler(event:Event):void
{
map.removeEventListener(ExtentEvent.EXTENT_CHANGE, setOverviewExtent);
}
private function mapclick(e:MapMouseEvent):void{
var mPt:MapPoint = ovMap.toMapFromStage(e.stageX, e.stageY);
var tempX:Number = mPt.x ;
var tempY:Number = mPt.y ;
var ext:Extent = ovGraphic.geometry as Extent;
var newext:Extent = new Extent(tempX - ext.width / 2, tempY - ext.height/ 2, tempX + ext.width / 2, tempY + ext.height / 2);
ovGraphic.geometry = newext;
map.extent = ovGraphic.geometry as Extent;
}
]]>
</fx:Script>
<esri:Map id ="ovMap"
width ="100%"
height ="100%"
mapClick="mapclick(event)"
panArrowsVisible ="false"
zoomSliderVisible ="false"
logoVisible ="false"
scaleBarVisible ="false"
panEnabled ="false"
clickRecenterEnabled ="false"
doubleClickZoomEnabled ="false"
keyboardNavigationEnabled ="false"
rubberbandZoomEnabled ="false"
scrollWheelZoomEnabled ="false">
</esri:Map>
</s:BorderContainer>
/**第二种:鹰眼图因主屏地图比例尺的改变而改变,比较适用于大范围大区域的地图鹰眼制作
*代码如下:
**/
package com.dse.common.gis
{
import com.esri.ags.Graphic;
import com.esri.ags.Map;
import com.esri.ags.events.ExtentEvent;
import com.esri.ags.events.MapEvent;
import com.esri.ags.geometry.Extent;
import com.esri.ags.geometry.MapPoint;
import com.esri.ags.layers.GraphicsLayer;
import com.esri.ags.symbols.LineSymbol;
import com.esri.ags.symbols.SimpleLineSymbol;
import com.esri.ags.symbols.SimpleFillSymbol;
import com.esri.ags.symbols.FillSymbol;
import flash.events.Event;
import flash.events.MouseEvent;
//--------------------------------------
// Other metadata
//--------------------------------------
[IconFile("overview-map.gif")]
/**
* An overview map that extends the base Map component and provides a convenience
* for linking the overview map to the main map.
*/
public class OverviewMap extends Map
{
//--------------------------------------------------------------------------
//
// Constructor
//
//--------------------------------------------------------------------------
/**
* Creates a new overview map instance.
*
* @param map The main map that is linked to this overview map.
*/
public function OverviewMap( mainMap:Map = null )
{
super();
this.mainMap = mainMap;
// Disable map navigation
mapNavigationEnabled = false;
this.scale=2000000;
// Hide the map controls
logoVisible = false;
panArrowsVisible = false;
scaleBarVisible = false;
zoomSliderVisible = false;
addEventListener(MouseEvent.CLICK, onOverviewClick);
}
//--------------------------------------------------------------------------
//
// Constants
//
//--------------------------------------------------------------------------
/**
* Overview mode in which the overview map's extent remains constant.
*/
public static const STATIC_MODE:String = "static";
/**
* Overview mode in which the overview map's extent changes to track the extent
* of the associated main map. This is the default overview mode.
*/
public static const DYNAMIC_MODE:String = "dynamic";
//--------------------------------------------------------------------------
//
// Variables
//
//--------------------------------------------------------------------------