ArcGIS API for Flex is mainly built on ArcGIS Server rest API. The client has limited functions and many advanced functions are implemented through geometry service and geoprocessing service. However, some simple functions, such as getting the center point of polygon, bring up a custom window at this point. If services are used for interaction, the user experience may deteriorate. Therefore, you can write some code to implement these functions on the client.
Here is the code I wrote to get the coordinates of the center point from a polygon:
/**
* Author: Wu Yongfeng
* MSN/Email: warrenwyf@gmail.com
*/
Package wuyf
{
Import com. ESRI. AGS. Geometry. extent;
Import com. ESRI. AGS. Geometry. mappoint;
Import com. ESRI. AGS. Geometry. polygon;
Public class geometryutil
{
/**
* Obtain the center of gravity of a polygon.
* @ Param polygon Polygon
* @ Return center of gravity
*
*/
Static public function getgravitycenter (polygon): mappoint
{
VaR Ext: extent = polygon. extent;
VaR P0: mappoint = new mappoint (ext. xmin, ext. ymin );
VaR momentx: Number = 0;
VaR momenty: Number = 0;
VaR weight: Number = 0;
For (var I: Int = 0; I {
VaR PTS: array = polygon. RingsAs array;
For (var j: Int = 0; j {
VaR P1: mappoint = polygon. getpoint (I, j );
VaR P2: mappoint;
If (j = pts. Length-1)
{
P2 = polygon. getpoint (I, 0 );
}
Else
{
P2 = polygon. getpoint (I, j + 1 );
}
VaR dweight: Number = (p1.x-0000x) * (p2.y-p1.y)
-(P1.x-Snapshot X) * (p0.y-p1.y)/2
-(P2.x-Snapshot X) * (p2.y-Snapshot y)/2
-(P1.x-p2.x) * (p2.y-p1.y)/2;
Weight + = dweight;
VaR pTMP: mappoint = new mappoint (p1.x + p2.x)/2, (p1.y + p2.y)/2 );
VaR gravityx: Number = percentile x + (pTMP. x-p0.x) * 2/3;
VaR gravityy: Number = 127y + (pTMP. y-p0.y) * 2/3;
Momentx + = gravityx * dweight;
Momenty + = gravityy * dweight;
}
}
Return new mappoint (momentx/weight, momenty/weight );
}
}
}
See the results: