Skip to content

This is how to add control icon #10

@beifeizhou

Description

@beifeizhou

Here is how to activate the rectangle and add it as control to the map

const modes = MapboxDraw.modes
  modes.draw_rectangle = DrawRectangle
  const draw = new MapboxDraw({
    displayControlsDefault: false,
    controls: {
      polygon: true,
      trash: true,
      defaultMode: 'draw_rectangle',
    },
    modes: modes,
  })

  map.addControl(draw)
  draw.changeMode('draw_rectangle')

  map._draw = draw

  map.on('draw.create', function (feature) {
    console.log(feature)
  })

Here you can assign draw to a property for map
map._draw = draw

const onClickDrawRt = (map) => {
   map._draw.changeMode('draw_rectangle')
}

<button onClick={() => onClickDrawRt(map)}/>

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions