/// <Summary>
/// Segment the data based on the start and end point to return a set of result points
/// </Summary>
Public ObservableCollection <Point> BuildDrawLineData (ObservableCollection <Point> MapPointList, string StartPeg, string StopPeg)
{
ObservableCollection <Point> Result = new ObservableCollection <Point> ();
Double StartValue = this. MathPegNo (StartPeg );
Double StopValue = this. MathPegNo (StopPeg );
If (StartValue> 1)
MapPointList = this. SplitLineByStartLength (MapPointList, StartValue );
// Intercepted distance
Double ResultLength = StopValue-StartValue;
// The total distance in the segmentation Calculation
Double TotalLength = 0.0;
// Segment distance in segment Calculation
Double FtrLength = 0.0;
// Vertex object in Calculation
Point pt1, pt2;
// Cyclically vertex set and calculate
For (int I = 0; I <MapPointList. Count; I ++)
{
If (I + 1 <MapPointList. Count)
{
Pt1 = MapPointList [I];
Pt2 = MapPointList [I + 1];
FtrLength = this. GetDistance (pt1.Y, pt1.X, pt2.Y, pt2.X );
TotalLength + = FtrLength;
If (TotalLength <ResultLength)
{
// Add the midpoint of the Set
Result. Add (pt1 );
}
Else
{
// Obtain the point in the current line after exceeding the value
Double RemainderLength = 0;
// The Truncation of the last line
RemainderLength = ResultLength-(TotalLength-FtrLength );
// The triangle ratio is calculated for a street.
Double x = Math. Abs (pt2.X-pt1.X );
Double y = Math. Abs (pt2.Y-pt1.Y );
Double x_x = x * (RemainderLength/FtrLength );
Double y_y = y * (RemainderLength/FtrLength );
// Determine the direction and calculate X
If (pt1.X> pt2.X)
X_x = pt1.X-x_x;
Else
X_x = pt1.X + x_x;
// Determine the direction and calculate Y
If (pt1.Y> pt2.Y)
Y_y = pt1.Y-y_y;
Else
Y_y = pt1.Y + y_y;
// Add the last vertex to the result
Result. Add (new Point (x_x, y_y ));
Break;
}
}
Else // Add the last Vertex
Result. Add (MapPointList. Last ());
}
Return Result;
}
// Truncate the vertex set whose supervertex is not zero
Private ObservableCollection <Point> SplitLineByStartLength (ObservableCollection <Point> MapPointList, double StartLength)
{
ObservableCollection <Point> Result = new ObservableCollection <Point> ();
// The total distance in the segmentation Calculation
Double TotalLength = 0.0;
// Segment distance in segment Calculation
Double FtrLength = 0.0;
// Vertex object in Calculation
Point pt1, pt2;
// The amount before the start. This is the first check that exceeds the start point.
Bool IsFirst = true;
// Cyclically vertex set and calculate
For (int I = 0; I <MapPointList. Count; I ++)
{
If (I + 1 <MapPointList. Count)
{
Pt1 = MapPointList [I];
Pt2 = MapPointList [I + 1];
FtrLength = this. GetDistance (pt1.Y, pt1.X, pt2.Y, pt2.X );
TotalLength + = FtrLength;
If (TotalLength> StartLength)
{
If (IsFirst)
{
IsFirst = false;
// Obtain the point in the current line after exceeding the value
Double RemainderLength = 0;
// The Truncation of the last line
RemainderLength = StartLength-(TotalLength-FtrLength );
// The triangle ratio is calculated for a street.
Double x = Math. Abs (pt2.X-pt1.X );
Double y = Math. Abs (pt2.Y-pt1.Y );
Double x_x = x * (RemainderLength/FtrLength );
Double y_y = y * (RemainderLength/FtrLength );
// Determine the direction and calculate X
If (pt1.X> pt2.X)
X_x = pt1.X-x_x;
Else
X_x = pt1.X + x_x;
// Determine the direction and calculate Y
If (pt1.Y> pt2.Y)
Y_y = pt1.Y-y_y;
Else
Y_y = pt1.Y + y_y;
// Add the last vertex to the result
Result. Add (new Point (x_x, y_y ));
}
Else // sort the vertex set after the start point
Result. Add (pt1 );
}
}
Else // Add the last Vertex
Result. Add (MapPointList. Last ());
}
Return Result;
}