Concept and algorithm of Flex + blazeds on military standards

Source: Internet
Author: User

Turn: http://bbs.esrichina-bj.cn/esri/viewthread.php? Tid = 57166

This post was last edited by _ Daniel at, 2009-11-12

A few days ago, I said that I would like to pass on the military standard algorithm IDEA. The result is delayed. Now I want to talk about my military standard idea.
The first technology used: the front-end as language draws the military logo (actually a polygon) and forms the points of the Polygon into an XML string. Here we can also transmit objects, however, the same corresponding object must be included in the background Java section. It is uploaded to the background through the remoteobject method of blazeds.
The backend can be saved to the database through Java, which is best saved as the clob field.
Below I will share the key code with you ..

// Process the mouse click event
Public Function map_mouseclickhandler (Event: mouseevent): void
{
Map. mapnavigationenabled = false;
// Confirm the coordinates of the clicked map points and place them in the array.
VaR m_point: mappoint = map. tomapfromstage (event. stagex, event. stagey );
If (m_firstpoints = NULL)
{
M_firstpoints = new array ();
}
M_firstpoints.push (m_point );
}
// Process double-click events
Public Function map_mousedoubleclickhandler (Event: mouseevent): void
{
M_gbjgeometry = new polyline ();
// Define the military label Polygon
If (m_firstpoints.length <= 2)
{
M_firstpoints.splice (0 );
Alert. Show ("Please click at least three points to complete the painting of the military logo", "error Info ");
Return;
}
// Draw lines and Surfaces Based on the besell Curve Algorithm
Drawbeziercurve ();
// Form graphic
Full_polygon_graphic = new graphic (full_gbjpolygon, gbjsymbol );
Full_polygon_graphic.tooltip = "GBJ ";
Full_gbjpolygon.spatialreference = map. spatialreference;
Graphicslayer. Add (full_polygon_graphic );
Map. removeeventlistener (mouseevent. Click, map_mouseclickhandler );
Map. removeeventlistener (mouseevent. double_click, map_mousedoubleclickhandler );
M_firstpoints.splice (0 );
This. dispatchevent (New drawevent ("drawend", full_polygon_graphic ));
}

/**
* This is the besell curve algorithm function used to draw military labels.
*
*/
Private function drawbeziercurve (): void
{
// The main algorithm IDEA is: determine a straight line from two points on the central axis, create a vertical line, and take the point at a certain distance on the vertical line to form the top curve and the bottom curve
If (m_gbjgeometry.paths! = NULL) & (m_gbjgeometry.paths.length> 0 ))
{
M_gbjgeometry.removepath (0 );
}
// Determine the quarterly parity of the click point to obtain the military star polygon
VaR jishu: Boolean = true;
If (m_firstpoints.length % 2 = 0)
{
Jishu = false;
}
Clogger.logger.info ("is the number of clicks odd?" + jishu );
VaR curvepoints: array = getzz_geometry (m_firstpoints, jishu );

VaR dgbj_geometry: array = getdbx_geometry (curvepoints );
Full_gbjpolygon = new polygon (dgbj_geometry );
}
/**
* This function is used to find all vertices on the central axis.
* @ Param clickarray
* @ Param jishu
* @ Return
*
*/
Private function getzz_geometry (clickarray: array, jishu: Boolean): Array
{
// First define the coordinate of the center axis curve
VaR curvepoints: array = new array ();
// Array Length
VaR array_length: Number = clickarray. length;
If (jishu)
{
Clogger.logger.info ("the number of clicks is an odd number, and the value is greater than or equal to three. It is:" + clickarray. Length + ");
For (var I: Int = 0; I <clickarray. Length-2; I = I + 2)
{
For (var j: Number = 0; j <= 1; j = J + 0.1)
{
If (I! = 0 & J = 0)
Continue;
VaR pos_x: Number = math. pow (1-j), 2) * clickarray. X + 2 * j * (1-j) * clickarray [I + 1]. X + math. pow (J, 2) * clickarray [I + 2]. x;
VaR pos_y: Number = math. pow (1-j), 2) * clickarray. Y + 2 * j * (1-j) * clickarray [I + 1]. Y + math. pow (J, 2) * clickarray [I + 2]. y;
VaR m_point: mappoint = new mappoint (pos_x, pos_y );
Curvepoints. Push (m_point );
}
}
}
// After the following is an even number, the preceding vertices are determined by three vertices, and the last four vertices are determined by the three besell curves.
If (! Jishu)
{
// Determine whether there are more than six click points. If there are six click points, first calculate the first three using the quadratic besell curve.
If (clickarray. length> = 6)
{
Clogger.logger.info ("the number of clicks is an even number, and the value is greater than or equal to 6. It is:" + clickarray. Length + ");
For (var I: Int = 0; I <clickarray. Length-5; I = I + 2)
{
For (var j: Number = 0; j <= 1; j = J + 0.1)
{
If (I! = 0 & J = 0)
Continue;
VaR pos_x: Number = math. pow (1-j), 2) * clickarray. X + 2 * j * (1-j) * clickarray [I + 1]. X + math. pow (J, 2) * clickarray [I + 2]. x;
VaR pos_y: Number = math. pow (1-j), 2) * clickarray. Y + 2 * j * (1-j) * clickarray [I + 1]. Y + math. pow (J, 2) * clickarray [I + 2]. y;
VaR m_point: mappoint = new mappoint (pos_x, pos_y );
// Number of central axis points
Curvepoints. Push (m_point );
}
}
// The last four vertices are determined by the three besels curve.
VaR P_1: mappoint = clickarray [array_length-4];
VaR P_2: mappoint = clickarray [array_length-3];
VaR P_3: mappoint = clickarray [array_length-2];
VaR P_4: mappoint = clickarray [array_length-1];
For (var k: Number = 0; k <1; k = K + 0.1)
{
If (k = 0)
Continue;
VaR pos_x: Number = p_1.x * Math. pow (1-k), 3) + 3 * p_2.x * K * Math. pow (1-k), 2) + 3 * p_3.x * Math. pow (K, 2) * (1-k) + p_4.x * Math. pow (K, 3 );
VaR pos_y: Number = p_1.y * Math. pow (1-k), 3) + 3 * p_2.y * K * Math. pow (1-k), 2) + 3 * p_3.y * Math. pow (K, 2) * (1-k) + p_4.y * Math. pow (K, 3 );
VaR m_point: mappoint = new mappoint (pos_x, pos_y );
// Add a central axis
Curvepoints. Push (m_point );
}
}
// If there are only four vertices, the following is the formula for finding only four vertices.
Else
{
Clogger.logger.info ("the number of clicks is 4, and the number is:" + clickarray. Length + ");
VaR P_1: mappoint = clickarray [0];
VaR P_2: mappoint = clickarray [1];
VaR P_3: mappoint = clickarray [2];
VaR P_4: mappoint = clickarray [3];
For (var k: Number = 0; k <1; k = K + 0.1)
{
VaR pos_x: Number = p_1.x * Math. pow (1-k), 3) + 3 * p_2.x * K * Math. pow (1-k), 2) + 3 * p_3.x * Math. pow (K, 2) * (1-k) + p_4.x * Math. pow (K, 3 );
VaR pos_y: Number = p_1.y * Math. pow (1-k), 3) + 3 * p_2.y * K * Math. pow (1-k), 2) + 3 * p_3.y * Math. pow (K, 2) * (1-k) + p_4.y * Math. pow (K, 3 );
VaR m_point: mappoint = new mappoint (pos_x, pos_y );
// Add a central axis
Curvepoints. Push (m_point );
}
}
}
Clogger.logger.info ("the number of all vertices on this axis is:" + curvepoints. Length );
Return curvepoints;
}

/**
* This function is used to find the vertices of a multilateral row.
* The principle used is to find the vertical line distance.
* @ Return
*
*/
Private function getdbx_geometry (curvepoints: array): Array
{
// Defines the coordinate array of vertices on the top curve (I started from this array when determining the military polygon)
VaR topcurepoints: array = new array ();
// Define the coordinate array of the following Curve
VaR bottomcurepoints: array = new array ();
// Define the line in the upper left corner
VaR left_top_points: array = new array ();
// Define the line at the bottom left.
VaR left_bottom_points: array = new array ();
// Define the array of edges in the upper-right corner
VaR right_top_points: array = new array ();
// Define the distance between the central axis and the upper and lower sides
VaR DIS: Number = (8-map. Level) * (8-map. Level) * 40;
// The large frame must be 0-1
VaR c_length: Number = curvepoints. length;
For (var u: Number = 0; U <curvepoints. length; U ++)
{
If (u = 0)
{
Continue;
}
Else
{
VaR m_point: mappoint = curvepoints;
VaR pos_x: Number = m_point.x;
VaR pos_y: Number = m_point.y;
// First obtain the coordinates of the last Vertex
VaR pre_point: mappoint = curvepoints [U-1];
// Calculate the vertices of the upper and lower edges.
VaR pre_pos_x: Number = pre_point.x;
VaR pre_pos_y: Number = pre_point.y;
VaR slope: Number = (pos_y-pre_pos_y)/(pos_x-pre_pos_x );
// Click OK.
VaR BB: Number = Dis * (1-U/c_length * 0.9 );
VaR cos_number: Number = math. Cos (math. atan (slope)-math. PI/2 );
VaR sin_number: Number = math. Sin (math. atan (slope)-math. PI/2 );
VaR top_pos_x: Number = 0.0;
VaR top_pos_y: Number = 0.0;
// Draw lines in four cases.
If (pre_pos_x <= pos_x & pre_pos_y <= pos_y)
{
Top_pos_x = pre_pos_x-(BB * cos_number) <0? (-BB * cos_number): (BB * cos_number ));
Top_pos_y = pre_pos_y + (BB * sin_number) <0? (-BB * sin_number): (BB * sin_number ));
}
Else if (pre_pos_x <= pos_x & pre_pos_y> pos_y)
{
Top_pos_x = pre_pos_x + (BB * cos_number) <0? (-BB * cos_number): (BB * cos_number ));
Top_pos_y = pre_pos_y + (BB * sin_number) <0? (-BB * sin_number): (BB * sin_number ));
}
Else if (pre_pos_x> = pos_x & pre_pos_y> = pos_y)
{
Top_pos_x = pre_pos_x + (BB * cos_number) <0? (-BB * cos_number): (BB * cos_number ));
Top_pos_y = pre_pos_y-(BB * sin_number) <0? (-BB * sin_number): (BB * sin_number ));
}
Else if (pre_pos_x> = pos_x & pre_pos_y <= pos_y)
{
Top_pos_x = pre_pos_x-(BB * cos_number) <0? (-BB * cos_number): (BB * cos_number ));
Top_pos_y = pre_pos_y-(BB * sin_number) <0? (-BB * sin_number): (BB * sin_number ));
}
VaR top_point: mappoint = new mappoint (top_pos_x, top_pos_y );
Clogger.logger.info ("the upper part is:" + top_pos_x + "YY:" + top_pos_y );
Topcurepoints. Push (top_point );
// Determine the curve below
VaR bottom_pos_x: number;
VaR bottom_pos_y: number;
If (pre_pos_x <= pos_x & pre_pos_y <= pos_y)
{
Bottom_pos_x = pre_pos_x + (BB * cos_number) <0? (-BB * cos_number): (BB * cos_number ));
Bottom_pos_y = pre_pos_y-(BB * sin_number) <0? (-BB * sin_number): (BB * sin_number ));
}
Else if (pre_pos_x <= pos_x & pre_pos_y> pos_y)
{
Bottom_pos_x = pre_pos_x-(BB * cos_number) <0? (-BB * cos_number): (BB * cos_number ));
Bottom_pos_y = pre_pos_y-(BB * sin_number) <0? (-BB * sin_number): (BB * sin_number ));
}
Else if (pre_pos_x> = pos_x & pre_pos_y> = pos_y)
{
Bottom_pos_x = pre_pos_x-(BB * cos_number) <0? (-BB * cos_number): (BB * cos_number ));
Bottom_pos_y = pre_pos_y + (BB * sin_number) <0? (-BB * sin_number): (BB * sin_number ));
}
Else if (pre_pos_x> = pos_x & pre_pos_y <= pos_y)
{
Bottom_pos_x = pre_pos_x + (BB * cos_number) <0? (-BB * cos_number): (BB * cos_number ));
Bottom_pos_y = pre_pos_y + (BB * sin_number) <0? (-BB * sin_number): (BB * sin_number ));
}
VaR bottom_point: mappoint = new mappoint (bottom_pos_x, bottom_pos_y );
Bottingurepoints. Push (bottom_point );
}
}
/*
** The following is a program for adding military arrows, because the upper and lower boundary curves have been obtained.
**
*/
VaR end_curvepoint: mappoint = curvepoints [curvepoints. Length-1];
VaR end_top_point: mappoint = topcurepoints [topcurepoints. Length-1];
VaR end_top_point2: mappoint = topcurepoints [topcurepoints. Length-2];
// Find the point above the Arrow
VaR X2: Number = end_curvepoint.x;
VaR Y2: Number = end_curvepoint.y;
VaR pos_x: Number = end_top_point.x;
VaR pos_y: Number = end_top_point.y;
VaR pre_pos_x: Number = end_top_point2.x;
VaR pre_pos_y: Number = end_top_point2.y;
VaR end_slope: Number = (pre_pos_y-pos_y)/(pre_pos_x-pos_x );
VaR B: Number = DIS;
VaR end_point_x: number;
VaR end_point_y: number;
VaR cos_number: Number = math. Cos (math. atan (end_slope)-math. PI/2 );
VaR sin_number: Number = math. Sin (math. atan (end_slope)-math. PI/2 );
// Draw lines in four cases.
If (pre_pos_x <= pos_x & pre_pos_y <= pos_y)
{
End_point_x = pre_pos_x-(B * cos_number) <0? (-B * cos_number): (B * cos_number ));
End_point_y = pre_pos_y + (B * sin_number) <0? (-B * sin_number): (B * sin_number ));
}
Else if (pre_pos_x <= pos_x & pre_pos_y> pos_y)
{
End_point_x = pre_pos_x + (B * cos_number) <0? (-B * cos_number): (B * cos_number ));
End_point_y = pre_pos_y + (B * sin_number) <0? (-B * sin_number): (B * sin_number ));
}
Else if (pre_pos_x> = pos_x & pre_pos_y> = pos_y)
{
End_point_x = pre_pos_x + (B * cos_number) <0? (-B * cos_number): (B * cos_number ));
End_point_y = pre_pos_y-(B * sin_number) <0? (-B * sin_number): (B * sin_number ));
}
Else if (pre_pos_x> = pos_x & pre_pos_y <= pos_y)
{
End_point_x = pre_pos_x-(B * cos_number) <0? (-B * cos_number): (B * cos_number ));
End_point_y = pre_pos_y-(B * sin_number) <0? (-B * sin_number): (B * sin_number ));
}
// Create the third vertex, and then create a triangle
Clogger.logger.info ("X:" + end_point_x + "---------- Y:" + end_point_y );
// Obtain the point in the upper-right corner.
VaR end_right_point: mappoint = new mappoint (end_point_x, end_point_y );
Topcurepoints. Push (end_right_point );
// The rightmost coordinate of the arrow vertex is
Clogger.logger.info ("the X coordinate of the vertex is X:" + end_curvepoint.x + "--------- y coordinate of the vertex:" + end_curvepoint.y );
Topcurepoints. Push (end_curvepoint );
// Bottom line
VaR end_bottom_point: mappoint = bottingurepoints [bottingurepoints. Length-1];
VaR end_bottom_point2: mappoint = bottingurepoints [bottingurepoints. Length-2];
// Calculate the point at the bottom of the arrow
VaR bx1: Number = end_bottom_point.x;
VaR by1: Number = end_bottom_point.y;
VaR bx0: Number = end_bottom_point2.x;
VaR by0: Number = end_bottom_point2.y;
VaR bend_slope: Number = (by1-by0)/(bx1-bx0 );
VaR bend_point_x: number;
VaR bend_point_y: number;
VaR bend_cos_number: Number = math. Cos (math. atan (bend_slope)-math. PI/2 );
VaR bend_sin_number: Number = math. Sin (math. atan (bend_slope)-math. PI/2 );
If (bx0 <= bx1 & by0 <= BY1)
{
Bend_point_x = bx0 + (B * bend_cos_number) <0? (-B * bend_cos_number): (B * bend_cos_number ));
Bend_point_y = by0-(B * bend_sin_number) <0? (-B * bend_sin_number): (B * bend_sin_number ));
}
Else if (bx0 <= bx1 & by0> BY1)
{
Bend_point_x = bx0-(B * bend_cos_number) <0? (-B * bend_cos_number): (B * bend_cos_number ));
Bend_point_y = by0-(B * bend_sin_number) <0? (-B * bend_sin_number): (B * bend_sin_number ));
}
Else if (bx0> = bx1 & by0> = BY1)
{
Bend_point_x = bx0-(B * bend_cos_number) <0? (-B * bend_cos_number): (B * bend_cos_number ));
Bend_point_y = by0 + (B * bend_sin_number) <0? (-B * bend_sin_number): (B * bend_sin_number ));
}
Else if (bx0> = bx1 & by0 <= BY1)
{
Bend_point_x = bx0 + (B * bend_cos_number) <0? (-B * bend_cos_number): (B * bend_cos_number ));
Bend_point_y = by0 + (B * bend_sin_number) <0? (-B * bend_sin_number): (B * bend_sin_number ));
}
Clogger.logger.info ("the X coordinate of the point below is:" + bend_point_x + "------- the Y coordinate of the point below is:" + bend_point_y );
// Obtain the point in the lower right corner.
VaR bend_right_point: mappoint = new mappoint (bend_point_x, bend_point_y );
Topcurepoints. Push (bend_right_point );
For (var k: Number = bottomcurepoints. Length-1; k> = 0; k --)
{
// This is the lower half
Clogger.logger.info ("the lower part starting from this:" + bottingurepoints [K]. x + "yyyyy:" + bottingurepoints [K]. y );
Topcurepoints. Push (bottingurepoints [k]);
}
// Add the tail part to complete the algorithm for marking the multilateral lines of the military,
Topcurepoints. Push (curvepoints [1]);
Topcurepoints. Push (topcurepoints [0]);
Clogger.logger.info ("the number of points on the military mark is" + topcurepoints. Length );
VaR rings: array = new array ();
Rings. Push (topcurepoints );
Return rings;
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.