Skip to content

How to have this type of layer added to a Leaflet map? #2

@loqtor

Description

@loqtor

Hi,

When trying to use the CachedTileLayer by:

const cachedTile = new CachedTileLayer(`https://api.mapbox.com/styles/v1/jb-alphero/cjitgxwys4ab62rmdov2oqku9/tiles/256/{z}/{x}/{y}?access_token=${ACCESS_TOKEN}`, {
      attribution: 'Test',
      maxZoom: 18,
      // id: 'mapbox.streets',
      // accessToken: { ACCESS_TOKEN },
    }).addTo(leafletMap);

And:

const cachedTile = new CachedTileLayer(`https://api.mapbox.com/styles/v1/jb-alphero/cjitgxwys4ab62rmdov2oqku9/tiles/256/{z}/{x}/{y}?access_token=${ACCESS_TOKEN}`, {
      attribution: 'Test',
      maxZoom: 18,
      // id: 'mapbox.streets',
      // accessToken: { ACCESS_TOKEN },
    });

    leafletMap.addLayer(cachedTile);

I'm getting this error:

Argument of type 'CachedTileLayer' is not assignable to parameter of type 'Layer'.
  Types of property 'addTo' are incompatible.
    Type '(map: Map | LayerGroup<any>) => CachedTileLayer' is not assignable to type '(map: Map | LayerGroup<any>) => Layer'.
      Types of parameters 'map' and 'map' are incompatible.
        Type 'L.Map | L.LayerGroup<any>' is not assignable to type 'import("/Users/martin/Desktop/projects/metservice-consumer-web/node_modules/@yaga/leaflet-cached-...'.
          Type 'Map' is not assignable to type 'Map | LayerGroup<any>'.
            Type 'Map' is not assignable to type 'LayerGroup<any>'.
              Property 'toGeoJSON' is missing in type 'Map'.

I also tried to create a LayerGroup and adding the CachedTileLayer but got the same thing.

I noticed we have different versions of leaflet types (I'm on ^1.2.7), but there does not seem to be a difference in the methods signature.

I'm not sure what I'm doing wrong, but I'm not being capable of getting this to work. I'm sure it must be something really silly, but if you could give me a hand that'd be great.

Thanks.

Cheers!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions