private function zoomToGraphics():void
{
var graphicProvider:ArrayCollection = gLayer.graphicProvider as ArrayCollection;
var graphicsExtent:Extent = GraphicUtil.getGraphicsExtent(graphicProvider.toArray());
if (graphicsExtent){
Map.extent = graphicsExtent;
Alert.show("Mheight: " + Map.extent.height + "\n Gheight: " + graphicsExtent.height
+ "\n " + "\n Mwidth: " + Map.extent.width + "\n Gwidth: " + graphicsExtent.width);
}
}<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx"
xmlns:esri="http://www.esri.com/2008/ags">
<fx:Script>
<![CDATA[
import com.esri.ags.events.MapMouseEvent;
import com.esri.ags.geometry.Extent;
import com.esri.ags.utils.GraphicUtil;
import mx.collections.ArrayCollection;
protected function map_mapClickHandler(event:MapMouseEvent):void
{
var graphicProvider:ArrayCollection = gLayer.graphicProvider as ArrayCollection;
var graphicsExtent:Extent = GraphicUtil.getGraphicsExtent(graphicProvider.toArray());
trace(graphicsExtent, graphicsExtent.width, graphicsExtent.height);
map.extent = graphicsExtent;
trace(map.extent, map.extent.width, map.extent.height)
}
]]>
</fx:Script>
<esri:Map id="map" mapClick="map_mapClickHandler(event)">
<esri:ArcGISTiledMapServiceLayer url="http://server.arcgisonline.com/ArcGIS/rest/services/World_Street_Map/MapServer"/>
<esri:GraphicsLayer id="gLayer">
<esri:Graphic>
<esri:WebMercatorMapPoint lon="10" lat="10"/>
</esri:Graphic>
<esri:Graphic>
<esri:WebMercatorMapPoint lon="10" lat="50"/>
</esri:Graphic>
</esri:GraphicsLayer>
</esri:Map>
</s:Application>
<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:esri="http://www.esri.com/2008/ags"
xmlns:mx="library://ns.adobe.com/flex/mx">
<fx:Script>
<![CDATA[
import com.esri.ags.Graphic;
import com.esri.ags.events.MapMouseEvent;
import com.esri.ags.geometry.MapPoint;
import com.esri.ags.geometry.Polygon;
import com.esri.ags.utils.GraphicUtil;
import com.esri.ags.geometry.Extent;
import mx.controls.Alert;
import mx.collections.ArrayCollection;
protected function Map_mapClickHandler(event:MapMouseEvent):void
{
//allow user to enter size of poly desired
if(tInput1.text == ""){
Alert.show("Please enter a number in the text input before clicking the map.");
}else{
var size:int = Number(tInput1.text);
var halfSize:Number = size/2;
var center:MapPoint=Map.toMapFromStage(event.stageX, event.stageY);
var botLeft:MapPoint = new MapPoint;
//new mapPoint is assigned the same coor sys as the map
botLeft.spatialReference=Map.spatialReference;
//units defined by the spatial reference
botLeft.x=center.x-halfSize;
botLeft.y=center.y-halfSize*20;
var botRight:MapPoint = new MapPoint;
botRight.spatialReference=Map.spatialReference;
botRight.x=center.x+halfSize;
botRight.y=center.y-halfSize*20;
var topRight:MapPoint = new MapPoint;
topRight.spatialReference=Map.spatialReference;
topRight.x=center.x+halfSize;
topRight.y=center.y+halfSize*20;
var topLeft:MapPoint = new MapPoint;
topLeft.spatialReference=Map.spatialReference;
topLeft.x=center.x-halfSize;
topLeft.y=center.y+halfSize*20;
var newPolygon:Polygon = new Polygon;
newPolygon.spatialReference=Map.spatialReference;
newPolygon.rings=[[botLeft, botRight, topRight, topLeft, botLeft]];
var newGraphic:Graphic = new Graphic;
newGraphic.geometry=newPolygon;
newGraphic.symbol=symbol1;
gLayer.add(newGraphic);
zoomToGraphics();
}
}
private function zoomToGraphics():void
{
var graphicProvider:ArrayCollection = ArrayCollection(gLayer.graphicProvider);
var graphicsExtent:Extent = GraphicUtil.getGraphicsExtent(graphicProvider.toArray());
//graphicsExtent.spatialReference = Map.spatialReference;
Map.extent = graphicsExtent;
Alert.show("Map height: " + Map.extent.height + "\n gE height: " + graphicsExtent.height + "\n " +
"\n Map width: " + Map.extent.width + "\n gE width: " + graphicsExtent.width);
}
protected function clearGraphics_clickHandler(event:MouseEvent):void
{
gLayer.clear();
}
]]>
</fx:Script>
<fx:Declarations>
<esri:SimpleFillSymbol id="symbol1"
style="solid"
color="0xFF0000"
alpha="0.3">
<esri:outline>
<esri:SimpleLineSymbol style="solid" color="0x000000" width="1" />
</esri:outline>
</esri:SimpleFillSymbol>
</fx:Declarations>
<s:BorderContainer id="mainBC"
width="550" height="730"
borderVisible="true"
borderAlpha="1" borderColor="#FF0000"
borderStyle="solid" borderWeight="3">
<s:layout>
<s:VerticalLayout horizontalAlign="center" verticalAlign="middle" paddingTop="5"/>
</s:layout>
<s:Label text="Click the map to add a graphic" fontSize="15"/>
<esri:Map id="Map" logoVisible="false" mapClick="Map_mapClickHandler(event)">
<esri:ArcGISTiledMapServiceLayer id="mapSvc" url="http://server.arcgisonline.com/ArcGIS/rest/services/World_Street_Map/MapServer"/>
<esri:GraphicsLayer id="gLayer"/>
</esri:Map>
<s:TextInput id="tInput1" text="10000"/>
<s:Button id="clearGraphics" label="Clear Graphics" click="clearGraphics_clickHandler(event)"/>
</s:BorderContainer>
</s:Application>
<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:esri="http://www.esri.com/2008/ags"
xmlns:mx="library://ns.adobe.com/flex/mx">
<fx:Script>
<![CDATA[
import com.esri.ags.Graphic;
import com.esri.ags.events.MapMouseEvent;
import com.esri.ags.geometry.MapPoint;
import com.esri.ags.geometry.Polygon;
import com.esri.ags.utils.GraphicUtil;
import com.esri.ags.geometry.Extent;
import mx.controls.Alert;
import mx.collections.ArrayCollection;
protected function Map_mapClickHandler(event:MapMouseEvent):void
{
//allow user to enter size of poly desired
if(tInput1.text == ""){
Alert.show("Please enter a number in the text input before clicking the map.");
}else{
var size:int = Number(tInput1.text);
var halfSize:Number = size/2;
var center:MapPoint=Map.toMapFromStage(event.stageX, event.stageY);
var botLeft:MapPoint = new MapPoint;
//new mapPoint is assigned the same coor sys as the map
botLeft.spatialReference=Map.spatialReference;
//units defined by the spatial reference
botLeft.x=center.x-halfSize;
botLeft.y=center.y-halfSize*Number(tInput2.text);
var botRight:MapPoint = new MapPoint;
botRight.spatialReference=Map.spatialReference;
botRight.x=center.x+halfSize;
botRight.y=center.y-halfSize*Number(tInput2.text);
var topRight:MapPoint = new MapPoint;
topRight.spatialReference=Map.spatialReference;
topRight.x=center.x+halfSize;
topRight.y=center.y+halfSize*Number(tInput2.text);
var topLeft:MapPoint = new MapPoint;
topLeft.spatialReference=Map.spatialReference;
topLeft.x=center.x-halfSize;
topLeft.y=center.y+halfSize*Number(tInput2.text);
var newPolygon:Polygon = new Polygon;
newPolygon.spatialReference=Map.spatialReference;
newPolygon.rings=[[botLeft, botRight, topRight, topLeft, botLeft]];
var newGraphic:Graphic = new Graphic;
newGraphic.geometry=newPolygon;
newGraphic.symbol=symbol1;
gLayer.add(newGraphic);
zoomToGraphics();
}
}
private function zoomToGraphics():void
{
var graphicProvider:ArrayCollection = ArrayCollection(gLayer.graphicProvider);
var graphicsExtent:Extent = GraphicUtil.getGraphicsExtent(graphicProvider.toArray());
//graphicsExtent.spatialReference = Map.spatialReference;
Map.extent = graphicsExtent;
Alert.show("Map height: " + Map.extent.height + "\n gE height: " + graphicsExtent.height + "\n " +
"\n Map width: " + Map.extent.width + "\n gE width: " + graphicsExtent.width);
}
protected function clearGraphics_clickHandler(event:MouseEvent):void
{
gLayer.clear();
}
]]>
</fx:Script>
<fx:Declarations>
<esri:SimpleFillSymbol id="symbol1"
style="solid"
color="0xFF0000"
alpha="0.3">
<esri:outline>
<esri:SimpleLineSymbol style="solid" color="0x000000" width="1" />
</esri:outline>
</esri:SimpleFillSymbol>
</fx:Declarations>
<s:BorderContainer id="mainBC"
width="550" height="500"
borderVisible="true"
borderAlpha="1" borderColor="#FF0000"
borderStyle="solid" borderWeight="3">
<s:layout>
<s:VerticalLayout horizontalAlign="center" verticalAlign="middle" paddingTop="5"/>
</s:layout>
<s:Label text="Click the map to add a graphic" fontSize="15"/>
<esri:Map id="Map" logoVisible="false" mapClick="Map_mapClickHandler(event)">
<esri:ArcGISTiledMapServiceLayer id="mapSvc" url="http://server.arcgisonline.com/ArcGIS/rest/services/World_Street_Map/MapServer"/>
<esri:GraphicsLayer id="gLayer"/>
</esri:Map>
<s:TextInput id="tInput1" text="10000"/>
<s:TextInput id="tInput2" text = "20"/>
<s:Button id="clearGraphics" label="Clear Graphics" click="clearGraphics_clickHandler(event)"/>
</s:BorderContainer>
</s:Application>
<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx"
xmlns:esri="http://www.esri.com/2008/ags">
<s:layout>
<s:VerticalLayout horizontalAlign="center"
paddingBottom="10"
paddingTop="10"/>
</s:layout>
<fx:Script>
<![CDATA[
protected function button1_clickHandler(event:MouseEvent):void
{
map.extent = testExt;
}
]]>
</fx:Script>
<s:Button click="button1_clickHandler(event)" label="Set Extent"/>
<esri:Map id="map"
width="500" height="600">
<esri:ArcGISTiledMapServiceLayer url="http://server.arcgisonline.com/ArcGIS/rest/services/World_Street_Map/MapServer"/>
<esri:GraphicsLayer>
<esri:Graphic>
<esri:WebMercatorExtent id="testExt"
minlon="5" minlat="-80" maxlon="10" maxlat="80"/>
<esri:symbol>
<esri:SimpleFillSymbol color="red"/>
</esri:symbol>
</esri:Graphic>
</esri:GraphicsLayer>
</esri:Map>
</s:Application>