How to use the terriajs-cesium/Source/ThirdParty/when.all function in terriajs-cesium

To help you get started, we’ve selected a few terriajs-cesium examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github TerriaJS / terriajs / lib / Map / RegionProvider.js View on Github external
promises.push(loadText(url)
        .then(function(xml) {
            that.loadRegionsFromXML(xml, undefined, "serverReplacements");
        }).otherwise(function(err) {
            console.log(err);
            throw(err);
        }));
    // if this column might be ambiguous then fetch the disambiguating values for each column as well (usually State)
    if (this.disambigProp) {
        url = baseuri.setQuery('valueReference', this.disambigProp).toString();
        promises.push(loadText(url).then(function(xml) {
            that.loadRegionsFromXML(xml, that.disambigProp, "disambigServerReplacements");
        }));
    }
    return when.all(promises).yield(true);
};
github TerriaJS / terriajs / lib / Models / ArcGisMapServerCatalogGroup.js View on Github external
ArcGisMapServerCatalogGroup.prototype._load = function() {
    var serviceUrl = cleanAndProxyUrl(this.terria, this.url) + '?f=json';
    var layersUrl = cleanAndProxyUrl(this.terria, this.url) + '/layers?f=json';

    var that = this;
    return when.all([loadJson(serviceUrl), loadJson(layersUrl)]).then(function(result) {
        var serviceJson = result[0];
        var layersJson = result[1];

        // Is this really a MapServer REST response?
        if (!serviceJson || !serviceJson.layers || !layersJson || !layersJson.layers) {
            throw new ModelError({
                title: 'Invalid ArcGIS Map Service',
                message: '\
An error occurred while invoking the ArcGIS Map Service.  The server\'s response does not appear to be a valid Map Service document.  \
<p>If you entered the link manually, please verify that the link is correct.</p>\
<p>If you did not enter this link manually, this error may indicate that the group you opened is temporarily unavailable or there is a \
problem with your internet connection.  Try opening the group again, and if the problem persists, please report it by \
sending an email to <a href="mailto:nationalmap@lists.nicta.com.au">nationalmap@lists.nicta.com.au</a>.</p>'
            });
        }
github TerriaJS / terriajs / lib / Models / SdmxJsonCatalogItem.js View on Github external
if (defined(totalsRequestString)) {
        if (!defined(item._regionTotals[totalsRequestString])) {
          var totalsUrl = getUrlFromDimensionRequestString(
            item,
            totalsRequestString
          );
          promises.push(item._getData(proxyCatalogItemUrl(item, totalsUrl)));
        }
      }
    }
  } else {
    url = item.originalUrl;
  }
  promises.push(item._getData(proxyCatalogItemUrl(item, url)));
  item.isLoading = true;
  return when
    .all(promises)
    .then(function(jsons) {
      // jsons is an array of length 1 or 2, with optional total data json first, then the specific data json.
      var json = jsons[jsons.length - 1]; // the specific json.

      // The structure of the SDMX 2.1 response is slightly different
      if (item.sdmxVersionNumber === 2.1) json = json.data;

      if (jsons.length === 2) {
        // Process and save the region totals as a datasets object.
        var totalsJson = jsons[0];
        if (item.sdmxVersionNumber === 2.1)
          totalsJson = convertTotalsJson(jsons[0].data);

        sdmxJsonLib.response.prepare(totalsJson);
        item._regionTotals[totalsRequestString] = {
github TerriaJS / terriajs / lib / Models / CatalogItem.js View on Github external
var terria = catalogItem.terria;

  if (defined(catalogItem.creatorCatalogItem)) {
    catalogItem.creatorCatalogItem.isEnabled = catalogItem.isEnabled;
  }

  if (catalogItem.isEnabled) {
    terria.nowViewing.add(catalogItem);

    // Load this catalog item's data (if we haven't already) when it is enabled.
    // Don't actually enable until the load finishes.
    // Be careful not to call _enable multiple times or to call _enable
    // after the item has already been disabled.
    if (!defined(catalogItem._loadForEnablePromise)) {
      var resolvedOrRejected = false;
      var loadPromise = when
        .all([catalogItem.load(), catalogItem.waitForDisclaimerIfNeeded()])
        .then(function() {
          if (catalogItem.isEnabled) {
            // If there's a separate now viewing item, remove this catalog item from the
            // now viewing list, if it exists.
            if (defined(catalogItem.nowViewingCatalogItem)) {
              catalogItem.terria.nowViewing.items.remove(catalogItem);
            }

            catalogItem._enable();
            catalogItem.terria.currentViewer.notifyRepaintRequired();
            catalogItem.terria.currentViewer.addAttribution(
              catalogItem.attribution
            );
            if (defined(catalogItem.imageryLayer)) {
              catalogItem.imageryLayer.featureInfoTemplate =
github TerriaJS / terriajs / lib / Models / addUserFiles.js View on Github external
createCatalogItemFromFileOrUrl(
          terria,
          viewState,
          file,
          dataType.value,
          true
        )
      );
      promises.push(loadPromise);
    }
    tempCatalogItem.loadPromise = loadPromise;
    tempCatalogItem.isEnabled = true;
    tempCatalogItemList.push(tempCatalogItem);
  }

  return when.all(promises, addedItems => {
    // if addedItem has only undefined item, means init files
    // have been uploaded
    if (addedItems.every(item => item === undefined)) {
      viewState.openAddData();
    } else {
      const items = addedItems.filter(
        item => item && !(item instanceof TerriaError)
      );
      tempCatalogItemList.forEach(function(value) {
        terria.catalog.userAddedDataGroup.remove(value);
      });
      return items;
    }
  });
}
github TerriaJS / terriajs / lib / Models / AbsIttCatalogItemOLD.js View on Github external
if (concept.code === that.regionTypeConcept) {
                concept.isUnique = true;
            }

            if (defined(codeGroups)) {
                var json = codeGroups[conceptID];
                if (defined(json)) {
                    promises.push(addConceptCodes(concept, json));
                }
            }
            else {
                promises.push(loadFunc(url, concept));
            }
        }
        return when.all(promises).then( function(results) {
            // put region type first and then sort after that
            var makeFirst = that.regionTypeConcept;
            that.absDataset.items.sort(function(a, b){
                return (a.code === makeFirst) ? -1 : ((b.code === makeFirst) ? 1 : (a.name > b.name ? 1 : -1));
            });

            return when(updateAbsResults(that)).then(function() {
                that._absDataset.isLoading = false;
            });

        });
    }).otherwise(function(e) {
        throw new TerriaError({
github TerriaJS / terriajs / lib / ReactViews / Analytics / RegionPicker.jsx View on Github external
addRegionLayer() {
    if (!defined(this.regionProvider)) {
      return;
    }

    if (this.regionProvider === this._loadingRegionProvider) {
      // The region provider hasn't changed.
      return;
    }

    this._loadingRegionProvider = this.regionProvider;

    const that = this;
    when
      .all([
        that.regionProvider.loadRegionIDs(),
        that.regionProvider.loadRegionNames()
      ])
      .then(function() {
        if (that.regionProvider !== that._loadingRegionProvider) {
          return;
        }
        that._regionNames = that.regionProvider.regionNames;

        if (defined(that._regionsCatalogItem)) {
          that._regionsCatalogItem.isEnabled = false;
          that._regionsCatalogItem = undefined;
        }

        that._regionsCatalogItem = new WebMapServiceCatalogItem(
github TerriaJS / terriajs / lib / ViewModels / ToolsPanelViewModel.js View on Github external
ToolsPanelViewModel.prototype.cacheTiles = function() {
    var requests = [];
    var promises = [];
    getAllRequests(['wms', 'esri-mapServer'], this.cacheFilter, requests, this.terria.catalog.group, promises);

    var that = this;
    when.all(promises, function() {
        console.log('Requesting tiles in zoom range ' + that.minZoomLevel + '-' + that.maxZoomLevel + ' from ' + requests.length + ' data sources.');
        requestTiles(that, requests, Number(that.minZoomLevel), Number(that.maxZoomLevel));
    });
};
github TerriaJS / terriajs / lib / ReactViews / Map / Panels / ToolsPanel / CountDatasets.jsx View on Github external
reportLoadError.bind(undefined, item, stats, path.slice())
                )
            );
          } else {
            promises.push(
              recurseAndUpdateTotals(item, stats, childStats, path)
            );
          }

          path.pop();
        } else {
          ++stats.items;
        }
      }

      return when.all(promises);
    }
github TerriaJS / terriajs / lib / ViewModels / ToolsPanelViewModel.js View on Github external
path.push(item.name);

                var loadPromise = item.load();
                if (defined(loadPromise) && item.isLoading) {
                    promises.push(loadPromise.then(recurseAndUpdateTotals.bind(undefined, item, stats, childStats, path.slice())).otherwise(reportLoadError.bind(undefined, item, stats, path.slice())));
                } else {
                    promises.push(recurseAndUpdateTotals(item, stats, childStats, path));
                }

                path.pop();
            } else {
                ++stats.items;
            }
        }

        return when.all(promises);
    }