mapbox-gl-draw icon indicating copy to clipboard operation
mapbox-gl-draw copied to clipboard

MapboxDraw is not a constructor

Open csimpi opened this issue 5 years ago • 3 comments
trafficstars

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

Framework: Angular 9

Steps to Trigger Behavior

  1. Install
  2. Import
  3. Start Angular App

Expected Behavior

Loads and works

Actual Behavior

I'm getting several error messages and it doesn't even load at all.

I saw some suggestions to change angular.json file or using old versions but those feel very ugly workarounds for me.

csimpi avatar Sep 29 '20 14:09 csimpi

What does your import look like? With 1.2.0 I see they switched to ES6 style modules. I believe the following

import * as MapboxDraw from '@mapbox/mapbox-gl-draw';

should be changed to

import MapboxDraw from '@mapbox/mapbox-gl-draw';

However matters may be more complicated if you rolled your own type definitions. I haven't figured that out yet.

jfoshee avatar Jan 26 '21 15:01 jfoshee

@jfoshee Thank you!

I don't even remember what was this. I guess I've solved it on my own. Mapbox support is super bad, unfortunately. They are not lazy only when they're sending the USD 2000 invoice per month :) I have never got proper support to my issues not here, not at the official support.

csimpi avatar Jan 26 '21 16:01 csimpi

Try With this--->>>

import * as mapboxgl from 'mapbox-gl'; import * as MapboxDraw from "@mapbox/mapbox-gl-draw";

  this.mapDraw = new MapboxDraw.default({
      displayControlsDefault: false,
      controls: {
        polygon: false,
        line_string: false,
        point: true,
        trash: true
      },
      defaultMode: 'draw_point'
    });

It will work definately..For me working with angular 15.... By using '.default'

Souvik-Khan31 avatar Aug 04 '23 04:08 Souvik-Khan31