Mapbox Typescript

Viewed 15279

I managed to get Leaflet working with Angular 2 and Webpack by following this project.

angular 2 leaflet starter

I can see the typings configured in "browser.d.ts":

/// <reference path="browser\ambient\leaflet\leaflet.d.ts" />

webpack.config.js defines an entry point:

...
entry: {
    'polyfills': './src/polyfills.ts',
    'libs': './src/libs.ts',
    'main': './src/main.ts'
},
...

The "libs.ts" contains the import of the Leaflet module:

import 'leaflet';

I'm using Atom as a code editor. It now recognises all the Leaflet classes and methods. I can now do things like this in Angular 2:

import {Map, TileLayer} from 'leaflet';
...
this.baseMaps = {
    StreetMap: new TileLayer('mapbox.streets')
};

Here is where my problems start. I'm trying to use mapbox.js. What I did was I installed mapbox.js library and typings:

npm install mapbox.js --save
typings install mapbox --save

This is where I'm stuck. For the life of me I can't figure out how to do what Leaflet managed to do.

import 'mapbox';

Doesn't 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 can see "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 will just 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?

2 Answers
Related