MapboxApi.js 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. import Credit from './Credit.js';
  2. import defined from './defined.js';
  3. /**
  4. * @exports MapboxApi
  5. */
  6. var MapboxApi = {};
  7. /**
  8. * The default Mapbox API access token to use if one is not provided to the
  9. * constructor of an object that uses the Mapbox API. If this property is undefined,
  10. * Cesium's default access token is used, which is only suitable for use early in development.
  11. * Please supply your own access token as soon as possible and prior to deployment.
  12. * Visit {@link https://www.mapbox.com/help/create-api-access-token/} for details.
  13. * When Cesium's default access token is used, a message is printed to the console the first
  14. * time the Mapbox API is used.
  15. *
  16. * @type {String}
  17. */
  18. MapboxApi.defaultAccessToken = undefined;
  19. var printedMapboxWarning = false;
  20. var errorCredit;
  21. var errorString = '<b>This application is using Cesium\'s default Mapbox access token. Please create a new access token for the application as soon as possible and prior to deployment by visiting <a href=https://www.mapbox.com/account/apps/>https://www.mapbox.com/account/apps/</a>, and provide your token to Cesium by setting the Cesium.MapboxApi.defaultAccessToken property before constructing the CesiumWidget or any other object that uses the Mapbox API.</b>';
  22. MapboxApi.getAccessToken = function(providedToken) {
  23. if (defined(providedToken)) {
  24. return providedToken;
  25. }
  26. if (!defined(MapboxApi.defaultAccessToken)) {
  27. if (!printedMapboxWarning) {
  28. console.log(errorString);
  29. printedMapboxWarning = true;
  30. }
  31. return 'pk.eyJ1IjoiYW5hbHl0aWNhbGdyYXBoaWNzIiwiYSI6ImNpd204Zm4wejAwNzYyeW5uNjYyZmFwdWEifQ.7i-VIZZWX8pd1bTfxIVj9g';
  32. }
  33. return MapboxApi.defaultAccessToken;
  34. };
  35. MapboxApi.getErrorCredit = function(providedToken) {
  36. if (defined(providedToken) || defined(MapboxApi.defaultAccessToken)) {
  37. return undefined;
  38. }
  39. if (!defined(errorCredit)) {
  40. errorCredit = new Credit(errorString, true);
  41. }
  42. return errorCredit;
  43. };
  44. export default MapboxApi;