openplans / shareabouts

Shareabouts is a mapping application for crowdsourced info gathering.
GNU General Public License v3.0
276 stars 149 forks source link

accesToken in config not passed through to app #161

Open eveostay opened 8 years ago

eveostay commented 8 years ago

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]')

modulitos commented 8 years ago

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!

BenSturmfels commented 1 year ago

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.