How to import mapbox-gl-draw into Angular 2/4? -
i importing module in angular 2/4 app this:
import { mapboxdraw } '@mapbox/mapbox-gl-draw/dist/mapbox-gl-draw';
and using in 1 of components this:
var draw = new mapboxdraw({ displaycontrolsdefault: false, controls: { polygon: true, trash: true } }); map.addcontrol(draw);
but getting error when open page:
error typeerror: __webpack_imported_module_4__mapbox_mapbox_gl_draw_dist_mapbox_gl_draw__.mapboxdraw not constructor
what best way import mapbox-gl-draw?
this minimal example app works on machine: based on little project on github: https://github.com/haoliangyu/ngx-mapboxgl-starter
import { component } '@angular/core'; import * mapboxgl 'mapbox-gl'; import * mapboxdraw 'mapbox-gl-draw'; @component({ selector: 'app-root', templateurl: './app.component.html', styleurls: ['./app.component.css'] }) export class appcomponent { ngoninit() { mapboxgl.accesstoken = 'your token'; let map = new mapboxgl.map({ container: 'map', style: 'mapbox://styles/mapbox/light-v9', zoom: 5, center: [-78.880453, 42.897852] }); let draw = new mapboxdraw(); map.addcontrol(draw) map.on('load', function() { // application code }); } }
#map { width: 500px; height: 500px; }
<div id='map'></div>
note using 'mapbox-gl-draw'
instead of '@mapbox/mapbox-gl-draw'
. might wanna try installing package via npm install mapbox-gl-draw
. tried later 1 throws error me. don't forget add required mapbox-gl-draw css.
Comments
Post a Comment