src/imageLoader.js
function loadImageFromImageLoader (imageId, options) {
  const colonIndex = imageId.indexOf(':');
  const scheme = imageId.substring(0, colonIndex);
  const loader = imageLoaders[scheme];

  if (loader === undefined || loader === null) {
    if (unknownImageLoader !== undefined) {
      return unknownImageLoader(imageId);
    }

    throw new Error('loadImageFromImageLoader: no image loader for imageId');
  }

  const imageLoadObject = loader(imageId, options);

  // Broadcast an image loaded event once the image is loaded
  imageLoadObject.promise.then(function (image) {
    triggerEvent(events, EVENTS.IMAGE_LOADED, { image });
  }, function (error) {
    const errorObject = {
      imageId,
      error
    };

    triggerEvent(events, EVENTS.IMAGE_LOAD_FAILED, errorObject);
  });

  return imageLoadObject;
}
function loadImageFromImageLoader (imageId, options) {
  const colonIndex = imageId.indexOf(':');
  const scheme = imageId.substring(0, colonIndex);
  const loader = imageLoaders[scheme];

  if (loader === undefined || loader === null) {
    if (unknownImageLoader !== undefined) {
      return unknownImageLoader(imageId);
    }

    throw new Error('loadImageFromImageLoader: no image loader for imageId');
  }

  const imageLoadObject = loader(imageId, options);

  // Broadcast an image loaded event once the image is loaded
  imageLoadObject.promise.then(function (image) {
    triggerEvent(events, EVENTS.IMAGE_LOADED, { image });
  }, function (error) {
    const errorObject = {
      imageId,
      error
    };

    triggerEvent(events, EVENTS.IMAGE_LOAD_FAILED, errorObject);
  });

  return imageLoadObject;
}
function loadImageFromImageLoader ( imageId , options ) { const colonIndex = imageId . indexOf ( ':' ) ; const scheme = imageId . substring ( 0 , colonIndex ) ; const loader = imageLoaders [ scheme ] ; if ( loader === undefined || loader === null ) { if ( unknownImageLoader !== undefined ) { return unknownImageLoader ( imageId ) ; } throw new Error ( 'loadImageFromImageLoader: no image loader for imageId' ) ; } const imageLoadObject = loader ( imageId , options ) ; // Broadcast an image loaded event once the image is loaded
 imageLoadObject . promise . then ( function ( image ) { triggerEvent ( events , EVENTS . IMAGE_LOADED , { image } ) ; } , function ( error ) { const errorObject = { imageId , error } ; triggerEvent ( events , EVENTS . IMAGE_LOAD_FAILED , errorObject ) ; } ) ; return imageLoadObject ; }
Load an image using a registered Cornerstone Image Loader.

The image loader that is used will be
determined by the image loader scheme matching against the imageId.

@param {String} imageId A Cornerstone Image Object's imageId
@param {Object} [options] Options to be passed to the Image Loader

@returns {ImageLoadObject} An Object which can be used to act after an image is loaded or loading fails
@memberof ImageLoader
Load an image using a registered Cornerstone Image Loader .