mapbox-gl-export icon indicating copy to clipboard operation
mapbox-gl-export copied to clipboard

Saving image does not preserve colors

Open m0hamad opened this issue 3 years ago • 5 comments

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.

m0hamad avatar Oct 21 '20 00:10 m0hamad

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.

JinIgarashi avatar Oct 21 '20 21:10 JinIgarashi

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:

initial_colour color_change

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.

m0hamad avatar Nov 06 '20 16:11 m0hamad

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?

JinIgarashi avatar Nov 07 '20 00:11 JinIgarashi

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.

m0hamad avatar Nov 10 '20 16:11 m0hamad

Hi @m0hamad Thanks. Let me continue to search the solution for this issue.

JinIgarashi avatar Nov 11 '20 13:11 JinIgarashi