mapbox / leaflet-image

leaflet maps to images
http://mapbox.github.io/leaflet-image/
BSD 2-Clause "Simplified" License
364 stars 142 forks source link

layer._adjustTilePoint is not a function #113

Open mho22 opened 6 years ago

mho22 commented 6 years ago

Hi,

I followed the steps below and when I click on the button I added to make a snapchot, it returns that error. Is the code still functional ?

I'm using this :

`

var oMapCenter =
{
    center: [50.820008, 4.368169],
    zoom: 11
}

var oTileSettings =
{
    maxZoom: 18,
    minZoom: 12,
    id: 'mapbox.streets',
    accessToken: '{{ config('app.mapbox') }}'
}

var goodMap = L.map('mapdiv', oMapCenter);
L.tileLayer('https://api.tiles.mapbox.com/v4/{id}/{z}/{x}/{y}.png?access_token={accessToken}', oTileSettings).addTo(goodMap);

document.getElementById('snap').addEventListener('click', function()
{
    leafletImage(goodMap, function(err, canvas)
     {
        // now you have canvas
        // example thing to do with that canvas:
        var img = document.createElement('img');
        var dimensions = map.getSize();
        img.width = dimensions.x;
        img.height = dimensions.y;
        img.src = canvas.toDataURL();
        document.getElementById('images').innerHTML = '';
        document.getElementById('images').appendChild(img);
    });
});

'

tombrennan06 commented 6 years ago

You need to make it clear which versions of leaflet-image and leaflet you are using.

As far as I know, _adjustTilePoint is not a function in leaflet >= 1.0.0. And 0.0.4 of leaflet-image is getting pretty old. Have you tried with the latest versions of both?

OndrejSpanel commented 6 years ago

Version 0.0.4 is mentioned in the readme as an example of CDN access:

<script src='//api.tiles.mapbox.com/mapbox.js/plugins/leaflet-image/v0.0.4/leaflet-image.js'></script>

Is a more recent version ready to use somewhere, or does one have to bundle its own?

tombrennan06 commented 6 years ago

I googled for it and found https://www.jsdelivr.com/package/npm/leaflet-image

AamirRizwan commented 5 years ago

@Itemshopp I'm getting the same error. Did you resolve the issue?

tombrennan06 commented 5 years ago

@AamirRizwan - did you read the post above? Which versions of leaflet-image and leaflet you are using? If you're using leaflet >= 1.0.0, _adjustTilePoint is no longer a function. Try with the latest versions of both.

AamirRizwan commented 5 years ago

@tombrennan06 sorry for late response. I'm using 0.4.0. Could not find a newer version. Jsdeliver has the same version i.e. 0.4.0.

GeraintEdwards commented 5 years ago

@AamirRizwan

The code is different at jsdeliever - it includes a test for layer._adjustTilePoint before its called.

I got it to work - though it is quite slow.

hirmes commented 5 years ago

Using the version at https://unpkg.com/leaflet-image@latest/leaflet-image.js solved the issue for me.