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 execution.

using System;
using System.Windows.Forms;
using AxMapWinGIS;
using MapWinGIS;
namespace Examples
{
public partial class MapExamples
{
// <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
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();
}
}
}
}
ImageType
The type of images supported by MapWinGIS.
Definition: Enumerations.cs:92
tkMapProjection
Commonly used map projections to be set in Form Designer (see AxMap.Projection property).
Definition: Enumerations.cs:1741
Map component for visualization of vector, raster or grid data.
Definition: AxMap.cs:56
void Redraw()
Redraws all layers in the map if the map is not locked.
Definition: AxMap.cs:183
Represents a rectangle on the map.
Definition: Extents.cs:49
double xMax
The maximum x bound for the extents object.
Definition: Extents.cs:121
double yMax
The maximum y bound for the extents object.
Definition: Extents.cs:137
double xMin
Gets the minimum x bound for the extents object.
Definition: Extents.cs:129
double yMin
Gets the minimum y bound for the extents object
Definition: Extents.cs:145
Represents an raster image of particular format which may be added to the map.
Definition: Image.cs:66
Represents visualization options for labels displayed on the map.
Definition: LabelCategory.cs:115
uint FontColor
Gets or sets font color of labels.
Definition: LabelCategory.cs:166
Represents a list of labels of the map layer and their visualization options.
Definition: Labels.cs:51
Labels Labels
Gets or sets instance of the labels class associated with the image.
Definition: Image.cs:417
string CdlgFilter
Returns the common dialog filter containing all supported file extensions in string format.
Definition: Image.cs:292
bool Open(string ImageFileName, ImageType fileType, bool InRam, ICallback cBack)
Opens an image from file.
Definition: Image.cs:357
Extents Extents
Returns the extents of the image.
Definition: Image.cs:555
LabelCategory AddCategory(string Name)
Adds a visualization category for labels.
Definition: Labels.cs:290
void AddLabel(string Text, double x, double y, double offsetX, double offsetY, double Rotation, int Category)
Adds a new label as the last one in the list.
Definition: Labels.cs:438
uint FontOutlineColor
Sets the color of the font outline.
Definition: Labels.cs:1190
int FontSize
Gets or sets the size of the font to draw labels with.
Definition: Labels.cs:1218
bool FontBold
Gets or sets the value which indicates whether the font of labels is bold.
Definition: Labels.cs:1133
int FontOutlineWidth
Gets or sets the width of the font outline. The default value is 1.
Definition: Labels.cs:1209
bool FontOutlineVisible
Gets or sets the value which indicates whether font outline is visible. The default value is false.
Definition: Labels.cs:1199
tkMapProjection Projection
Sets projection of the map. It providers 2 most commonly used coordinate system/projections to be eas...
Definition: AxMap.cs:2709
bool GrabProjectionFromData
Gets or sets a value indicating whether projection for will be taken from the first datasource added ...
Definition: AxMap.cs:2701
int AddLayer(object Object, bool visible)
Adds a layer to the map.
Definition: AxMap.cs:1342