ToolTip.cs

This example demonstrates how to show tootip with attributes of a shape in mousemove event. The tooltip is drawn as a label on the spatially referenced drawing layer. The smooth redraw of the tooltip is possible only for version higher than 4.8 where the redraw of the spatially referenced drawing layers can be done independently of the data layers. Here is a screenshot with the results of the code execution.

using System.IO;
using System.Windows.Forms;
using AxMapWinGIS;
using MapWinGIS;
namespace Examples
{
public partial class MapExamples
{
// the handle of the drawing layer
private int _mDrawingHandle = -1;
// <summary>
// Opens a shapefile, registers event handler
// </summary>
public void ToolTip(AxMap axMap1, string dataPath)
{
axMap1.Projection = tkMapProjection.PROJECTION_GOOGLE_MERCATOR;
string filename = dataPath + "landuse.shp";
if (!File.Exists(filename))
{
MessageBox.Show("Couldn't file the file: " + filename);
return;
}
Shapefile sf = new Shapefile();
sf.Open(filename, null);
if (!sf.StartEditingShapes(true, null))
{
MessageBox.Show("Failed to start edit mode: " + sf.Table.ErrorMsg[sf.LastErrorCode]);
}
else
{
sf.UseQTree = true;
sf.Labels.Generate("[Name]", tkLabelPositioning.lpCentroid, false);
axMap1.AddLayer(sf, true);
axMap1.SendMouseMove = true;
axMap1.ShowRedrawTime = true;
axMap1.MapUnits = tkUnitsOfMeasure.umMeters;
axMap1.CurrentScale = 50000;
axMap1.CursorMode = tkCursorMode.cmNone;
MapEvents.MouseMoveEvent += AxMap1MouseMoveEvent; // change MapEvents to axMap1
_mDrawingHandle = axMap1.NewDrawing(tkDrawReferenceList.dlScreenReferencedList);
Labels labels = axMap1.get_DrawingLabels(_mDrawingHandle);
labels.FrameVisible = true;
labels.FrameType = tkLabelFrameType.lfRectangle;
}
}
// <summary>
// Handles mouse move event. Determines which shape is under cursor. Calls drawing routine.
// </summary>
void AxMap1MouseMoveEvent(object sender, _DMapEvents_MouseMoveEvent e)
{
Labels labels = axMap1.get_DrawingLabels(0);
labels.Clear();
// it's assumed here that the layer we want to edit is the first 1 (with 0 index)
int layerHandle = axMap1.get_LayerHandle(0);
var sf = axMap1.get_Shapefile(layerHandle);
if (sf != null)
{
double projX = 0.0;
double projY = 0.0;
axMap1.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.0, SelectMode.INTERSECTION, ref result))
{
int[] shapes = result as int[];
if (shapes != null && shapes.Length == 1)
{
string s = "";
for (int i = 0; i < sf.NumFields; i++)
{
s += sf.Field[i].Name + ": " + sf.CellValue[i, shapes[0]] + "\n";
}
labels.AddLabel(s, e.x + 80, e.y);
}
}
}
axMap1.Redraw2(tkRedrawType.RedrawSkipDataLayers);
}
}
}
SelectMode
The selection mode, which determines which shapes will be considered as included in the rectangular s...
Definition: Enumerations.cs:149
tkLabelPositioning
The available positioning of the label relative to the parent shape.
Definition: Enumerations.cs:835
tkRedrawType
Types of map redraw.
Definition: Enumerations.cs:1683
tkCursorMode
Available cursor modes. Determines the default respond of map to the action of user.
Definition: Enumerations.cs:344
tkLabelFrameType
The the available shapes of the frames for labels, i.e. rectangles drawn around the labels to ensure ...
Definition: Enumerations.cs:822
tkMapProjection
Commonly used map projections to be set in Form Designer (see AxMap.Projection property).
Definition: Enumerations.cs:1741
tkUnitsOfMeasure
The possible units of measure for the data being displaying on map.
Definition: Enumerations.cs:1397
tkDrawReferenceList
The type of spatial reference for the drawing layer.
Definition: Enumerations.cs:484
Map component for visualization of vector, raster or grid data.
Definition: AxMap.cs:56
void Redraw2(tkRedrawType redrawType)
Performs specific type of map redraw.
Definition: AxMap.cs:370
bool ShowRedrawTime
Gets or sets a value which indicates whether the time of map redraw will be displayed on the screen.
Definition: AxMap.cs:203
Represents a rectangle on the map.
Definition: Extents.cs:49
Represents a list of labels of the map layer and their visualization options.
Definition: Labels.cs:51
Provides a functionality for accessing and editing ESRI shapefiles.
Definition: Shapefile.cs:72
Labels Labels
Gets or sets the instance of the Labels class associated with the shapefile.
Definition: Shapefile.cs:184
int LastErrorCode
Gets the code of last error which took place inside this object.
Definition: Shapefile.cs:249
int Generate(string Expression, tkLabelPositioning Method, bool LargestPartOnly)
Generates labels for each shape of the parent shapefile.
Definition: Labels.cs:490
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
void Clear()
Removes all the labels and parts but not the visualization categories.
Definition: Labels.cs:466
bool FrameVisible
Gets or sets the values which indicates whether label's frame is visible.
Definition: Labels.cs:1357
tkLabelFrameType FrameType
Gets or sets the shape of the label's frame.
Definition: Labels.cs:1348
void PixelToProj(double pixelX, double pixelY, ref double projX, ref double projY)
Converts pixel coordinates to projected map coordinates
Definition: AxMap.cs:2634
tkUnitsOfMeasure MapUnits
Gets or sets the units of measure for the map.
Definition: AxMap.cs:2622
tkMapProjection Projection
Sets projection of the map. It providers 2 most commonly used coordinate system/projections to be eas...
Definition: AxMap.cs:2709
Labels get_DrawingLabels(int drawingLayerIndex)
Gets labels associated with the drawing layer.
Definition: AxMap.cs:1659
int NewDrawing(tkDrawReferenceList projection)
Creates a new drawing layer on the map returning its handle.
Definition: AxMap.cs:1868
double CurrentScale
Gets or sets the current map scale.
Definition: AxMap.cs:2395
tkCursorMode CursorMode
Gets or sets the cursor mode for the map.
Definition: AxMap.cs:456
bool SendMouseMove
Gets or sets whether the map sends mouse move events.
Definition: AxMap.cs:562
int get_LayerHandle(int layerPosition)
Gets the handle of the layer at the given position in the map. Returns -1 if there is no layer at the...
Definition: AxMap.cs:1352
int AddLayer(object Object, bool visible)
Adds a layer to the map.
Definition: AxMap.cs:1342
Shapefile get_Shapefile(int layerHandle)
Gets shapefile object associated with the layer.
Definition: AxMap.cs:1546
bool StartEditingShapes(bool startEditTable, ICallback cBack)
Starts editing mode for the shapefile.
Definition: Shapefile.cs:840
bool Open(string shapefileName, ICallback cBack)
Opens shapefile from the disk.
Definition: Shapefile.cs:1430
bool UseQTree
Gets or sets a value which indicates whether built-in quad-tree spatial index should be used for shap...
Definition: Shapefile.cs:1963
Table Table
Gets the reference to the attribute table associated with the shapefile.
Definition: Shapefile.cs:677