angulartypescriptleafletngx-leafletfireflysemantics-slice

Typescript typing for leaflet options?


We can initialize leaflet like this, using an any type. Just wondering whether there is a more direct type we can use? Something like LeafletOptions?

  leafletOptions: any = {
    zoom: 2,
    minZoom: 2,
    maxZoom: 4,
    zoomControl: false,
    center: L.latLng({ lat: 38.991709, lng: -76.886109 }),
    maxBounds: new L.LatLngBounds(
      new L.LatLng(-89.98155760646617, -180),
      new L.LatLng(89.99346179538875, 180)
    ),
    maxBoundsViscosity: 1.0,
  };

Solution

  • If you’re using the definitely typed package, it’s called MapOptions

    https://github.com/DefinitelyTyped/DefinitelyTyped/blob/98f892cafa74e0217c7d2b5d87c8cc673365a434/types/leaflet/index.d.ts#L1903

    It looks like ngx-leaflet does use that package

    https://github.com/bluehalo/ngx-leaflet/blob/e0990a3c99338fd216fef22d8e65f5e6b338334b/package.json#L23