mapbox-gl-export
mapbox-gl-export copied to clipboard
Saving image does not preserve colors
I am trying to use this to screenshot the map with a GeoJSON feature Layer that has different colors, and the layer is saved as part of the screenshot, but not the colors. Thank you.
Hi @m0hamad , thank you for the report. Actually, I have never tested this plugin with GeoJSON layer. Could you tell me more detailed information about it? If you can provide any sample source code, I can try it what is happening. Also, please share some screenshot images. so I can easily understand the problem.
Hi @JinIgarashi, so sorry for the late reply.
Mapbox has a map.addSource()
, where you can supply it with GeoJSON data, and within the properties of the data, we have colour. When we call map.addLayer()
, we can then set the initial colour or colours of each data point of the layer. As it turns out, the screenshot feature works great for that, but for our app, we can change the colours of different parts of the layer after initially loading it:


The problem is that when we change the colour of any of those buildings and try to screenshot, the screenshot only shows the original colours. Here is the function we use:
map.setFeatureState( { id: id, source: 'buildings-source' }, { id: id, click: true, color: color } );
If there is a way to show the colours in the screenshot from this function, or if there is another way to colour the layer that will work with screenshots that would be amazing. Thank you.
Hi @m0hamad
I understood the situation. My plugin will regenerate new map canvas for exporting from Mapbox style by map.getStyle()
. I guess map.getStyle()
will not contains style of FeatureState
.
https://github.com/watergis/mapbox-gl-export/blob/0d7c7679501cd8999772194f5c5f14329037af61/lib/map-generator.ts#L88-L99
If there is a way to recover FeatureState's style after regenerate Map object, I think it can produce an image with color. I found there is a method of getFeatureState, but it might be difficult to use this method.
Do you have any idea?
Hi @JinIgarashi
I cannot seem to find a way to use getFeatureState as part of the snapshot feature. I was wondering if you got the style of the map on the initial load or if you get the current map style after I click on the button.
Thank you for trying to look into this.
Hi @m0hamad Thanks. Let me continue to search the solution for this issue.