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

mapox layers reordered after updating figure with Plotly.react #5266

Closed
jonmmease opened this issue Nov 12, 2020 · 2 comments · Fixed by #5269
Closed

mapox layers reordered after updating figure with Plotly.react #5266

jonmmease opened this issue Nov 12, 2020 · 2 comments · Fixed by #5269
Labels
bug something broken

Comments

@jonmmease
Copy link
Contributor

Overview

I would like to overlay a mapbox image layer on top of a mapbox raster layer and update the image layer's coordinates and/or source properties in response to zoom/pan events using Plotly.react

On initial render, everything works fine and the z-order of the two layers matches the order in the layout.mapbox.layers array. However, after updating the image layer's coordinates in a plotly_relayout callback, the image layer is pushed behind the raster layer.

Here's an example, where the opacity of the raster layer is set to 0.5 so that you can see the image behind it.

Codepen: https://codepen.io/jonmmease/pen/vYKvxwx?editors=1010

mapbox_layer_order

Unless anyone has an idea of what might be going on here, I'll start poking around in https://github.com/plotly/plotly.js/blob/master/src/plots/mapbox/layers.js.

@archmoj archmoj added the bug something broken label Nov 12, 2020
@archmoj
Copy link
Contributor

archmoj commented Nov 12, 2020

It is an update bug here:

proto.update = function update(opts) {
if(!this.visible) {
// 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();
this.updateSource(opts);
this.updateLayer(opts);
} else if(this.needsNewLayer(opts)) {
this.updateLayer(opts);
} else {
this.updateStyle(opts);
}
this.visible = isVisible(opts);
};

It seems to work if I replace the function with something like:

proto.update = function update(opts) {
    if(!this.visible) {
        // IMPORTANT: must create source before layer to not cause errors
        this.updateSource(opts);
        this.updateLayer(opts);
    } else {
        if(this.needsNewSource(opts)) {
            // IMPORTANT: must delete layer before source to not cause errors
            this.removeLayer();
            this.updateSource(opts);
            this.updateLayer(opts);
        }

        if(this.needsNewImage(opts)) {
            this.updateImage(opts);
        }

        if(this.needsNewLayer(opts)) {
            this.updateLayer(opts);
        } else {
            this.updateStyle(opts);
        }
    }

    this.visible = isVisible(opts);
};

@jonmmease
Copy link
Contributor Author

Thanks, I'm playing with it now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug something broken
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants