Sunday, April 25, 2010

MapInfo : Setting default drawing Style

How to set the default drawing Style for the AddMapTool ?

AddMapToolProperties addMapToolProperties = mapControl1.Tools.AddMapToolProperties as AddMapToolProperties;
CompositeStyle cs = addMapToolProperties.CompositeStyle;
LineWidth lw = new LineWidth(5, LineWidthUnit.Pixel);
SimpleLineStyle ls = new SimpleLineStyle(lw, 2, Color.Blue, false);
addMapToolProperties.CompositeStyle.LineStyle = ls;

You create the AddMapToolProperties and change the CompositeStyle according to what you want and then use this addMapToolProperties when creating your AddMapTool.

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.