// <summary> // Adds randomly positioned labels to the image layer. // </summary> public void ImageLabels(AxMap axMap1) { axMap1.Projection = tkMapProjection.PROJECTION_NONE; axMap1.GrabProjectionFromData = true; Image img = new Image(); OpenFileDialog dlg = new OpenFileDialog { Filter = img.CdlgFilter }; if (dlg.ShowDialog() == DialogResult.OK) { img.Open(dlg.FileName, ImageType.USE_FILE_EXTENSION, false, null); axMap1.AddLayer(img, true); Labels lbl = img.Labels; lbl.FontSize = 12; lbl.FontBold = true; lbl.FontOutlineVisible = true; lbl.FontOutlineColor = (255 << 16) + (255 << 8) + 255; //white lbl.FontOutlineWidth = 4; LabelCategory cat = lbl.AddCategory("Red"); cat.FontColor = 255; cat = lbl.AddCategory("Blue"); cat.FontColor = 255 << 16; cat = lbl.AddCategory("Yellow"); cat.FontColor = 255 + 255 << 8; Extents ext = img.Extents; double xRange = ext.xMax - ext.xMin; double yRange = ext.yMax - ext.yMin; Random rnd = new Random(); for (int i = 0; i < 100; i++) { double x = xRange * rnd.NextDouble(); double y = yRange * rnd.NextDouble(); int categoryIndex = i % 3; lbl.AddLabel("label" + Convert.ToString(i), ext.xMin + x, ext.yMin + y, i * 3.6, categoryIndex); } axMap1.Redraw(); } }
private void axMap1_MouseMoveEvent(object sender, _DMapEvents_MouseMoveEvent e) { #region 原版添加标签 if (sfMouseMove != null) { foreach (Shapefile sf in sfMouseMove.Values) { labels = sf.Labels; labels.FontSize = 15; labels.FontBold = true; labels.FrameVisible = true; labels.FrameType = tkLabelFrameType.lfRectangle; labels.AutoOffset = false; labels.OffsetX = 40; LabelCategory cat = labels.AddCategory("Red"); cat.FontColor = 255; double projX = 0.0; double projY = 0.0; Map.PixelToProj(e.x, e.y, ref projX, ref projY); object result = null; var ext = new Extents(); ext.SetBounds(projX, projY, 0.0, projX, projY, 0.0); if (sf.SelectShapes(ext, 0.00007, SelectMode.INTERSECTION, ref result)) { if (labelFlag_MouseMove == 0) { mouseMoveOperate(result, sf, labels, projX, projY); Map.Redraw(); movemoveenter++; string tStr = "aaa:" + movemoveenter; int str = labels.Count; Debug.Print("labels:" + str); labelFlag_MouseMove = 1; } } else { if (labelFlag_MouseMove == 1) { sf.Labels.Clear(); labelFlag_MouseMove = 0; Map.Redraw(); movemoveenter++; string tStr = "bbb:" + movemoveenter; int str = labels.Count; Debug.Print("labels:" + str); } } } } #endregion }
void MapMouseMoveEvent(object sender, _DMapEvents_MouseMoveEvent e) { #region 单重显示 Shapefile sf = App.Map.get_Shapefile(1); if (sf != null) { Labels labels = sf.Labels; labels.FontSize = 15; labels.FontBold = true; labels.FrameVisible = true; labels.FrameType = tkLabelFrameType.lfRectangle; labels.AutoOffset = false; labels.OffsetX = 40; LabelCategory cat = labels.AddCategory("Red"); cat.FontColor = 255; double projX = 0.0; double projY = 0.0; App.Map.PixelToProj(e.x, e.y, ref projX, ref projY); object result = null; var ext = new Extents(); ext.SetBounds(projX, projY, 0.0, projX, projY, 0.0); if (sf.SelectShapes(ext, 0.00005, SelectMode.INTERSECTION, ref result) && (p == 0)) { //string temp = GisPoint.readOneData(projX, projY); //string tempx = temp + "℃"; //if(Convert.ToDouble(temp)>=50) //{ // labels.AddLabel(tempx, projX, projY, 0.0, 0); //} //else //{ // labels.AddLabel(tempx, projX, projY, 0.0, -1); //} //p = 1; } else { sf.Labels.Clear(); p = 0; } App.Map.Redraw(); } #endregion }
private void axMap1_MouseDownEvent(object sender, _DMapEvents_MouseDownEvent e) { if (sfMouseDown != null) { foreach (Shapefile sf in sfMouseDown.Values) { if (sf != null) { Labels labels = sf.Labels; labels.FontSize = 15; labels.FontBold = true; labels.FrameVisible = true; labels.FrameType = tkLabelFrameType.lfRectangle; labels.AutoOffset = false; labels.OffsetX = 40; LabelCategory cat = labels.AddCategory("Red"); cat.FontColor = 255; double projX = 0.0; double projY = 0.0; Map.PixelToProj(e.x, e.y, ref projX, ref projY); object result = null; var ext = new Extents(); ext.SetBounds(projX - 0.0004, projY - 0.0004, 0.0, projX + 0.0004, projY + 0.0004, 0.0); if (sf.SelectShapes(ext, 0.0001, SelectMode.INTERSECTION, ref result)) { if (labelFlag_MouseDown == 0) { mouseDownOperate(result, sf, labels, projX, projY); Map.Redraw(); labelFlag_MouseDown = 1; } } else { if (labelFlag_MouseDown == 1) { sf.Labels.Clear(); Map.Redraw(); labelFlag_MouseDown = 0; } } } } } }
/// <summary> /// Generate label categories for the given set of shapefile categories /// </summary> /// <param name="mapWin">The reference to MapWindow</param> /// <param name="layerHandle">The handle of the layer</param> internal static void GenerateCategories(LegendControl.Legend legend, int layerHandle) { Layer lyr = legend.GetLayer(layerHandle); Shapefile sf = lyr.GetObject() as MapWinGIS.Shapefile; Labels lb = sf.Labels; sf.Labels.ClearCategories(); for (int i = 0; i < sf.Categories.Count; i++) { ShapefileCategory cat = sf.Categories.get_Item(i); LabelCategory labelCat = lb.AddCategory(cat.Name); labelCat.Expression = cat.Expression; } SymbologySettings settings = Globals.get_LayerSettings(layerHandle); ColorBlend blend = (ColorBlend)settings.LabelsScheme; if (blend != null) { ColorScheme scheme = ColorSchemes.ColorBlend2ColorScheme(blend); if (settings.LabelsRandomColors) { lb.ApplyColorScheme(tkColorSchemeType.ctSchemeRandom, scheme); } else { lb.ApplyColorScheme(tkColorSchemeType.ctSchemeGraduated, scheme); } } if (settings.LabelsVariableSize) { for (int i = 0; i < lb.NumCategories; i++) { lb.get_Category(i).FontSize = (int)((double)sf.Labels.FontSize + (double)settings.LabelsSizeRange / ((double)lb.NumCategories - 1) * (double)i); } } // Expressions aren't supported by labels yet, therefore we need to copy indices from the symbology for (int i = 0; i < lb.Count; i++) { MapWinGIS.Label label = lb.get_Label(i, 0); label.Category = sf.get_ShapeCategory(i); } }
public void AddText(double x, double y) { Labels labels = sf.Labels; labels.FontSize = 15; labels.FontBold = true; labels.FrameVisible = false; labels.FrameType = tkLabelFrameType.lfRectangle; labels.AutoOffset = false; labels.OffsetX = 40; LabelCategory cat = labels.AddCategory("wenzi"); cat.FontColor = 255; string aisLabel = "文字部分"; labels.AddLabel(aisLabel, x, y, 0.0, -1); }
public void Add(ILabelStyle item) { _labels.AddCategory(""); _labels.Category[_labels.NumCategories - 1] = item.GetInternal(); // TODO: implement directly in MapWinGIS }