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

Add a custom layer on headless frontend

Open phifaner opened this issue 5 years ago • 3 comments

Platform: Mapbox SDK version:

Steps to trigger behavior

  1. I want to add a custom layer on map and decide to render the map and the layer in headless manner.

  2. 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); }

  3. 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

phifaner avatar Aug 28 '20 16:08 phifaner

hi, kkaefer @kkaefer, could you please give some hint to this problem? Thanks

phifaner avatar Aug 30 '20 03:08 phifaner

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?

phifaner avatar Aug 30 '20 04:08 phifaner

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

phifaner avatar Aug 30 '20 15:08 phifaner