Polygons can be loaded from ArcIMS directly into flash however I advice you not to send polygons with too many details as this will overload your server and client application.
The following examples shows you how you can use the Map toolbox to interactively load polygon information and display this on the map. We expect that you already looked into the other examples and know how to get a basic map inside flash. Once you have a map follow the following steps. Note that in the example we name the map instance 'my_map'.
1) Drag a geoMovieclip into the stage and change the following parameters. (Open the Component Inspector from the windows menu)
- behavior : arround_mouse (We query the data when the mouse stands still over a area)
- featurelimit : 1 (We only need one feature)
- fieldmovieclips : polydraw_convert (the movieclip we want to load for every feature, we will make this movie clip in the next step)
- layerid : contryBorder (The layer we will get the features from)
- target_instance : my_map (the instance we need to use to get the map from)
geoMovieclip will retrieve field and geometry from the ArcIMS server and pass all this information to the movieclip you assign as receiver. In our case we called this movieclip "polydraw_convert"
Step 2: Create a new movieclip. Inside the movieclip we type the following code inside the first frame (Press F9, in the time line click on the first frame). Name this polygon "polydraw_convert". Note that the script only deals with the drawing of the polygon. Nothings else because all the rest is done by geoMovieclip.
//
// Get a link towards the Mapviewer-component
//
var my_map = _root.my_map;
//
// Some variables defining color and line styles
//
var fillColor:Color = new Color("0xFF0000");
var lineColor:Color = new Color("0xFFFFFF");
var fillTransparancy:Number = 30;
var lineTransparancy:Number = 70;
var lineSize:Number = 2
//
// We only want one movieclip to be shown, this routine ensures that the previous movieclip get deleted.
//
if (_global._polyScreen != undefined) {
// Remove the movieclip
_global._polyScreen.removeMovieClip();
}
// remember the movieclip
_global._polyScreen = this;
// set movieclip to the same place as the mapviewer. Top corner.
_x = 0;
_y = 0;
//
// Draw the polygon in case there is one
//
if (fields.polygons.length > 0) {
// clear current drawings
clear();
// Fore very polygon
for (i1 in fields.polygons) {
// Get a polygon, one feature can have more then one polygon.
var pointer = fields.polygons[i1];
// set the fill color
beginFill(fillColor,fillTransparancy);
// set the line style
lineStyle(lineSize, lineColor, lineTransparancy);
// convert map to screen coordinates
var xy = my_map.mapPointToScreenPoint({x:pointer[0],y:pointer[1]},true);
// convert global flash coordinates into local movieclip coordinates
globalToLocal(xy);
// move the pointer to this location
moveTo(xy.x,xy.y);
// for every other point, draw a line
for (var i=2; i < pointer.length;i=i+2) {
var xy = my_map.mapPointToScreenPoint({x:pointer[i],y:pointer[i+1]},true);
globalToLocal(xy);
if (xy.x != undefined && xy.y != undefined) {
lineTo(xy.x,xy.y);
}
}
// Close the polygon and fill it.
endFill();
}
}
Step 3: The movieclip needs to be inside the library, not on the stage! Right click on the "polydraw_convert" movie clip and check the "export for ActionScript". This is an important step otherwise the compiler will not make this movieclip available for script.
The folowing flash application shows you the above example.