I managed to get Leaflet working with Angular 2 and Webpack by completing this project.
angular 2 start sheet
I see the typing configured in "browser.d.ts":
webpack.config.js defines the entry point:
... entry: { 'polyfills': './src/polyfills.ts', 'libs': './src/libs.ts', 'main': './src/main.ts' }, ...
The "libs.ts" contains the import of the "Flyer" module:
import 'leaflet';
I use Atom as a code editor. Now it recognizes all the classes and methods of the Flyer. Now I can do something similar in Angular 2:
import {Map, TileLayer} from 'leaflet'; ... this.baseMaps = { StreetMap: new TileLayer('mapbox.streets') };
This is where my problems begin. I am trying to use mapbox.js. What I did, I installed the mapbox.js library and tickets:
npm install mapbox.js
This is where I am stuck. For life, I canβt understand how to do what Leaflet managed to do.
import 'mapbox';
Does not work.
ERROR in ./src/libs.ts Module not found: Error: Cannot resolve module 'mapbox' in C:\Develop\angular2-webpack-starter\src @ ./src/libs.ts 3:0-17
I see that "browser.d.ts" has the following:
/// <reference path="browser\ambient\leaflet\leaflet.d.ts" /> /// <reference path="browser\ambient\mapbox\mapbox.d.ts" />
I thought maybe Mapbox would work because it extends the Leaflet library?
It seems that I can basically do something like this, which is the standard javascript way:
this.baseMaps = { StreetMap: L.mapbox.tileLayer('mapbox.streets') };
But not this:
this.baseMaps = { StreetMap: new TileLayer('mapbox.streets') };
This obviously doesn't work either:
import {Map, TileLayer} from 'mapbox';
What am I doing wrong?