ThinkGeo.com    |     Documentation    |     Premium Support

How to draw and plot polygon shapes in the map

Hello


am using WPF edition.


Am in need to draw the polygon shape for given location and i need to show it on the map, how i can do this????



 From reading your request, I think that what you want to do is track a polygon on the map and display the result. See the code below to see how I do that. See the comments for the explainations. If this is not what you are looking for, please explain to us in  little more details.



private void LoadPost8010()
{
    //Event handler to get the shape after tracking shape.
    wpfMap1.TrackOverlay.TrackEnded += new EventHandler<TrackEndedTrackInteractiveOverlayEventArgs>(TrackOverlay_TrackEnded);
    //Sets the map to track polygon. Tracks the polygon by clicking on map for each vertex of polygon 
    //and double clicking to end tracking the polygon.
    wpfMap1.TrackOverlay.TrackMode = TrackMode.Polygon;

    wpfMap1.MapUnit = GeographyUnit.DecimalDegree;
    wpfMap1.BackgroundOverlay.BackgroundBrush = new GeoSolidBrush(GeoColor.GeographicColors.ShallowOcean);

    WorldMapKitWmsWpfOverlay worldMapKitDesktopOverlay = new WorldMapKitWmsWpfOverlay();
    wpfMap1.Overlays.Add(worldMapKitDesktopOverlay);

    //InMemoryFeatureLayer to display the result of the tracked polygons.
    InMemoryFeatureLayer inMemoryFeaturelayer = new InMemoryFeatureLayer();
    inMemoryFeaturelayer.ZoomLevelSet.ZoomLevel01.DefaultAreaStyle = AreaStyles.CreateSimpleAreaStyle(GeoColor.FromArgb(150, GeoColor.StandardColors.Red));
    inMemoryFeaturelayer.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20;

    //Puts the InMemoryFeatureLayer on the LayerOverlay.
    LayerOverlay dynamicOverlay = new LayerOverlay();
    dynamicOverlay.Layers.Add("Polygons", inMemoryFeaturelayer);
    wpfMap1.Overlays.Add("DynamicOverlay", dynamicOverlay);

    wpfMap1.CurrentExtent = new RectangleShape(-98, 48, -75, 0);
    wpfMap1.Refresh();
}

//Events to get the result of the tracked polygon after double clicking to end the tracking.
private void TrackOverlay_TrackEnded(object sender, TrackEndedTrackInteractiveOverlayEventArgs e)
{
    LayerOverlay dynamicOverlay = (LayerOverlay)wpfMap1.Overlays["DynamicOverlay"];
    InMemoryFeatureLayer inMemoryFeatureLayer = (InMemoryFeatureLayer)dynamicOverlay.Layers["Polygons"];

    //Adds the tracked feature to InMemoryFeatureLayer from the feature of TrackShapeLayer of TrackOverlay
    inMemoryFeatureLayer.InternalFeatures.Add(wpfMap1.TrackOverlay.TrackShapeLayer.InternalFeatures[0]);

    //Alternative way is to use e.TrackedShape.
    //inMemoryFeatureLayer.InternalFeatures.Add(new Feature(e.TrackShape));

    //Clears the tracked features from TrackShapeLayer.
    wpfMap1.TrackOverlay.TrackShapeLayer.InternalFeatures.Clear();

    //Refreshes only dynamicOverlay so that we don't refresh the entire map.
    wpfMap1.Refresh(dynamicOverlay);
}