Skip to content

Mapbox react updates #4418

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

Merged
merged 5 commits into from
Dec 16, 2019
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
optimize update of mapbox image source
  • Loading branch information
jonmmease committed Dec 8, 2019
commit 7e355d7ec4fac17f9e98c434e86dc88fb9d765cc
26 changes: 26 additions & 0 deletions src/plots/mapbox/layers.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ proto.update = function update(opts) {
// IMPORTANT: must create source before layer to not cause errors
this.updateSource(opts);
this.updateLayer(opts);
} else if(this.needsNewImage(opts)) {
this.updateImage(opts);
} else if(this.needsNewSource(opts)) {
// IMPORTANT: must delete layer before source to not cause errors
this.removeLayer();
Expand All @@ -52,6 +54,18 @@ proto.update = function update(opts) {
this.visible = isVisible(opts);
};

proto.needsNewImage = function(opts) {
var map = this.subplot.map;
return (
map.getSource(this.idSource) &&
this.sourceType === 'image' &&
opts.sourcetype === 'image' &&
(this.source !== opts.source ||
JSON.stringify(this.coordinates) !==
JSON.stringify(opts.coordinates))
);
};

proto.needsNewSource = function(opts) {
// for some reason changing layer to 'fill' or 'symbol'
// w/o changing the source throws an exception in mapbox-gl 0.18 ;
Expand All @@ -70,6 +84,13 @@ proto.needsNewLayer = function(opts) {
);
};

proto.updateImage = function(opts) {
var map = this.subplot.map;
map.getSource(this.idSource).updateImage({
url: opts.source, coordinates: opts.coordinates
});
};

proto.updateSource = function(opts) {
var map = this.subplot.map;

Expand Down Expand Up @@ -223,6 +244,11 @@ function convertOpts(opts) {
'text-opacity': opts.opacity
});
break;
case 'raster':
Lib.extendFlat(paint, {
'raster-fade-duration': 0
});
break;
}

return {
Expand Down