shareabouts
shareabouts copied to clipboard
accesToken in config not passed through to app
In our local flavor's config.yml I have
layers:
- type: mapbox
style: mapbox://styles/[actual string removed]
accessToken: [actual string removed]
But, the accessToken wasn't being passed through, resulting in the error L.mapboxGL is not a function
.
The workaround was to add the token string to the settings.py:
+MAPBOX_TOKEN = env.get('MAPBOX_TOKEN', '[string]')
You can see where the Django template checks the token and loads the library here: https://github.com/openplans/shareabouts/blob/master/src/sa_web/templates/base.html#L140-L144 I think this is by design to avoid loading the mapbox-gl-js library unnecessarily.
I believe the accessToken:
attribute in the config is used only when you want to override the access token in your environment variable for a particular layer.
Perhaps this design could be more explicit. Ideally, I imagine a solution that loads modules dynamically, by using RequireJS. It seems like it would be a significant refactor, but worth it!
Agreed, this is a little akward the way that MAPBOX_TOKEN
is required for the Mapbox JS to be loaded. The docs in CONFIG.md don't really explain this properly.