Sunday, April 25, 2010

MapInfo addMapTool

Using the MapInfo various addMapTools (AddCircleMapTool, AddEllipseMapTool, AddLineMapTool, AddPointMapTool, AddPolygonMapTool, AddPolylineMapTool, AddRectangleMapTool, AddTextMapTool), how do you specify which Layer should the Tool add its item onto ?

The answer is to use the ToolFilter and the addMapToolsProperties.InsertionLayerFilter() function.

See the code below.

AddMapToolProperties addMapToolProperties = mapControl1.Tools.AddMapToolProperties as AddMapToolProperties;
ToolFilter toolFilter = (ToolFilter)addMapToolProperties.InsertionLayerFilter;
if (toolFilter != null && !toolFilter.IncludeLayer(myLayer2.MapLayer))
{
toolFilter.SetExplicitInclude(myLayer2.MapLayer, true);
}

After which, use the new "addMapToolProperties" when you create your AddMapTool.

No comments: