Hi,
I have to draw a rectangle( transparent) on mouse click selection. How to proceed for this ? ?
Hi,
I have to draw a rectangle( transparent) on mouse click selection. How to proceed for this ? ?
Sneha,
Thanks for your post and questions.
Try following code snippet shows how to track a transparent rectangle; also, I attached the result for it.
Any more questions please feel free to let me know.
Thanks.
Yale
Hi,
I didn’t receive your code . Will you please attach it again !!
Thanks,
Sneha
Sneha,
I'm sorry that Yale forgot to attach the code snippet to you, here is the code snippet below for your requirements:
public AddFeaturesFromAFeatureLayer()
{
InitializeComponent();
winformsMap1.MapClick += new EventHandler<MapClickWinformsMapEventArgs>(winformsMap1_MapClick);
}
private void AddFeaturesFromAFeatureLayer_Load(object sender, EventArgs e)
{
winformsMap1.MapUnit = GeographyUnit.DecimalDegree;
winformsMap1.CurrentExtent = new RectangleShape(0, 100, 100, 0);
winformsMap1.BackgroundOverlay.BackgroundBrush = new GeoSolidBrush(GeoColor.StandardColors.White);
InMemoryFeatureLayer inMemoryLayer = new InMemoryFeatureLayer();
inMemoryLayer.ZoomLevelSet.ZoomLevel01.DefaultAreaStyle.FillSolidBrush.Color = GeoColor.FromArgb(100, GeoColor.StandardColors.Transparent);
inMemoryLayer.ZoomLevelSet.ZoomLevel01.DefaultAreaStyle.OutlinePen.Color = GeoColor.StandardColors.Blue;
inMemoryLayer.ZoomLevelSet.ZoomLevel01.DefaultLineStyle.OuterPen = new GeoPen(GeoColor.FromArgb(200, GeoColor.StandardColors.Red), 5);
inMemoryLayer.ZoomLevelSet.ZoomLevel01.DefaultPointStyle.SymbolPen = new GeoPen(GeoColor.FromArgb(255, GeoColor.StandardColors.Green), 8);
inMemoryLayer.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20;
LayerOverlay staticOverlay = new LayerOverlay();
staticOverlay.Layers.Add("InMemoryFeatureLayer", inMemoryLayer);
winformsMap1.Overlays.Add("InMemoryOverlay", staticOverlay);
winformsMap1.Refresh();
}
private void winformsMap1_MapClick(object sender, MapClickWinformsMapEventArgs e)
{
InMemoryFeatureLayer inMemoryLayer = (InMemoryFeatureLayer)winformsMap1.FindFeatureLayer("InMemoryFeatureLayer");
PointShape clickPoint = new PointShape(e.WorldX, e.WorldY);
PointShape upperLeftPoint = new PointShape(clickPoint.X - 20, clickPoint.Y + 20);
PointShape lowerRightPoint = new PointShape(clickPoint.X + 20, clickPoint.Y - 20);
RectangleShape rectanglShape = new RectangleShape(upperLeftPoint, lowerRightPoint);
if (inMemoryLayer.InternalFeatures.Count > 0)
{
inMemoryLayer.InternalFeatures.Clear();
}
inMemoryLayer.InternalFeatures.Add(new Feature(rectanglShape));
winformsMap1.Refresh();
}
Thanks,
Scott,
Hi,
Thanks for your feedback.
In the above code, the rectangle drawn is fixed . I need to draw the rectangle according to the user’s mouse click or drag events.
How to achieve this ??
Sneha,
Here is the code snippet for your requirements below:
winformsMap1.TrackOverlay.TrackMode = TrackMode.Rectangle;
winformsMap1.TrackOverlay.TrackShapeLayer.ZoomLevelSet.ZoomLevel01.DefaultAreaStyle.FillSolidBrush.Color = GeoColor.FromArgb(100, GeoColor.StandardColors.Transparent);
winformsMap1.TrackOverlay.TrackShapeLayer.ZoomLevelSet.ZoomLevel01.DefaultAreaStyle.OutlinePen.Color = GeoColor.StandardColors.Blue;
winformsMap1.TrackOverlay.TrackShapeLayer.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20;
The code above allows you to draw the transparent rectangle according to your mouse drag event.
Thanks,
Scott,
Hi,
Thanks for the feedback…
Sneha,
Any more questions please let us know again,
Thanks,
Scott,
Hi,
The above code draws a rectangle. But as soon as the mouse button is up the rectangle also goes off. I want the rectangle to remain. It should go off on mouse double click…
Sneha,
I tested it, when the mouse button is up the rectangle would not be disappear. Please get the latest version to try again,
Thanks,
Scott,