Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,27 @@ module.exports = function leafletImage(map, callback) {

function drawTileLayer(l) {
if (l instanceof L.TileLayer) layerQueue.defer(handleTileLayer, l);
else if (l instanceof L.ImageOverlay) layerQueue.defer(handleImageOverlay, l);
else if (l._heat) layerQueue.defer(handlePathRoot, l._canvas);
}

function handleImageOverlay(imgOverlay, callback) {
var imgBounds = imgOverlay.getBounds(),
bounds = new L.Bounds(
map.latLngToLayerPoint(imgBounds.getNorthWest()),
map.latLngToLayerPoint(imgBounds.getSouthEast())),
size = bounds.getSize();
var imageObj = new Image();
imageObj.src = imgOverlay._url;
imageObj.onload = function () {
var ctx = canvas.getContext('2d');
ctx.drawImage(this, bounds.min.x, bounds.min.y, size.x, size.y);
callback(null, {
canvas: canvas
});
};
}

function drawMarkerLayer(l) {
if (l instanceof L.Marker && l.options.icon instanceof L.Icon) {
layerQueue.defer(handleMarkerLayer, l);
Expand Down
20 changes: 20 additions & 0 deletions leaflet-image.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,27 @@ module.exports = function leafletImage(map, callback) {

function drawTileLayer(l) {
if (l instanceof L.TileLayer) layerQueue.defer(handleTileLayer, l);
else if (l instanceof L.ImageOverlay) layerQueue.defer(handleImageOverlay, l);
else if (l._heat) layerQueue.defer(handlePathRoot, l._canvas);
}

function handleImageOverlay(imgOverlay, callback) {
var imgBounds = imgOverlay.getBounds(),
bounds = new L.Bounds(
map.latLngToLayerPoint(imgBounds.getNorthWest()),
map.latLngToLayerPoint(imgBounds.getSouthEast())),
size = bounds.getSize();
var imageObj = new Image();
imageObj.src = imgOverlay._url;
imageObj.onload = function () {
var ctx = canvas.getContext('2d');
ctx.drawImage(this, bounds.min.x, bounds.min.y, size.x, size.y);
callback(null, {
canvas: canvas
});
};
}

function drawMarkerLayer(l) {
if (l instanceof L.Marker && l.options.icon instanceof L.Icon) {
layerQueue.defer(handleMarkerLayer, l);
Expand Down Expand Up @@ -250,6 +268,8 @@ module.exports = function leafletImage(map, callback) {
}

function addCacheString(url) {
// workaround for https://github.com/mapbox/leaflet-image/issues/84
if (!url) return url;
// If it's a data URL we don't want to touch this.
if (isDataURL(url) || url.indexOf('mapbox.com/styles/v1') !== -1) {
return url;
Expand Down