Im letting the user draw polygons on the map by manipulating winformsMap1_MapClick. They click on the map to form x number of points, then when they click on the first point (to close the polygon), the polygon should be drawn. The points plotted on the screen is declared as:
InMemoryFeatureLayer markerLayer = new InMemoryFeatureLayer(); markerLayer.ZoomLevelSet.ZoomLevel01.DefaultPointStyle.PointType = PointType.Bitmap; markerLayer.ZoomLevelSet.ZoomLevel01.DefaultPointStyle.Image = new GeoImage("dot.gif");
When i compare the first and last points (on the map they do overlap), it always evaluate to false: BaseShape currentShape = myFeature.GetShape(); BaseShape firstShape = drawLayer.InternalFeatures[0].GetShape(); if (currentShape.Intersects(firstShape))
The PointShapeA.Intersects(PointShapeB) returns true only if PointShapeA and PointShapeB are identical, that’s almost impossible by adding points manually by our hands, even it seems they are totally override, but in fact they are not.
I suggest to get the screen distance between the 2 points and if it is smaller than a threshold, we say it is override. Here is the sample code: private void winformsMap1_MapClick(object sender, WinformsMapClickEventArgs e) { InMemoryFeatureLayer markerLayer = (InMemoryFeatureLayer)winformsMap1.DynamicOverlay.Layers[“markerLayer”]; markerLayer.InternalFeatures.Add(new Feature(e.WorldLocation)); winformsMap1.RefreshDynamic();
// Get the screen distance between the 2 points, sure you can get rid of the Sqrt to make it more efficient double distance = Math.Sqrt(Math.Pow(e.X - firstScreenPointF.X, 2) + Math.Pow(e.Y - firstScreenPointF.Y, 2));
if (distance < 2) { MessageBox.Show(“Overlap!”); } }
Your solution worked, the polygon is drawn correctly as i expected. But i have a side issue though. The markers were drawn with labels that i read in the forum:
InMemoryFeatureLayer markerLabelLayer = new InMemoryFeatureLayer();
There are a couple ways to do that. First, TextStyle has a property called “PointPlacement” which is an enumeration you can set the position of the label, such as UpperLeft or LowerRight. Also, TextStyle has properties XoffsetInPixel and YoffsetInPixel with which you can directly customize the offset of the label. Please have a look the sample Labeling ->”Change the label placement for points” for detail.