DrawingManager Class

Note

Bing Maps Web Control SDK retirement

Bing Maps Web Control SDK is deprecated and will be retired. Free (Basic) account customers can continue to use Bing Maps Web Control SDK until June 30th, 2025. Enterprise account customers can continue to use Bing Maps Web Control SDK until June 30th, 2028. To avoid service disruptions, all implementations using Bing Maps Web Control SDK will need to be updated to use Azure Maps Web SDK by the retirement date that applies to your Bing Maps for Enterprise account type. For detailed migration guidance, see Migrate from Bing Maps Web Control SDK and Migrate Bing Maps Enterprise applications to Azure Maps with GitHub Copilot.

Azure Maps is Microsoft's next-generation maps and geospatial services for developers. Azure Maps has many of the same features as Bing Maps for Enterprise, and more. To get started with Azure Maps, create a free Azure subscription and an Azure Maps account. For more information about azure Maps, see Azure Maps Documentation. For migration guidance, see Bing Maps Migration Overview.

The DrawingManager class manages the ability to draw and edit multiple shapes on the map. Shapes managed by this class are rendered on a separate drawing layer. User can use a mouse or a touch screen to draw on the map. When they are done, double clicking the map, pressing the escape button or any button on the toolbar will exit the current drawing mode. This class does not have a publicly accessible constructor and can only be accessed using the showDrawingManager of the DrawingTools class.

Methods

The DrawingManager class has the following methods.

Name Return Type Description
add(data: IPrimitive or IPrimitive[], index?: number) Adds a shapes to the layer, at the specified index if specified.

  • data – The shape(s) to be added to the layer.
  • index – The index at which to insert the shape into the layer.
dispose() Disposes the drawing manager instance.
clear() Resets the drawing manager and clears all shapes in the drawing layer.
getDrawingMode() DrawingMode Gets the current drawing mode of the drawing manager.
getPrimitives() IPrimitive[] Gets an array of shapes that are in the layer. This can be used to iterate over the individual shapes.
indexOf(primitive: IPrimitive, fromIndex?: number) number Returns the index of the shape in the drawing layer. Returns -1 if shape is not found.
remove(primitive: IPrimitive) IPrimitive Removes a shape from the layer and returns it.
removeAt(index: number) IPrimitive Removes a shape from the layer at the specified index.
setDrawingMode(mode: DrawingMode) Sets the drawing mode of the drawing manager.
setOptions(options: DrawingManagerOptions) Sets the drawing tool options.
setPrimitives(primitives: IPrimitive[]) Replaces all shapes in the layer with the new array of shapes that have been provided.

Events

The DrawingManager class provides the following events.

Name Type Description
disposed Occurs when the drawing manager has been disposed.
drawingChanged IPrimitive Occurs after the shape has had a change. For example, finished dragging a vertex to a new location.
drawingChanging IPrimitive Occurs when the shape is being actively manipulated. For example, this event will continuously fire when dragging a vertex of a shape.
drawingEnded IPrimitive Occurs when the user has finished drawing or editing a shape.
drawingErased IPrimitive Occurs when a shape is erased.
drawingModeChanged DrawingMode Occurs when the drawing mode has changed.
drawingStarted IPrimitive Occurs when the user has started drawing or editing a shape.