digidem / mapbox-map-image-export

Export a Mapbox GL map to a hi-res image for printing
MIT License
85 stars 21 forks source link

WebGL and linux #3

Closed tomino62 closed 7 years ago

tomino62 commented 7 years ago

Hi,

Can you tell me if the app can work on Linux server ?

I got this error :

Error: Failed to initialize WebGL at Map._setupPainter (/usr/lib/node_modules/mapbox-map-image-export/node_modules/mapbox-gl/dist/mapbox-gl-dev.js:16714:41) at new Map (/usr/lib/node_modules/mapbox-map-image-export/node_modules/mapbox-gl/dist/mapbox-gl-dev.js:15815:14) at mapMosaicStream (/usr/lib/node_modules/mapbox-map-image-export/lib/map_mosaic_stream.js:41:13) at Object. (/usr/lib/node_modules/mapbox-map-image-export/index.js:27:17) at Module._compile (module.js:541:32) at Object.devtoolCompileModule [as .js] (/usr/lib/node_modules/mapbox-map-image-export/node_modules/devtool/lib/require-hook.js:32:14) at Module.load (module.js:458:32) at tryModuleLoad (module.js:417:12) at Function.Module._load (module.js:409:3) at Module.require (module.js:468:17) TypeError: /usr/lib/node_modules/mapbox-map-image-export/index.js Cannot read property 'resize' of undefined at Map.resize (/usr/lib/node_modules/mapbox-map-image-export/node_modules/mapbox-gl/dist/mapbox-gl-dev.js:16000:21) at new Map (/usr/lib/node_modules/mapbox-map-image-export/node_modules/mapbox-gl/dist/mapbox-gl-dev.js:15844:14) at mapMosaicStream (/usr/lib/node_modules/mapbox-map-image-export/lib/map_mosaic_stream.js:41:13) at Object. (/usr/lib/node_modules/mapbox-map-image-export/index.js:27:17) at Module._compile (module.js:541:32) at Object.devtoolCompileModule [as .js] (/usr/lib/node_modules/mapbox-map-image-export/node_modules/devtool/lib/require-hook.js:32:14) at Module.load (module.js:458:32) at tryModuleLoad (module.js:417:12) at Function.Module._load (module.js:409:3) at Module.require (module.js:468:17)

Thx for your help.

kriscarle commented 7 years ago

I'll try to jump in and help here. To run WebGL headless on a Linux server, you probably need to use xvfb Here is a Docker container that could work as a starting point: https://github.com/kfatehi/docker-chrome-xvfb

I'm using a bit of a different approach, using the Manet screenshot tool https://github.com/vbauer/manet running with xvfb in Docker https://github.com/openmaphub/manet-dockerfile. Very curious to try out this project though :)

gmaclennan commented 7 years ago

Thanks for jumping in @kriscarle. I had tried to get this running headless on travisCI but with no luck, I was wondering if it was because WebGL is not supported on the platform the CI servers are running on. I believe WebGL does require a graphics card to work, so it would not work with a server without one.

@tomino62 you might have luck with https://github.com/mapbox/mapbox-gl-native/ I have found it to be behind mapbox-gl-js in terms of features, which has resulted in maps rendering differently. I think this is what Mapbox uses internally for rendering static maps, since I have seen the same differences in those vs. mapbox-gl-js rendering. I'd be interested to hear how it goes.

kriscarle commented 7 years ago

@gmaclennan mapbox-gl-native has a xvfb config that works on Travis https://github.com/mapbox/mapbox-gl-native/blob/master/scripts/travis_setup.sh

mapbox-gl-native is where I started, but at least back then there were too many implementation differences, plus I couldn't include overlays like legends, markers, etc., so I went back to screenshots.

I also ended up using SlimerJS and Gecko. Too many issues with Chromium/PhantomJS. Though that has possibly been fixed, Chrome 59 has headless support https://news.ycombinator.com/item?id=14101233

gmaclennan commented 7 years ago

Great info Kris, thanks! This is running on headless Electron by the way, so full Chrome rather than PhantomJS. The main reason for the approach is because we were exporting maps at 7 feet x 5 feet and approx. 25,000 pixels across, so we needed something that could stream without holding the exported image in memory.

kriscarle commented 7 years ago

Cool I'll definitely have to check it out then.

cooljacob204 commented 2 years ago

I recently came across this issue and this thread is the top one on google however it didn't fix my issue.

So after much research I figured it out, this was my fix:

I installed chromium-swiftshader and passed these arguments to chromium '--enable-webgl', '--use-gl=swiftshader'