Stuart, OK I think I got it worked out for dynamic and static this time.<?xml version="1.0" encoding="utf-8"?>
<!--
////////////////////////////////////////////////////////////////////////////////
//
// Copyright © 2008 - 2009 ESRI
//
// All rights reserved under the copyright laws of the United States.
// You may freely redistribute and use this software, with or
// without modification, provided you include the original copyright
// and use restrictions. See use restrictions in the file:
// <install location>/FlexViewer/License.txt
//
////////////////////////////////////////////////////////////////////////////////
-->
<BaseWidget xmlns ="com.esri.solutions.flexviewer.*"
xmlns:esri ="http://www.esri.com/2008/ags"
xmlns:mx ="http://www.adobe.com/2006/mxml"
xmlns:mxeffects ="com.adobe.ac.mxeffects.*"
xmlns:widgets ="com.esri.solutions.flexviewer.widgets.*"
x ="600"
y ="300"
widgetConfigLoaded ="init()">
<mx:Script>
<![CDATA[
import com.esri.ags.events.LayerEvent;
import mx.collections.ArrayCollection;
import com.esri.ags.utils.WebMercatorUtil;
import com.esri.ags.virtualearth.VETiledLayer;
import com.esri.ags.events.ExtentEvent;
import com.esri.ags.geometry.Extent;
import com.esri.ags.geometry.MapPoint;
import com.esri.ags.Graphic;
import com.esri.ags.layers.GraphicsLayer;
import com.esri.ags.layers.ArcGISDynamicMapServiceLayer;
import com.esri.ags.layers.ArcGISTiledMapServiceLayer;
import com.esri.ags.symbol.SimpleFillSymbol;
import com.esri.ags.symbol.SimpleLineSymbol;
import com.esri.ags.Map;
import flash.events.MouseEvent;
import mx.controls.Alert;
import mx.graphics.ImageSnapshot;
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;
private function init():void
{
if (configXML)
{
var type:String = configXML.mapservice.@type;
var url:String = configXML.mapservice;
var style:String = configXML.mapservice.@style;
var label:String = configXML.mapservice.@label;
overviewMode = configXML.mapservice.@mode;
switch (type.toLowerCase())
{
case "tiled":
{
var tiledlayer:ArcGISTiledMapServiceLayer = new ArcGISTiledMapServiceLayer(url);
tiledlayer.alpha = alpha;
if (overviewMode == "dynamic")
tiledlayer.addEventListener(LayerEvent.TILES_UPDATED,updateOvExtent);
ovMap.addLayer(tiledlayer);
break;
}
case "dynamic":
{
var dynlayer:ArcGISDynamicMapServiceLayer = new ArcGISDynamicMapServiceLayer(url);
dynlayer.alpha = alpha;
if (overviewMode == "dynamic")
dynlayer.addEventListener(Event.COMPLETE,updateOvExtent);
ovMap.addLayer(dynlayer);
break;
}
case "virtualearth":
{
var veTiledLayer:VETiledLayer = new VETiledLayer();
veTiledLayer.id = label;
veTiledLayer.tokenURL = url;
veTiledLayer.environment = "production";
veTiledLayer.visible = true;
veTiledLayer.alpha = alpha;
veTiledLayer.mapStyle = style;
veTiledLayer.name = label;
ovMap.addLayer(veTiledLayer);
break;
}
}
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);
ovGraphic.addEventListener(Event.CHANGE,updateOvExtent);
updateOverviewExtent();
setTimeout(updateOverviewExtent, 4000);
}
}
private function setOverviewExtent(event:ExtentEvent):void
{
ovGraphic.geometry = map.extent;
if (overviewMode == "dynamic"){
ovMap.extent = map.extent.expand(3);
}
try{
var ac:ArrayCollection = new ArrayCollection([]);
var bmpDat:BitmapData = ImageSnapshot.captureBitmapData(ovMap);
ac.addItem(bmpDat);
addSharedData("ovMap",ac);
}
catch(err:Error){
}
AddOVMap();
}
private function updateOverviewExtent():void
{
ovGraphic.geometry = map.extent;
if (overviewMode == "dynamic"){
ovMap.extent = map.extent.expand(3);
}
try{
var ac:ArrayCollection = new ArrayCollection([]);
var bmpDat:BitmapData = ImageSnapshot.captureBitmapData(ovMap);
ac.addItem(bmpDat);
addSharedData("ovMap",ac);
}
catch(err:Error){
}
AddOVMap();
}
private function updateOvExtent(Evt:Event):void
{
callLater(AddOVMap,null);
}
private function AddOVMap():void
{
try{
var ac:ArrayCollection = new ArrayCollection([]);
var bmpDat:BitmapData = ImageSnapshot.captureBitmapData(ovMap);
ac.addItem(bmpDat);
addSharedData("ovMap",ac);
}
catch(err:Error){
}
}
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);
}
]]>
</mx:Script>
<WidgetTemplate id="wTemplate" widgetClosed="widgetClosedHandler(event)" widgetOpened="widgetOpenedHandler(event)" widgetMinimized="widgetMinimizedHandler(event)">
<esri:Map id ="ovMap"
width ="100%"
height ="100%"
panArrowsVisible ="false"
zoomSliderVisible ="false"
logoVisible ="false"
scaleBarVisible ="false"
panEnabled ="false"
clickRecenterEnabled ="false"
doubleClickZoomEnabled ="false"
keyboardNavigationEnabled ="false"
rubberbandZoomEnabled ="false"
scrollWheelZoomEnabled ="false">
</esri:Map>
</WidgetTemplate>
</BaseWidget>