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

add the ability to load images using ajax #51

Open
wants to merge 10 commits into
base: gh-pages
Choose a base branch
from
Prev Previous commit
adding Uint8Array to globals
robertleeplummerjr committed Jun 8, 2016

Verified

This commit was signed with the committer’s verified signature.
Okabe-Junya Junya Okabe
commit c6c74af09d7f434a3ad34ad88e08fc0d0a67c239
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* global L */
/* global L, Uint8Array */

var queue = require('d3-queue').queue;

12 changes: 6 additions & 6 deletions leaflet-image.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
(function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.leafletImage = f()}})(function(){var define,module,exports;return (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){
/* global L */
/* global L, Uint8Array */

var queue = require('d3-queue').queue;

@@ -66,7 +66,7 @@ module.exports = function leafletImage(map, callback, useAjax) {
});
layers.forEach(function (layer) {
if (layer && layer.img && !layer.canvas) {
ctx.drawImage(layer.img, 0, 0);
ctx.drawImage(layer.img, 0, 0);
}
});
done();
@@ -233,15 +233,15 @@ module.exports = function leafletImage(map, callback, useAjax) {
getBase64(url, function (data) {
im.src = imageCache[marker._icon.src] = 'data: image/png;base64, ' + data;
if (!loaded) {
setTimeout(function() {
setTimeout(function () {
im.onload();
},0);
}
});
} else {
im.src = cache;
if (!loaded) {
setTimeout(function() {
setTimeout(function () {
im.onload();
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The image isn't yet added to the page, but is base64. setTimeout(fn, 0) ensures it is loaded when the next available context is, which (since we just set the src) is just after the src is rendered. Otherwise the image is not yet rendered, thus resulting in a blank image.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry for the tardy response.

},0);
}
@@ -274,7 +274,7 @@ module.exports = function leafletImage(map, callback, useAjax) {
var request = new XMLHttpRequest();
request.open('GET', url, true);
request.responseType = 'arraybuffer';
request.onload = function() {
request.onload = function () {
if (request.status >= 200 && request.status < 400) {
var buffer = this.response,
binary = '',
@@ -297,7 +297,7 @@ module.exports = function leafletImage(map, callback, useAjax) {
callback(null, {
img: img
});
})
});
}
};