Leaflet / Leaflet.VectorGrid

Display gridded vector data (sliced GeoJSON or protobuf vector tiles) in Leaflet 1.0.0
598 stars 194 forks source link

How can you import the module with typescript? #118

Closed rklerck closed 7 years ago

rklerck commented 7 years ago

Probably a stupid one, but I can't figure it out. I'm trying to import de module in a typescript file. But how can I do this if the module has no exports?

I'm trying to do:

import .... from 'leaflet.vectorgrid ';

So I can do the L.vectorGrid.protobuf(

Sorry if it's an obvious one, but I really can't get it to work.

haoliangyu commented 7 years ago

@rklerck You can simply import the library with

import 'leaflet.vectorgrid';

It will automatically patch the L object with the vectorGrid namespace if the type definition is written right. If you are interested in seeing a live example, take a look at ngx-leaflet-starter.

rklerck commented 7 years ago

Thnx for the quick response!

Unfortunately, when I do it like that. Typescript complains with " Cannot find name 'L' ".

import {Component} from '@angular/core';
import {Config, NavController} from 'ionic-angular';
import {PropertyService} from '../../providers/property-service-mock';
import {PropertyDetailPage} from '../property-detail/property-detail';
import leaflet from 'leaflet';
import 'leaflet.vectorgrid';

L.vectorGrid.protobuf(
rklerck commented 7 years ago

I didn't understand it but now I do finally, had to create a .d.ts file.. that's what you meant with "if the type definition is written right".

// in the global namesapce "L"
declare namespace L {
  // there is a child namespace "vectorGrid"
  namespace vectorGrid {
     export function protobuf(url: any, options?: any): any;
  }
}
mkaa commented 5 years ago

this wont build in production mode