Skip to content

Commit

Permalink
Better error for elements that cannot be drawn. Fixes mapbox#29
Browse files Browse the repository at this point in the history
  • Loading branch information
tmcw committed May 18, 2016
1 parent 1b692d6 commit 395ce1b
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 8 deletions.
12 changes: 8 additions & 4 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -172,10 +172,14 @@ module.exports = function leafletImage(map, callback) {
canvas.height = dimensions.y;
var ctx = canvas.getContext('2d');
var pos = L.DomUtil.getPosition(root).subtract(bounds.min).add(origin);
ctx.drawImage(root, pos.x, pos.y, canvas.width - (pos.x * 2), canvas.height - (pos.y * 2));
callback(null, {
canvas: canvas
});
try {
ctx.drawImage(root, pos.x, pos.y, canvas.width - (pos.x * 2), canvas.height - (pos.y * 2));
callback(null, {
canvas: canvas
});
} catch(e) {
console.error('Element could not be drawn on canvas', root);
}
}

function handleMarkerLayer(marker, callback) {
Expand Down
12 changes: 8 additions & 4 deletions leaflet-image.js
Original file line number Diff line number Diff line change
Expand Up @@ -173,10 +173,14 @@ module.exports = function leafletImage(map, callback) {
canvas.height = dimensions.y;
var ctx = canvas.getContext('2d');
var pos = L.DomUtil.getPosition(root).subtract(bounds.min).add(origin);
ctx.drawImage(root, pos.x, pos.y, canvas.width - (pos.x * 2), canvas.height - (pos.y * 2));
callback(null, {
canvas: canvas
});
try {
ctx.drawImage(root, pos.x, pos.y, canvas.width - (pos.x * 2), canvas.height - (pos.y * 2));
callback(null, {
canvas: canvas
});
} catch(e) {
console.error('Element could not be drawn on canvas', root);
}
}

function handleMarkerLayer(marker, callback) {
Expand Down

0 comments on commit 395ce1b

Please sign in to comment.