Class: DrawTool

DrawTool

A map tool to help draw geometries.

new DrawTool(optionsopt) [source]

In default, DrawTool supports the following modes:
[Point, LineString, Polygon, Circle, Ellipse, Rectangle, ArcCurve, QuadBezierCurve, CubicBezierCurve]
You can easily add new mode to DrawTool by calling registerMode
var drawTool = new DrawTool({
    mode : 'Polygon',
    symbol : {
        'lineColor' : '#000',
        'lineWidth' : 5
    },
    once : true
}).addTo(map);
Parameter Type Default Description
options opt Object null construct options
Properties
Parameter Type Default Description
mode opt String null mode of the draw tool
symbol opt Object null symbol of the geometries drawn
once opt Boolean null whether disable immediately once drawn a geometry.
autoPanAtEdge opt Boolean false Whether to make edge judgement or not.
Extends:
Fires:

Members

  • (constant) options

  • Properties:
    Name Type Default Description
    options opt Object null construct options
    Properties
    Name Type Default Description
    mode opt String null mode of the draw tool
    symbol opt Object null symbol of the geometries drawn
    once opt Boolean null whether disable immediately once drawn a geometry.
    autoPanAtEdge opt Boolean false Whether to make edge judgement or not.
    blockGeometryEvents opt Boolean false Whether Disable geometryEvents when drawing.
    zIndex opt Number Number.MAX_VALUE drawlayer zIndex.The default drawn layer will be at the top
    Source:

    Static Methods

  • (static) registerMode(name, modeAction) [source]

  • Register a new mode for DrawTool
    //Register "CubicBezierCurve" mode to draw Cubic Bezier Curves.
    DrawTool.registerMode('CubicBezierCurve', {
            'action': 'clickDblclick',
            'create': path => new CubicBezierCurve(path),
            'update': (path, geometry) => {
                geometry.setCoordinates(path);
            },
            'generate': geometry => geometry
           }
         });
    Parameter Type Description
    name String mode name
    modeAction Object modeActions
    Properties
    Parameter Type Description
    action Object the action of DrawTool: click, mousedown, clickDblclick
    create Object the create method of drawn geometry
    update Object the update method of drawn geometry
    generate Object the method to generate geometry at the end of drawing.

  • (static) getRegisterMode(name) [source]

  • Get mode actions by mode name
    Parameter Type Description
    name String DrawTool mode name
    Returns:
    Object: mode actions

    Methods

  • getMode() [source]

  • Get current mode of draw tool
    Returns:
    String: mode
  • setMode(mode) [source]

  • Set mode of the draw tool
    Parameter Type Description
    mode String mode of the draw tool

  • getSymbol() [source]

  • Get symbol of the draw tool
    Returns:
    Object: symbol
  • setSymbol(symbol) [source]

  • Set draw tool's symbol
    Parameter Type Description
    symbol Object symbol set
    Returns:
    DrawTool: this
  • getCurrentGeometry() [source]

  • Get geometry is currently drawing
    Returns:
    Geometry: geometry currently drawing
  • undo() [source]

  • Undo drawing, only applicable for click/dblclick mode
    Returns:
    DrawTool: this
  • redo() [source]

  • Redo drawing, only applicable for click/dblclick mode
    Returns:
    DrawTool: this
  • endDraw(paramopt) [source]

  • End current draw
    Parameter Type Default Description
    param opt Object null params of drawend event
    Returns:
    DrawTool: this
  • setLayerZIndex(zIndex) [source]

  • set draw inner layers zIndex
    Parameter Type Description
    zIndex Number draw layer zIndex
    Returns:
    this:
  • (inherited) addTo(map) [source]

  • Adds the map tool to a map.
    Parameter Type Description
    map Map
    Fires:
    Returns:
    MapTool: this
  • (inherited) getMap() [source]

  • Gets the map it added to.
    Returns:
    Map: map
  • (inherited) enable() [source]

  • Enable the map tool.
    Fires:
    Returns:
    MapTool: this
  • (inherited) disable() [source]

  • Disable the map tool
    Fires:
    Returns:
    MapTool: this
  • (inherited) isEnabled() [source]

  • Returns whether the tool is enabled
    Returns:
    Boolean: true | false
  • (inherited) on(eventsOn, handler, contextopt) [source]

  • Register a handler function to be called whenever this event is fired.
    foo.on('mousedown mousemove mouseup', onMouseEvent, foo);
    Parameter Type Default Description
    eventsOn String event types to register, seperated by space if more than one.
    handler function handler function to be called
    context opt Object null the context of the handler
    Mixes From:
    Returns:
    Any: this
  • (inherited) addEventListener(eventTypes, handler, contextopt) [source]

  • Alias for on
    Parameter Type Default Description
    eventTypes String event types to register, seperated by space if more than one.
    handler function handler function to be called
    context opt Object null the context of the handler
    Mixes From:
    Returns:
    : this
  • (inherited) once(eventTypes, handler, contextopt) [source]

  • Same as on, except the listener will only get fired once and then removed.
    foo.once('mousedown mousemove mouseup', onMouseEvent, foo);
    Parameter Type Default Description
    eventTypes String event types to register, seperated by space if more than one.
    handler function listener handler
    context opt Object null the context of the handler
    Mixes From:
    Returns:
    : this
  • (inherited) off(eventsOff, handler, contextopt) [source]

  • Unregister the event handler for the specified event types.
    foo.off('mousedown mousemove mouseup', onMouseEvent, foo);
    Parameter Type Default Description
    eventsOff String event types to unregister, seperated by space if more than one.
    handler function listener handler
    context opt Object null the context of the handler
    Mixes From:
    Returns:
    : this
  • (inherited) removeEventListener(eventTypes, handler, contextopt) [source]

  • Alias for off
    Parameter Type Default Description
    eventTypes String event types to unregister, seperated by space if more than one.
    handler function listener handler
    context opt Object null the context of the handler
    Mixes From:
    Returns:
    : this
  • (inherited) listens(eventType, hanlderopt, contextopt) [source]

  • Returns listener's count registered for the event type.
    Parameter Type Default Description
    eventType String an event type
    hanlder opt function null listener function
    context opt Object null the context of the handler
    Mixes From:
    Returns:
    Number:
  • (inherited) getListeningEvents() [source]

  • Get all the listening event types
    Mixes From:
    Returns:
    Array.<String>: events
  • (inherited) copyEventListeners(target) [source]

  • Copy all the event listener to the target object
    Parameter Type Description
    target Object target object to copy to.
    Mixes From:
    Returns:
    : this
  • (inherited) fire(eventType, param) [source]

  • Fire an event, causing all handlers for that event name to run.
    Parameter Type Description
    eventType String an event type to fire
    param Object parameters for the listener function.
    Mixes From:
    Returns:
    : this
  • (inherited) callInitHooks() [source]

  • Visit and call all the init hooks defined on Class and its parents.
    Returns:
    Class: this
  • (inherited) setOptions(options) [source]

  • Merges options with the default options of the object.
    Parameter Type Description
    options Object options to set
    Returns:
    Class: this
  • (inherited) config(conf) [source]

  • 1. Return object's options if no parameter is provided.
    2. update an option and enable/disable the handler if a handler with the same name existed.
    // Get marker's options;
    var options = marker.config();
    // Set map's option "draggable" to false and disable map's draggable handler.
    map.config('draggable', false);
    // You can update more than one options like this:
    map.config({
        'scrollWheelZoom' : false,
        'doubleClickZoom' : false
    });
    Parameter Type Description
    conf Object config to update
    Returns:
    Class: this
  • (inherited) onConfig() [source]

  • Default callback when config is called

    Events

  • drawvertex [source]

  • drawvertex event.
    Properties:
    Name Type Description
    type String drawvertex
    target DrawTool draw tool
    geometry Geometry geometry drawn
    coordinate Coordinate coordinate of the event
    containerPoint Point container point of the event
    viewPoint Point view point of the event
    domEvent Event dom event
    Source:

  • drawprepare [source]

  • drawprepare event.Note that it occurs before drawstart
    Properties:
    Name Type Description
    type String drawprepare
    target DrawTool draw tool
    coordinate Coordinate coordinate of the event
    containerPoint Point container point of the event
    viewPoint Point view point of the event
    domEvent Event dom event
    Source:

  • drawstart [source]

  • drawstart event.
    Properties:
    Name Type Description
    type String drawstart
    target DrawTool draw tool
    coordinate Coordinate coordinate of the event
    containerPoint Point container point of the event
    viewPoint Point view point of the event
    domEvent Event dom event
    Source:

  • mousemove [source]

  • mousemove event.
    Properties:
    Name Type Description
    type String mousemove
    target DrawTool draw tool
    geometry Geometry geometry drawn
    coordinate Coordinate coordinate of the event
    containerPoint Point container point of the event
    viewPoint Point view point of the event
    domEvent Event dom event
    Source:

  • drawend [source]

  • drawend event.
    Properties:
    Name Type Description
    type String drawend
    target DrawTool draw tool
    geometry Geometry geometry drawn
    coordinate Coordinate coordinate of the event
    containerPoint Point container point of the event
    viewPoint Point view point of the event
    domEvent Event dom event
    Source:

  • (inherited) add [source]

  • add event.
    Properties:
    Name Type Description
    type String add
    target MapTool map tool
    Overrides:
    Source:

  • (inherited) enable [source]

  • enable event.
    Properties:
    Name Type Description
    type String enable
    target MapTool map tool
    Overrides:
    Source:

  • (inherited) disable [source]

  • disable event.
    Properties:
    Name Type Description
    type String disable
    target MapTool map tool
    Overrides:
    Source:

  • (inherited) remove [source]

  • remove event.
    Properties:
    Name Type Description
    type String remove
    target MapTool map tool
    Overrides:
    Source: