Add a custom layer on headless frontend
Platform: Mapbox SDK version:
Steps to trigger behavior
-
I want to add a custom layer on map and decide to render the map and the layer in headless manner.
-
I add a custom layer followed the ExampleCustomLayer.cpp in the bin/render.cpp. The code is like this:
std::unique_ptrmbgl::style::CustomLayerHost exampleHost(new ExampleCustomLayer); auto customLayer = std::make_uniquembgl::style::CustomLayer("points", std::move(exampleHost)); map.getStyle().addLayer(std::move(customLayer));
try { std::ofstream out(output, std::ios::binary); out << encodePNG(frontend.render(map).image); out.close(); } catch(std::exception& e) { std::cout << "Error: " << e.what() << std::endl; exit(1); }
-
The custom layer does not appear and the render() function does not run at all
Could anybody give a hint or solution. Thanks in advance!
Expected behavior
the custom layer will be plotted
Actual behavior
not appear
hi, kkaefer @kkaefer, could you please give some hint to this problem? Thanks
So far, I know that the headless front render set the MapMode::static and stillImageRequest is null. Thus, Map::Impl::onUpdate() does not write the UpdateParameters. We don't need to change the map-mode, right? so we have to set stillImageRequest? and how?
It is interesting that custom_layer.test.cpp works well. It seems that map.getStyle().loadURL(style) conflict with map.addLayer. Just use map.getStyle().loadJSON