ImageLabels.cs

This example demonstrates how to to add randomly positioned labels to the image layer. Here is a screenshot with the results of the code.

using System;
using System.Windows.Forms;
using AxMapWinGIS;
using MapWinGIS;

public partial class MapExamples
{
    // <summary>
    // Adds randomly positioned labels to the image layer.
    // </summary>
    public void ImageLabels(AxMap axMap1)
    {
        Image img = new Image();
        OpenFileDialog dlg = new OpenFileDialog();
        dlg.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;
            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;
            double x, y;
            Random rnd = new Random();

            for (int i = 0; i < 100; i++)
            {
                x = xRange * rnd.NextDouble();
                y = yRange * rnd.NextDouble();

                int categoryIndex = i % 3;
                lbl.AddLabel("label" + Convert.ToString(i),
                                    ext.xMin + x, ext.yMin + y, (double)i * 3.6, categoryIndex);
            }

            axMap1.Redraw();
        }
    }
}
 All Classes Files Functions Enumerations Properties