using System.Windows; using System.Windows.Controls; using ThinkGeo.MapSuite.Core; using ThinkGeo.MapSuite.WpfDesktopEdition; namespace CSHowDoISamples { public partial class DisplayASimpleMap : UserControl { LayerOverlay overlay = new LayerOverlay(); InMemoryFeatureLayer highLightPointLayer = new InMemoryFeatureLayer(); PolygonShape polygon = new PolygonShape("POLYGON((0 0, 80 0, 80 80, 0 80, 0 0))"); InMemoryFeatureLayer highLightLineLayer = new InMemoryFeatureLayer(); public DisplayASimpleMap() { InitializeComponent(); highLightLineLayer.ZoomLevelSet.ZoomLevel01.DefaultLineStyle = LineStyles.CreateSimpleLineStyle(GeoColor.StandardColors.Red, 2, false); highLightLineLayer.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20; highLightPointLayer.ZoomLevelSet.ZoomLevel01.DefaultPointStyle = PointStyles.CreateSimpleCircleStyle(GeoColor.StandardColors.Red, 10); highLightPointLayer.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20; } private void WpfMap_Loaded(object sender, RoutedEventArgs e) { Map1.MapUnit = GeographyUnit.DecimalDegree; Map1.CurrentExtent = new RectangleShape(-155.733, 95.60, 104.42, -81.9); InMemoryFeatureLayer polygonLayer = new InMemoryFeatureLayer(); polygonLayer.InternalFeatures.Add(new Feature(polygon)); polygonLayer.ZoomLevelSet.ZoomLevel01.DefaultAreaStyle = AreaStyles.Country1; polygonLayer.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20; InMemoryFeatureLayer pointLayer = new InMemoryFeatureLayer(); InMemoryFeatureLayer lineLayer = new InMemoryFeatureLayer(); for (int i = 0; i < polygon.OuterRing.Vertices.Count - 1; i++) { LineShape line = new LineShape(new Vertex[] { polygon.OuterRing.Vertices[i], polygon.OuterRing.Vertices[i + 1] }); lineLayer.InternalFeatures.Add(new Feature(line)); PointShape point = new PointShape(polygon.OuterRing.Vertices[i]); pointLayer.InternalFeatures.Add(new Feature(point)); } overlay.Layers.Add(polygonLayer); overlay.Layers.Add("points", pointLayer); overlay.Layers.Add("lines", lineLayer); overlay.Layers.Add(highLightLineLayer); overlay.Layers.Add(highLightPointLayer); Map1.Overlays.Add("overlay", overlay); Map1.Refresh(); } //map click event private void Map1_MapClick(object sender, MapClickWpfMapEventArgs e) { PointShape point = e.WorldLocation; foreach (var item in ((InMemoryFeatureLayer)overlay.Layers["points"]).InternalFeatures) { if (point.GetDistanceTo(item, GeographyUnit.Meter, DistanceUnit.Meter) < 5) { highLightPointLayer.InternalFeatures.Add(new Feature((PointShape)item.GetShape())); break; } } // ---------------------------------- display line on the side of polygon---------------------------------- //highLightLineLayer.InternalFeatures.Clear(); //foreach (var item in ((InMemoryFeatureLayer)overlay.Layers["lines"]).InternalFeatures) //{ // LineShape line = (LineShape)item.GetShape(); // if (point.GetDistanceTo(item, GeographyUnit.Meter, DistanceUnit.Meter) < 5) // { // highLightLineLayer.InternalFeatures.Add(new Feature(line)); // break; // } //} Map1.Refresh(); } //add a button, and invoke this method private void button1_Click(object sender, RoutedEventArgs e) { LineShape line = new LineShape(); foreach (var item in highLightPointLayer.InternalFeatures) { PointShape point = (PointShape)item.GetShape(); line.Vertices.Add(new Vertex(point)); } MultipolygonShape polygons = line.Buffer(5, GeographyUnit.Meter, DistanceUnit.Meter); polygons = polygons.GetIntersection(polygon); InMemoryFeatureLayer newPolygon = new InMemoryFeatureLayer(); newPolygon.InternalFeatures.Add(new Feature(polygons)); newPolygon.ZoomLevelSet.ZoomLevel01.DefaultAreaStyle = AreaStyles.CreateSimpleAreaStyle(GeoColor.StandardColors.Green); newPolygon.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20; ((LayerOverlay)Map1.Overlays["overlay"]).Layers.Add(newPolygon); Map1.Refresh(); } } }