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

Fix updating image before initial image is loaded or the loading failed #12928

Closed
Closed
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
2 changes: 1 addition & 1 deletion src/source/image_source.js
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ class ImageSource extends Evented implements Source {
* });
*/
updateImage(options: {url: string, coordinates?: Coordinates}): this {
if (!this.image || !options.url) {
if (!options.url) {
return this;
}
if (this._imageRequest && options.url !== this.options.url) {
Expand Down
23 changes: 23 additions & 0 deletions test/unit/source/image_source.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,12 @@ test('ImageSource', (t) => {
img.onload();
img.data = new Uint8Array(req.response);
};
const respondNotFound = () => {
const req = requests.shift();
req.setStatus(404);
req.onerror();
req.response = new ArrayBuffer(1);
};
t.stub(browser, 'getImageData').callsFake(() => new ArrayBuffer(1));

t.test('constructor', (t) => {
Expand Down Expand Up @@ -256,5 +262,22 @@ test('ImageSource', (t) => {
t.end();
});

t.test('updates image before first image was loaded', (t) => {
const source = createSource({url : '/notfound.png'});
const map = new StubMap();
const spy = t.spy(map._requestManager, 'transformRequest');
const errorStub = t.stub(console, 'error');
source.onAdd(map);
respondNotFound();
t.ok(errorStub.calledOnce);
t.notOk(source.image);
source.updateImage({url: '/image2.png'});
respond();
t.ok(spy.calledTwice);
t.equal(spy.getCall(1).args[0], '/image2.png');
t.equal(spy.getCall(1).args[1], 'Image');
t.end();
});

t.end();
});