private void mapBox1_MouseMove(Coordinate worldPos, MouseEventArgs imagePos) { string tooltip = string.Empty; Envelope infoPoint = new Envelope(worldPos.CoordinateValue); infoPoint.ExpandBy(mapBox1.Map.PixelSize * 30); foreach (Layer layer in mapBox1.Map.Layers) { if (layer is TearDropLayer) { TearDropLayer tdl = (TearDropLayer)layer; FeatureDataSet ds = new FeatureDataSet(); if (!tdl.DataSource.IsOpen) { tdl.DataSource.Open(); } tdl.DataSource.ExecuteIntersectionQuery(infoPoint, ds); tdl.DataSource.Close(); foreach (FeatureDataRow row in ds.Tables[0].Rows) { MapLocation line = (MapLocation)row["MapLocation"]; string colour = (string)row["Colour"]; if (colour == TearDropLayer.GREY) { tooltip += line.ToString() + "\n"; } } } } if (!tooltip.Equals(mapTooltip.GetToolTip(mapBox1))) { mapTooltip.SetToolTip(mapBox1, tooltip); } }
private void SetupMap() { lifelines = new FeatureDataTable(); lifelines.Columns.Add("MapLifeLine", typeof(MapLifeLine)); lifelines.Columns.Add("LineCap", typeof(string)); lifelines.Columns.Add("Label", typeof(string)); lifelines.Columns.Add("ViewPort", typeof(Envelope)); GeometryFeatureProvider lifelinesGFP = new GeometryFeatureProvider(lifelines); VectorStyle linestyle = new VectorStyle { Line = new Pen(Color.Green, 2f) }; linestyle.Line.MiterLimit = 0; linesLayer = new VectorLayer("LifeLines") { DataSource = lifelinesGFP, Style = linestyle }; Dictionary <string, IStyle> styles = new Dictionary <string, IStyle>(); VectorStyle line = new VectorStyle { PointColor = new SolidBrush(Color.Green), PointSize = 2 }; styles.Add(MapLifeLine.LINE, line); VectorStyle startPoint = new VectorStyle { PointColor = new SolidBrush(Color.Green), PointSize = 2, Symbol = Image.FromFile(Path.Combine(Application.StartupPath, @"Resources\Icons\arrow-right.png")) }; styles.Add(MapLifeLine.START, startPoint); VectorStyle endPoint = new VectorStyle { PointColor = new SolidBrush(Color.Green), PointSize = 2, Symbol = Image.FromFile(Path.Combine(Application.StartupPath, @"Resources\Icons\arrow-left.png")) }; styles.Add(MapLifeLine.END, endPoint); linesLayer.Theme = new SharpMap.Rendering.Thematics.UniqueValuesTheme <string>("LineCap", styles, line); mapBox1.Map.Layers.Add(linesLayer); labelLayer = new LabelLayer("Label") { DataSource = lifelinesGFP, Enabled = true, //Specifiy field that contains the label string. LabelColumn = "Label", TextRenderingHint = TextRenderingHint.AntiAlias, SmoothingMode = SmoothingMode.AntiAlias }; LabelStyle style = new LabelStyle { ForeColor = Color.Black, Font = new Font(FontFamily.GenericSerif, 14, FontStyle.Bold), HorizontalAlignment = LabelStyle.HorizontalAlignmentEnum.Center, VerticalAlignment = LabelStyle.VerticalAlignmentEnum.Bottom, CollisionDetection = true, Offset = new PointF(0, 25), Halo = new Pen(Color.Yellow, 3) }; labelLayer.Style = style; mapBox1.Map.Layers.Add(labelLayer); points = new TearDropLayer("Points"); mapBox1.Map.Layers.Add(points); selections = new TearDropLayer("Selections"); mapBox1.Map.VariableLayers.Add(selections); mh.AddParishLayers(mapBox1.Map); mh.SetScaleBar(mapBox1); mapBox1.Map.MinimumZoom = 500; mapBox1.Map.MaximumZoom = 50000000; mapBox1.QueryGrowFactor = 30; mapBox1.Map.ZoomToExtents(); mapBox1.ActiveTool = SharpMap.Forms.MapBox.Tools.Pan; }