M. Atif Riaz
M. Atif Riaz

Reputation: 502

Getting error on initializing leaflet-image plugin

I have a sample code in which I am trying to use leaflet-image plugin with some leaflet map but I am getting following error on initializing leafletImage (related issue which is supposed to be resolved in version 0.8 I am using 1.0.0)

leafletImage(map, function(err, canvas) {});

Uncaught TypeError: layer._adjustTilePoint is not a function(anonymous function) @ leaflet-image.js:87handleTileLayer @ leaflet-image.js:84pop @ leaflet-image.js:201defer @ leaflet-image.js:232drawTileLayer @ leaflet-image.js:23eachLayer @ leaflet.js:6leafletImage @ leaflet-image.js:17abc @ (index):127onclick @ (index):107

see the Demo

Following the example here on leaflet-image

Upvotes: 9

Views: 2714

Answers (1)

Marko Letic
Marko Letic

Reputation: 2550

You are not using the latest version of the leaflet-image plugin. When I look at the code you have provided I can see this:

tiles.forEach(function(tilePoint) {
    var originalTilePoint = tilePoint.clone();

    layer._adjustTilePoint(tilePoint);

    var tilePos = layer._getTilePos(originalTilePoint)
        .subtract(bounds.min)
        .add(origin);

    if (tilePoint.y >= 0) {
        var url = addCacheString(layer.getTileUrl(tilePoint));
        tileQueue.defer(loadTile, url, tilePos, tileSize);
    }
});

But in the latest version of the plugin on GitHub this is corrected with:

tiles.forEach(function (tilePoint) {
    var originalTilePoint = tilePoint.clone();

    if (layer._adjustTilePoint) {
        layer._adjustTilePoint(tilePoint);
    }

    var tilePos = layer._getTilePos(originalTilePoint)
        .subtract(bounds.min)
        .add(origin);

    if (tilePoint.y >= 0) {
        if (isCanvasLayer) {
            var tile = layer._tiles[tilePoint.x + ':' + tilePoint.y];
            tileQueue.defer(canvasTile, tile, tilePos, tileSize);
        } else {
            var url = addCacheString(layer.getTileUrl(tilePoint));
            tileQueue.defer(loadTile, url, tilePos, tileSize);
        }
    }
});

So just include the proper version of the plugin and everything will be fine.

Upvotes: 5

Related Questions