mapbox / mapbox-gl-draw

Draw tools for mapbox-gl-js
https://www.mapbox.com/mapbox-gl-js/example/mapbox-gl-draw/
ISC License
942 stars 590 forks source link

Cannot read property 'getMode' of undefined #1007

Open roliauo opened 4 years ago

roliauo commented 4 years ago

Cannot read property 'getMode' of undefined at MapboxDraw.__webpack_exports__.default.api.getMode

mapbox-gl-js version: 1.12.0 mapbox-gl-draw version: 1.2.0

  draw.current = new MapboxDraw({
            displayControlsDefault: false,
            styles: drawingStyle,
            modes:
            {
                ...MapboxDraw.modes,
                [MapConstants.drawingTypeOption.freehand]: FreeDraw,
                lots_of_points: LotsOfPointsMode,
            }
        });
  console.log('draw.current.getMode', draw.current.getMode(), MapboxDraw.modes)
  map.addControl(draw.current);

20200827-1

20200827-0

https://github.com/mapbox/mapbox-gl-draw/blob/main/src/setup.js the 'ctx' object missing events

add this line to solve this problem:

ctx.events = events(ctx);

20200827-2

Etheryte commented 9 months ago

If you're landing here from googling the error message, the original problem seems to be fixed as far as I can tell. You'll get the same error if you try and interact with the plugin before you've added it to the map.