Hi! Please, help! I need correctly show the pointShapes if they are in the radar zone. I use your project SweepAngleDesktopEditiion, but not with static points. I take from "How do I..." dynamic shape sample where the points move random. The first entering to radar zone the points show correct - they become yellow, but the second, the third and so on the yellow point on radar zone do not move due to random moving of pointShape. Excuse my topic - code is too much :(
// This Item to activate radar
private void radarToolStripMenuItem_Click(object sender, EventArgs e)
{
//Displays the polygon for sweep angle.
InMemoryFeatureLayer inMemoryFeatureLayer = new InMemoryFeatureLayer();
inMemoryFeatureLayer.ZoomLevelSet.ZoomLevel01.DefaultAreaStyle = AreaStyles.CreateHueFamilyLinearGradientAreaStyle(GeoColor.StandardColors.Transparent, GeoColor.StandardColors.Yellow,
5, GeoColor.FromArgb(150, GeoColor.StandardColors.Blue), GeoColor.FromArgb(150, GeoColor.StandardColors.Red), 45);
inMemoryFeatureLayer.ZoomLevelSet.ZoomLevel01.DefaultPointStyle = PointStyles.CreateSimplePointStyle(PointSymbolType.Circle, GeoColor.StandardColors.Yellow, 10);
inMemoryFeatureLayer.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20;
InMemoryFeatureLayer pointsInMemoryFeatureLayer = new InMemoryFeatureLayer();
pointsInMemoryFeatureLayer.ZoomLevelSet.ZoomLevel01.DefaultPointStyle = PointStyles.CreateSimplePointStyle(PointSymbolType.Circle, GeoColor.StandardColors.Yellow, 10);
pointsInMemoryFeatureLayer.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20;
//Collection of PointShapes to do the spatial query based on the sweep angle PolygonShape.
//pointShapes.Add(new PointShape(192.2297, 3934.9704));
//pointShapes.Add(new PointShape(196.2452, 3935.9696));
//pointShapes.Add(new PointShape(194.2597, 3937.9676));
//pointShapes.Add(new PointShape(195.2565, 3936.9581));
//pointShapes.Add(new PointShape(197.2455, 3938.947));
//pointShapes.Add(new PointShape(198.2352, 3939.9531));
//-------------------------------------------------------------------------------------------
LayerOverlay dynamicLayerOverlay = new LayerOverlay();
dynamicLayerOverlay.Layers.Add("Sweep Angle", inMemoryFeatureLayer);
dynamicLayerOverlay.Layers.Add("Points", pointsInMemoryFeatureLayer);
winformsMap1.Overlays.Add("Dynamic Overlay", dynamicLayerOverlay);
timer1.Interval = 1;
timer1.Start();
winformsMap1.Refresh(dynamicLayerOverlay);
}
private void timer1_Tick(object sender, EventArgs e)
{
try
{
if (sweepAngle >= 180) sweepAngle = 91F;
//Updates the sweep angle polygon
LayerOverlay dynamicLayerOverlay = (LayerOverlay)winformsMap1.Overlays["Dynamic Overlay"];
InMemoryFeatureLayer inMemoryFeatureLayer = (InMemoryFeatureLayer)dynamicLayerOverlay.Layers["Sweep Angle"];
InMemoryFeatureLayer pointsInMemoryFeatureLayer = (InMemoryFeatureLayer)dynamicLayerOverlay.Layers["Points"];
InMemoryFeatureLayer pointsInMemoryFeatureLayer = new InMemoryFeatureLayer();
pointsInMemoryFeatureLayer.ZoomLevelSet.ZoomLevel01.DefaultPointStyle = PointStyles.CreateSimplePointStyle(PointSymbolType.Circle, GeoColor.StandardColors.Yellow, 10);
pointsInMemoryFeatureLayer.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20;
inMemoryFeatureLayer.Open();
inMemoryFeatureLayer.EditTools.BeginTransaction();
inMemoryFeatureLayer.InternalFeatures.Clear();
PolygonShape polygonShape = CreatePie(new PointShape(17, 83), 90F, sweepAngle, 0.1F, 0.2F);
inMemoryFeatureLayer.EditTools.Add(new Feature(polygonShape));
inMemoryFeatureLayer.EditTools.CommitTransaction();
inMemoryFeatureLayer.Close();
//Updates the points based on spatial query.
pointsInMemoryFeatureLayer.InternalFeatures.Clear();
pointsInMemoryFeatureLayer.Open();
pointsInMemoryFeatureLayer.EditTools.BeginTransaction();
//pointsInMemoryFeatureLayer.InternalFeatures.Clear();
foreach (PointShape pointShape in pointShapes)
{
if (polygonShape.Contains(pointShape))
{
pointsInMemoryFeatureLayer.EditTools.Add(new Feature(pointShape));
dynamicLayerOverlay.Layers.Add(pointsInMemoryFeatureLayer);
}
}
pointsInMemoryFeatureLayer.EditTools.CommitTransaction();
pointsInMemoryFeatureLayer.Close();
sweepAngle = sweepAngle + 10;
winformsMap1.Refresh(dynamicLayerOverlay);
}
catch
{
}
}
// This code from sample of points random moving
private readonly RectangleShape pointsBoundary = new RectangleShape(97.26, 3948.52, 229.43, 3853.20);
private System.Threading.Timer movePointsTimer;
private System.Threading.Timer changeColorTimer;
private static Random random = new Random();
private delegate void ToUIThreadDelegate();
private void целераспределениеToolStripMenuItem_Click(object sender, EventArgs e)
{
movePointsTimer = new System.Threading.Timer(new TimerCallback(MovePoints));
changeColorTimer = new System.Threading.Timer(new TimerCallback(ChangeColor));
InMemoryFeatureLayer pointsLayer = new InMemoryFeatureLayer();
pointsLayer.ZoomLevelSet.ZoomLevel01.DefaultPointStyle = new PointStyle(PointSymbolType.Circle, new GeoSolidBrush(GeoColor.StandardColors.Blue), 10);
pointsLayer.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20;
//PointShape pointShape = GetRandomPoint(pointsBoundary);
//LayerOverlay pointsOverlay = new LayerOverlay();
depOverlay.Layers.Add("Points", pointsLayer);
winformsMap1.Refresh();
int pointsCount = Convert.ToInt32(30);
InMemoryFeatureLayer pointsLayer1 = (InMemoryFeatureLayer)winformsMap1.FindFeatureLayer("Points");
//Overlay pointsOverlay = winformsMap1.Overlays["depOverlay"];
pointsLayer1.InternalFeatures.Clear();
for (int i = 0; i < pointsCount; i++)
{
PointShape pointShape = GetRandomPoint(pointsBoundary);
string id = GetRandomDirection().ToString();
Feature feature = new Feature(pointShape.X, pointShape.Y, id);
pointsLayer1.InternalFeatures.Add(feature);
pointShapes.Add(new PointShape(pointShape.X,pointShape.Y));
}
winformsMap1.Refresh(depOverlay);
// Starts the move points timer
movePointsTimer.Change(0, Convert.ToInt32(5000));
// Starts the color changing timer
//changeColorTimer.Change(0, Convert.ToInt32(1200));
//btnBegin.Enabled = false;
//btnStop.Enabled = true;
}
private void MovePoints(object obj)
{
this.BeginInvoke(new ToUIThreadDelegate(MovePointsOnUIThread));
}
private void MovePointsOnUIThread()
{
InMemoryFeatureLayer pointsLayer = (InMemoryFeatureLayer)winformsMap1.FindFeatureLayer("Points");
//Overlay pointsOverlay = winformsMap1.Overlays["PointsOverlay"];
Collection features = new Collection();
for (int i = 0; i < pointsLayer.InternalFeatures.Count; i++)
{
PointShape shape = pointsLayer.InternalFeatures.GetShape() as PointShape;
string id = pointsLayer.InternalFeatures.Id;
PanDirection direction = (PanDirection)PanDirection.Parse(typeof(PanDirection), id, true);
if (shape.X > pointsBoundary.UpperLeftPoint.X && shape.X < pointsBoundary.LowerRightPoint.X && shape.Y < pointsBoundary.UpperLeftPoint.Y && shape.Y > pointsBoundary.LowerRightPoint.Y)
{
UpdatePointShape(shape, direction);
}
else
{
id = ReverseDirection(shape, direction).ToString();
}
features.Add(new Feature(shape.X, shape.Y, id));
}
pointsLayer.InternalFeatures.Clear();
foreach (Feature item in features)
{
pointsLayer.InternalFeatures.Add(item);
}
winformsMap1.Refresh(depOverlay);
}
private void ChangeColor(object obj)
{
this.BeginInvoke(new ToUIThreadDelegate(ChangeColorOnUIThread));
}
private void ChangeColorOnUIThread()
{
InMemoryFeatureLayer pointsLayer = (InMemoryFeatureLayer)winformsMap1.FindFeatureLayer("Points");
//Overlay pointsOverlay = winformsMap1.Overlays["PointsOverlay"];
pointsLayer.ZoomLevelSet.ZoomLevel01.DefaultPointStyle = new PointStyle(PointSymbolType.Circle, new GeoSolidBrush(GeoColor.GetRandomGeoColor(RandomColorType.All)), 10);
winformsMap1.Refresh(depOverlay);
}
private void btnStop_Click(object sender, EventArgs e)
{
movePointsTimer.Change(0, Timeout.Infinite);
changeColorTimer.Change(0, Timeout.Infinite);
//btnBegin.Enabled = true;
//btnStop.Enabled = false;
}
private void RefreshPointsRandomly_ParentChanged(object sender, EventArgs e)
{
movePointsTimer.Change(0, Timeout.Infinite);
changeColorTimer.Change(0, Timeout.Infinite);
//btnBegin.Enabled = true;
//btnStop.Enabled = false;
}
private static PanDirection ReverseDirection(PointShape shape, PanDirection direction)
{
PanDirection newDirection = PanDirection.Down;
switch (direction)
{
case PanDirection.Up:
newDirection = PanDirection.Down;
break;
case PanDirection.UpperRight:
newDirection = PanDirection.LowerLeft;
break;
case PanDirection.Right:
newDirection = PanDirection.Left;
break;
case PanDirection.LowerRight:
newDirection = PanDirection.UpperLeft;
break;
case PanDirection.Down:
newDirection = PanDirection.Up;
break;
case PanDirection.LowerLeft:
newDirection = PanDirection.UpperRight;
break;
case PanDirection.Left:
newDirection = PanDirection.Right;
break;
case PanDirection.UpperLeft:
newDirection = PanDirection.LowerRight;
break;
default:
break;
}
UpdatePointShape(shape, newDirection);
return newDirection;
}
private static void UpdatePointShape(PointShape shape, PanDirection direction)
{
switch (direction)
{
case PanDirection.Up:
shape.Y++;
break;
case PanDirection.UpperRight:
shape.X++;
shape.Y++;
break;
case PanDirection.Right:
shape.X++;
break;
case PanDirection.LowerRight:
shape.X++;
shape.Y--;
break;
case PanDirection.Down:
shape.Y--;
break;
case PanDirection.LowerLeft:
shape.X--;
shape.Y--;
break;
case PanDirection.Left:
shape.X--;
break;
case PanDirection.UpperLeft:
shape.X--;
shape.Y++;
break;
default:
break;
}
}
public static PointShape GetRandomPoint(RectangleShape currentExtent)
{
double x = random.Next((int)currentExtent.UpperLeftPoint.X, (int)currentExtent.LowerRightPoint.X);
double y = random.Next((int)currentExtent.LowerRightPoint.Y, (int)currentExtent.UpperLeftPoint.Y);
PointShape pointShape = new PointShape(x, y);
return pointShape;
}
public static PanDirection GetRandomDirection()
{
int i = random.Next(8);
PanDirection panDirection = (PanDirection)i;
return panDirection;
}
}
Thank you.