ThinkGeo.com    |     Documentation    |     Premium Support

How to draw a polygon on map

Hi,


I am new to the Map Suite.


I added a ShapeFileFeatureLayer to my winformsMap control.


Now user can zoom in /out of the map, and wants to draw a polygon on the region interested.


How to draw a polygon on  the map and how to get the vertice of the polygon?


Please give some code samples to do these.


Thank you very much.


 


Katherine


 



Katherine,


Thanks for your post and welcome you to ThinkGeo MapSuite Desktop Edition discussion forum.
 
We have a HowDoI sample showing how to add a Polygon to the MapControl, just take a look:
HowDoISamples\ Dynamic Shapes\ HighlightAFeatureOnTheMap
 
Try using the following code to get the verteices out from Polygon, change the logic if you want:

        public Collection<Vertex> GetPolygonVerteices(PolygonShape polygonShape)
        {
            Collection<Vertex> returnVerteices = new Collection<Vertex>();
            foreach (Vertex outRingVertex in polygonShape.OuterRing.Vertices)
            {
                returnVerteices.Add(outRingVertex);
            }
 
            foreach (RingShape innerRing in polygonShape.InnerRings)
            {
                foreach (Vertex innerRingVertex in innerRing.Vertices)
                {
                    returnVerteices.Add(innerRingVertex);
                }
            }
 
            return returnVerteices;
        }

 
Any more questions just feel free to let me know.
 
Thanks.
 
Yale

Hi Yale, 
  
 Thank you very much for your help.  
 In addition to highlight the polygon on the map,  I want user to be able to draw/track a polygon or polyline on the worldLayer, then I need to know the vetices of the polygon or the array of points of the polyline. 
  
 How to get the vertices? Thank you. 
  
 Katherine

Katherine, 
  
 The code snippets above shows you how to get the vertecies out from a Polygon:). 
  
 Any more questions just feel free to let me know. 
  
 Thanks. 
  
 Yale