Hi, Val,
excuse me, it took me too much time and , say the truth, I couldn't make executable sample. If you don't mind, I show you my code in logical way.
private void Form1_Load(object sender, EventArgs e)
{
SqlDataAdapter shipAdapter = new SqlDataAdapter("select Ico,1,2,3 from CPoint order by 1", myConnection);
DataSet shipSet = new DataSet("CPoint");
shipAdapter.Fill(shipSet, "CPoint");
EditInterActiveIcon(shipSet);
}
private void EditInterActiveIcon(DataSet iconSet)
{
// настройка EditInteractiveOverlay
//EditInteractiveOverlay used because it already has the logic for dragging.
EditInteractiveOverlay editInteractiveOverlay = new EditInteractiveOverlay();
//Sets the property IsActive for DragControlPointsLayer to false so that the control point (as four arrows) is not visible.
editInteractiveOverlay.DragControlPointsLayer.ZoomLevelSet.ZoomLevel01.DefaultPointStyle.IsActive = false;
editInteractiveOverlay.DragControlPointsLayer.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20;
//Sets the property IsActive for all the Styles of EditShapesLayer because we are using a ValueStyle instead.
editInteractiveOverlay.EditShapesLayer.ZoomLevelSet.ZoomLevel01.DefaultPointStyle.IsActive = false;
editInteractiveOverlay.EditShapesLayer.ZoomLevelSet.ZoomLevel01.DefaultLineStyle.IsActive = false;
editInteractiveOverlay.EditShapesLayer.ZoomLevelSet.ZoomLevel01.DefaultAreaStyle.IsActive = false;
//ValueStyle used for displaying the feature according to the value of the column "Type" for displaying with a flag or unknown icon.
ValueStyle valueStyle = new ValueStyle();
valueStyle.ColumnName = "Type";
//valueStyle.ColumnName = "Base";
editInteractiveOverlay.EditShapesLayer.ZoomLevelSet.ZoomLevel01.CustomStyles.Clear();
int i = 0;
foreach (DataRow drShip in iconSet.Tables[0].Rows)
{
MemoryStream ms = new MemoryStream((byte[])drShip[0]);
ScalingImageStyle scalingImageStyle = new ScalingImageStyle(GeographyUnit.DecimalDegree, new GeoImage(ms), 100000000, 1000000, 50, 10);
Collection[Style] iconPointStyle = new Collection[Style]();
iconPointStyle.Add(scalingImageStyle);
valueStyle.ValueItems.Add(new ValueItem(Convert.ToString(drShip[1]) + " " + Convert.ToString(drShip[2]), iconPointStyle));
i = i + 1;
}
editInteractiveOverlay.EditShapesLayer.ZoomLevelSet.ZoomLevel01.CustomStyles.Add(valueStyle);
editInteractiveOverlay.EditShapesLayer.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20;
editInteractiveOverlay.EditShapesLayer.Open();
editInteractiveOverlay.EditShapesLayer.Columns.Add(new FeatureSourceColumn("Type"));
editInteractiveOverlay.EditShapesLayer.Columns.Add(new FeatureSourceColumn("Base"));
ScalingTextStyle scalingTextStyle = new ScalingTextStyle(GeographyUnit.DecimalDegree, "[Type]", 100000000, 1000000, 12, 6);
scalingTextStyle.OverlappingRule = LabelOverlappingRule.NoOverlapping;
scalingTextStyle.DuplicateRule = LabelDuplicateRule.OneDuplicateLabelPerQuadrant;
scalingTextStyle.YOffsetInPixel = 30;
ScalingTextStyle scalingTextStyle1 = new ScalingTextStyle(GeographyUnit.DecimalDegree, "[Base]", 100000000, 1000000, 12, 6);
scalingTextStyle1.OverlappingRule = LabelOverlappingRule.NoOverlapping;
scalingTextStyle1.DuplicateRule = LabelDuplicateRule.OneDuplicateLabelPerQuadrant;
scalingTextStyle1.YOffsetInPixel = 45;
editInteractiveOverlay.EditShapesLayer.ZoomLevelSet.ZoomLevel01.CustomStyles.Add(scalingTextStyle);
editInteractiveOverlay.EditShapesLayer.ZoomLevelSet.ZoomLevel01.CustomStyles.Add(scalingTextStyle1);
editInteractiveOverlay.EditShapesLayer.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20;
editInteractiveOverlay.EditShapesLayer.Close();
Collection<Feature> iconFeature = new Collection<Feature>();
i = 0;
foreach (DataRow drShip in iconSet.Tables[0].Rows)
{
iconFeature.Add(new Feature(new PointShape()));
iconFeature[i].ColumnValues["Type"] = Convert.ToString(drShip[1]) + " " + Convert.ToString(drShip[2]);//; // +" " +
iconFeature[i].ColumnValues["Base"] = Convert.ToString(drShip[3]);
editInteractiveOverlay.EditShapesLayer.InternalFeatures.Add(Convert.ToString(drShip[1]) + " " + Convert.ToString(drShip[2]), iconFeature[i]);// + " " +
i = i + 1;
}
//Sets the properties of EditInteractiveOverlay to have the appropriate behavior.
editInteractiveOverlay.CanAddVertex = false;
editInteractiveOverlay.CanDrag = true;
editInteractiveOverlay.CanRemoveVertex = false;
editInteractiveOverlay.CanResize = false;
editInteractiveOverlay.CanRotate = false;
editInteractiveOverlay.CalculateAllControlPoints();
winformsMap1.EditOverlay = editInteractiveOverlay;
winformsMap1.Refresh(winformsMap1.EditOverlay);
//disable the double click modes in order to not have second effect behavior
//of the map when adding or removing an icon by double clicking
winformsMap1.ExtentOverlay.DoubleLeftClickMode = MapDoubleLeftClickMode.Disabled;
winformsMap1.ExtentOverlay.DoubleRightClickMode = MapDoubleRightClickMode.Disabled;
//iconSet.Clear();
}
private void routToolStripMenuItem_Click(object sender, EventArgs e)
// menu Item to determine the rout of moving
{
It = "Root";
dockingWindow1.Text = this.Text + ": " + It;
tripFlag = true;
CustomTrackInteractiveOverlayLine customTrackInteractiveOverlay = new CustomTrackInteractiveOverlayLine();
customTrackInteractiveOverlay.TrackShapeLayer.ZoomLevelSet.ZoomLevel01.DefaultLineStyle = LineStyles.ContestedBorder1;
customTrackInteractiveOverlay.TrackShapeLayer.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20;
winformsMap1.TrackOverlay = customTrackInteractiveOverlay;
winformsMap1.Refresh(winformsMap1.TrackOverlay);
// datagridview1 - grid to show the points of moving
dataGridView1.Visible = true;
dataGridView1.Width = dockingWindow5.Width;
dataGridView1.Height = dataGridView1.ColumnHeadersHeight;
dataGridView1.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize;
dataGridView1.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill;
dataGridView1.Location = new Point(5, 30);
comboBox1.Location = new Point(5, 5); // type vehicle
comboBox2.Location = new Point(comboBox1.Location.X + 130, 5); //number vehicle
comboBox3.Location = new Point(comboBox2.Location.X + 130, 5); //vehicle holder
button1.Location = new Point(dockingWindow5.Width - 300, 5); // to make model of moving
button2.Location = new Point(dockingWindow5.Width - 200, 5); // clear the results of modeling
treeView1.Nodes.Add("Rout");
treeView1.Nodes[treeView1.Nodes.Count - 1].Checked = true;
foreach (ToolStripButton tlsbt in toolStrip1.Items)
{
tlsbt.CheckState = CheckState.Unchecked;
}
//btnTrackNormal.CheckState = CheckState.Checked;
btnTrackLine.CheckState = CheckState.Checked;
}
private void winformsMap1_MapClick(object sender, MapClickWinformsMapEventArgs e)
// making rout points
{
if (e.MouseButton == MapMouseButton.Left)
{
double angle = 0;
double currentDist = 0;
string To = "00:00:00";
pointLineShape.Vertices.Add(new Vertex(e.WorldX, e.WorldY));
DistanceLineShape.Add(pointLineShape);
proj4Projection.Open();
Vertex geoVertex = proj4Projection.ConvertToExternalProjection(pointLineShape.Vertices[pointLineShape.Vertices.Count - 1].X, pointLineShape.Vertices[pointLineShape.Vertices.Count - 1].Y);
if (pointLineShape.Vertices.Count >= 2)
{
angle = GetAngleFromTwoVertices((Vertex)pointLineShape.Vertices[pointLineShape.Vertices.Count - 2], (Vertex)pointLineShape.Vertices[pointLineShape.Vertices.Count - 1]);
PointShape pointShape1 = new PointShape(pointLineShape.Vertices[pointLineShape.Vertices.Count - 2]);
PointShape pointShape2 = new PointShape(pointLineShape.Vertices[pointLineShape.Vertices.Count - 1]);
// Определение дистанции между точками (0.658 - коэффициент, уменьшающий погрешность и представляющий расстояние в милях)
currentDist = Math.Round((pointShape1.GetDistanceTo(pointShape2, GeographyUnit.Meter, DistanceUnit.Meter)* 0.658), 2) ;
To = Convert.ToString(Convert.ToDateTime(CurrentDate) - Convert.ToDateTime(dataGridView1.Rows[0].Cells[6].Value));
}
proj4Projection.Close();
dataGridView1.Rows.Add(1);
dataGridView1.Rows[dataGridView1.Rows.Count - 1].Cells[0].Value = Convert.ToString(dataGridView1.Rows.Count);
dataGridView1.Rows[dataGridView1.Rows.Count - 1].Cells[1].Value = Convert.ToString(e.WorldX);
dataGridView1.Rows[dataGridView1.Rows.Count - 1].Cells[2].Value = Convert.ToString(e.WorldY);
dataGridView1.Rows[dataGridView1.Rows.Count - 1].Cells[3].Value = DecimalDegrees.d_To_DMs(geoVertex.Y, 2, DecimalDegrees.Type.Latitude);// Convert.ToString(e.WorldX);
dataGridView1.Rows[dataGridView1.Rows.Count - 1].Cells[4].Value = DecimalDegrees.d_To_DMs(geoVertex.X, 2, DecimalDegrees.Type.Longitude);
dataGridView1.Rows[dataGridView4.Rows.Count - 1].Cells[5].Value = To.ToString();
dataGridView1.Rows[dataGridView1.Rows.Count - 1].Cells[6].Value = statusBarPanelTimeReader.Text;
dataGridView1.Rows[dataGridView1.Rows.Count - 1].Cells[7].Value = Math.Round(angle,0);
dataGridView1.Rows[dataGridView1.Rows.Count - 1].Cells[8].Value = Math.Round(currentDist*1000/3600,2);
dataGridView1.Height = dataGridView1.Rows[0].Height * (dataGridView1.Rows.Count + 1);
dataGridView1.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill;
if (dataGridView1.Rows.Count >= 11)
{
dataGridView1.Height = dataGridView1.Rows[0].Height * 11;
}
}
}
}
private void button1_Click(object sender, EventArgs e)
// making model of moving
{
if (comboBox1.Text == "" || comboBox2.Text == "" || comboBox3.Text == "" || dataGridView1.Rows.Count == 0)
{
MessageBox.Show("Smth wrong");
return;
}
LineShape shipLine = winformsMap1.TrackOverlay.TrackShapeLayer.InternalFeatures[winformsMap1.TrackOverlay.TrackShapeLayer.InternalFeatures.Count - 1].GetShape() as LineShape;
if (dataGridView1.Rows.Count != shipLine.Vertices.Count-1)
{
MessageBox.Show("Smth wrong");
return;
}
timer5.Interval = 1000;
timer5.Start();
}
int index = 0;
private void timer5_Tick(object sender, EventArgs e)
// timer of moving
{
if (index <= dataGridView1.Rows.Count - 1)
{
winformsMap1.EditOverlay.EditShapesLayer.Open();
winformsMap1.EditOverlay.EditShapesLayer.InternalFeatures.Remove(comboBox1.Text + " " + comboBox2.Text + " " + comboBox3.Text);
PointShape planeShape = new PointShape(Convert.ToDouble(dataGridView1.Rows[index].Cells[1].Value), Convert.ToDouble(dataGridView1.Rows[index].Cells[2].Value));
Feature carFeature = new Feature(planeShape);
{
carFeature.ColumnValues["Type"] = comboBox1.Text + " " + comboBox2.Text;
carFeature.ColumnValues["Base"] = comboBox3.Text;
winformsMap1.EditOverlay.EditShapesLayer.InternalFeatures.Add(comboBox1.Text + " " + comboBox2.Text + " " + comboBox3.Text, carFeature);
winformsMap1.EditOverlay.CanDrag = true;
winformsMap1.EditOverlay.CalculateAllControlPoints();
winformsMap1.Refresh(winformsMap1.EditOverlay);
index = index + 1;
}
}
else
{
index = 0;
}
}
private double GetAngleFromTwoVertices(Vertex fromVertex, Vertex toVertex)
{
double alpha;
// Avoid divide by zero run values.
if ((int)toVertex.Y - (int)fromVertex.Y == 0)
{
if ((int)toVertex.X > (int)fromVertex.X)
alpha = 90;
else
alpha = 270;
}
else
{
// Calculate angle from offset.
double riseoverrun = (double)((int)toVertex.X - (int)fromVertex.X) / (double)((int)toVertex.Y - (int)fromVertex.Y);
double radians = Math.Atan(riseoverrun);
alpha = radians * ((double)180 / Math.PI);
// Handle quadrant specific transformations.
if (((int)toVertex.X - (int)fromVertex.X) > 0 && ((int)toVertex.Y - (int)fromVertex.Y) < 0) //
alpha += 180;
if (((int)toVertex.X - (int)fromVertex.X) < 0 && ((int)toVertex.Y - (int)fromVertex.Y) < 0) //
alpha += 180;
if (alpha < 0) //
alpha += 360;
if (alpha == 0 && (int)toVertex.Y - (int)fromVertex.Y < 0)
alpha = 180;
}
return alpha;
}
So in this code I try to make the model of moving vehicle, which is in EditInteractiveOverlay & which has custom style - ScalingImageStyle. Everything is OK, my image moves, but it do not turn to the angle of moving.
((ScalingImageStyle)(valueStyle.ValueItems[valueStyle.ValueItems.Count - 1].CustomStyles[0])).RotationAngle = 45;
doesn't work.
Thank you for your help,
Nick