CanvasMap
Getting Started Tutorials 3D Reference

Adding Basic Geographic Tools

CanvasMap supports drawing over the map with rectangles, rounded rectangles, ovals, curves and arrows. These items are supported through the CMLayerItems class. You can also add your own tools or just create items from JavaScript.

Adding a CMLayerItems layer

You can add a layer for items in the same way as any other layer:

TheItemLayer=new CMLayerItems(); // create the layer object and save it to a global variable
TheItemLayer.SetSetting("Name","Items");
TheMainContainer.AddLayer(TheItemLayer); // add the layer to the scene
 

When the layer is selected, the tools will appear across the top of the tool bar. The user can then create items with the appropriate tools and edit them with the arrow tool.

Getting the Tool Objects

You can get the item objects that the user created with:

var NumChildren=TheItemLayer.GetNumChildren(); // get the number of items in the layer
for (var i=0;i<NumChildren;i++) // go through all the items in the layer
{
	var TheChild=TheItemLayer.GetChild(i); // get the item
	
	// add your code here, in this case we get the coordinates for the rectangle
	var TheCoordinates=TheChild.GetSetting("Rectangle","Coordinates");
}

Rectangle, rounded rectangle and ovals are all sub-classes of CMItemRect. You can obtain the coordinates for the corners of the bounding rectangle of these items with the setting "Rectangle", "Coordinates". The curves and arrows are subclasses of the CMItemPoly class and you can get and set the coordinates for these objects with the setting "Curve", and "Coordinates".

Adding Tools

You can add standard tools to the map with the following code:

 var TheView=TheMainContainer.GetView(); // get the current view
 var TheToolHandler=new CMToolHandler(ObjectType); // object to handle the tool being used in the view
 TheToolHandler.TheLayer=TheLayer; // existing CMLayerItems layer
 
 TheView.SetToolHandler(TheToolHandler); // setup the tool be to used in the view

TheLayer should be a preexisting CMLayerItems layer and the ObjectType should be one of: