Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
loqtor opened this issue Jan 29, 2019 · 0 comments
Open

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

loqtor opened this issue Jan 29, 2019 · 0 comments

Comments

@loqtor
Copy link

loqtor commented Jan 29, 2019

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!

@loqtor loqtor changed the title Could not use this with Typescript How to have this type of layer added to a Leaflet map? Jan 29, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant