Source: Core/loadArrayBuffer.js

  1. /*global define*/
  2. define([
  3. './loadWithXhr'
  4. ], function(
  5. loadWithXhr) {
  6. 'use strict';
  7. /**
  8. * Asynchronously loads the given URL as raw binary data. Returns a promise that will resolve to
  9. * an ArrayBuffer once loaded, or reject if the URL failed to load. The data is loaded
  10. * using XMLHttpRequest, which means that in order to make requests to another origin,
  11. * the server must have Cross-Origin Resource Sharing (CORS) headers enabled.
  12. *
  13. * @exports loadArrayBuffer
  14. *
  15. * @param {String|Promise.<String>} url The URL of the binary data, or a promise for the URL.
  16. * @param {Object} [headers] HTTP headers to send with the requests.
  17. * @returns {Promise.<ArrayBuffer>} a promise that will resolve to the requested data when loaded.
  18. *
  19. *
  20. * @example
  21. * // load a single URL asynchronously
  22. * Cesium.loadArrayBuffer('some/url').then(function(arrayBuffer) {
  23. * // use the data
  24. * }).otherwise(function(error) {
  25. * // an error occurred
  26. * });
  27. *
  28. * @see {@link http://www.w3.org/TR/cors/|Cross-Origin Resource Sharing}
  29. * @see {@link http://wiki.commonjs.org/wiki/Promises/A|CommonJS Promises/A}
  30. */
  31. function loadArrayBuffer(url, headers) {
  32. return loadWithXhr({
  33. url : url,
  34. responseType : 'arraybuffer',
  35. headers : headers
  36. });
  37. }
  38. return loadArrayBuffer;
  39. });