lib/Models/SensorObservationServiceCatalogItem.js
function loadObservationData(item) {
  if (!item._featureMapping) {
    return;
  }
  var featuresOfInterest = Object.keys(item._featureMapping);
  // Are there too many features to load observations (or we've been asked not to try)?
  if (
    !item.tryToLoadObservationData ||
    featuresOfInterest.length > item.requestSizeLimit * item.requestNumberLimit
  ) {
    // MODE 1. Do not load observation data for the features.
    // Just show where the features are, and when the feature info panel is opened, then load the feature's observation data
    // (via the 'chart' column in _tableStructure, which generates a call to item.loadIntoTableStructure).
    var tableStructure = item._tableStructure;
    if (!defined(tableStructure)) {
      tableStructure = new TableStructure(item.name);
    }
    var columns = createColumnsFromMapping(item, tableStructure);
    tableStructure.columns = columns;
    if (!defined(item._tableStructure)) {
      item._tableStyle.dataVariable = null; // Turn off the legend and give all the points a single colour.
      item.initializeFromTableStructure(tableStructure);
    } else {
      item._tableStructure.columns = tableStructure.columns;
    }
    return when();
  }
  // MODE 2. Create a big time-varying tableStructure with all the observations for all the features.
  // In this mode, the feature info panel shows a chart through as a standard time-series, like it would for any time-varying csv.
  return item
    .loadIntoTableStructure(featuresOfInterest)
    .then(function(observationTableStructure) {
      if (
        !defined(observationTableStructure) ||
        observationTableStructure.columns[0].values.length === 0
      ) {
        throw new TerriaError({
          sender: item,
          title: item.name,
          message:
            "The Sensor Observation Service did not return any features matching your query."
        });
      }
      // Add the extra columns from the mapping into the table.
      var identifiers = observationTableStructure.getColumnWithName(
        "identifier"
      ).values;
      var newColumns = createColumnsFromMapping(
        item,
        observationTableStructure,
        identifiers
      );
      observationTableStructure.activeTimeColumnNameIdOrIndex = undefined;
      observationTableStructure.columns = observationTableStructure.columns.concat(
        newColumns
      );
      observationTableStructure.idColumnNames = item._idColumnNames;
      if (item.showFeaturesAtAllTimes) {
        // Set finalEndJulianDate so that adding new null-valued feature rows doesn't mess with the final date calculations.
        // To do this, we need to set the active time column, so that finishJulianDates is calculated.
        observationTableStructure.setActiveTimeColumn(
          item.tableStyle.timeColumn
        );
        var finishDates = observationTableStructure.finishJulianDates.map(d =>
          Number(JulianDate.toDate(d))
        );
        // I thought we'd need to unset the time column, because we're about to change the columns again, and there can be interactions
        // - but it works without unsetting it.
        // observationTableStructure.setActiveTimeColumn(undefined);
        observationTableStructure.finalEndJulianDate = JulianDate.fromDate(
          new Date(Math.max.apply(null, finishDates))
        );
        observationTableStructure.columns = observationTableStructure.getColumnsWithFeatureRowsAtStartAndEndDates(
          "date",
          "value"
        );
      }
      if (!defined(item._tableStructure)) {
        observationTableStructure.name = item.name;
        item.initializeFromTableStructure(observationTableStructure);
      } else {
        observationTableStructure.setActiveTimeColumn(
          item.tableStyle.timeColumn
        );
        // Moving this isActive statement earlier stops all points appearing on the map/globe.
        observationTableStructure.columns.filter(
          column => column.id === "value"
        )[0].isActive = true;
        item._tableStructure.columns = observationTableStructure.columns; // TODO: doesn't do anything.
        // Force the timeline (terria.clock) to update by toggling "isShown" (see CatalogItem's isShownChanged).
        if (item.isShown) {
          item.isShown = false;
          item.isShown = true;
        }
        // Changing the columns triggers a knockout change of the TableDataSource that uses this table.
      }
    });
}
function loadObservationData(item) {
  if (!item._featureMapping) {
    return;
  }
  var featuresOfInterest = Object.keys(item._featureMapping);
  // Are there too many features to load observations (or we've been asked not to try)?
  if (
    !item.tryToLoadObservationData ||
    featuresOfInterest.length > item.requestSizeLimit * item.requestNumberLimit
  ) {
    // MODE 1. Do not load observation data for the features.
    // Just show where the features are, and when the feature info panel is opened, then load the feature's observation data
    // (via the 'chart' column in _tableStructure, which generates a call to item.loadIntoTableStructure).
    var tableStructure = item._tableStructure;
    if (!defined(tableStructure)) {
      tableStructure = new TableStructure(item.name);
    }
    var columns = createColumnsFromMapping(item, tableStructure);
    tableStructure.columns = columns;
    if (!defined(item._tableStructure)) {
      item._tableStyle.dataVariable = null; // Turn off the legend and give all the points a single colour.
      item.initializeFromTableStructure(tableStructure);
    } else {
      item._tableStructure.columns = tableStructure.columns;
    }
    return when();
  }
  // MODE 2. Create a big time-varying tableStructure with all the observations for all the features.
  // In this mode, the feature info panel shows a chart through as a standard time-series, like it would for any time-varying csv.
  return item
    .loadIntoTableStructure(featuresOfInterest)
    .then(function(observationTableStructure) {
      if (
        !defined(observationTableStructure) ||
        observationTableStructure.columns[0].values.length === 0
      ) {
        throw new TerriaError({
          sender: item,
          title: item.name,
          message:
            "The Sensor Observation Service did not return any features matching your query."
        });
      }
      // Add the extra columns from the mapping into the table.
      var identifiers = observationTableStructure.getColumnWithName(
        "identifier"
      ).values;
      var newColumns = createColumnsFromMapping(
        item,
        observationTableStructure,
        identifiers
      );
      observationTableStructure.activeTimeColumnNameIdOrIndex = undefined;
      observationTableStructure.columns = observationTableStructure.columns.concat(
        newColumns
      );
      observationTableStructure.idColumnNames = item._idColumnNames;
      if (item.showFeaturesAtAllTimes) {
        // Set finalEndJulianDate so that adding new null-valued feature rows doesn't mess with the final date calculations.
        // To do this, we need to set the active time column, so that finishJulianDates is calculated.
        observationTableStructure.setActiveTimeColumn(
          item.tableStyle.timeColumn
        );
        var finishDates = observationTableStructure.finishJulianDates.map(d =>
          Number(JulianDate.toDate(d))
        );
        // I thought we'd need to unset the time column, because we're about to change the columns again, and there can be interactions
        // - but it works without unsetting it.
        // observationTableStructure.setActiveTimeColumn(undefined);
        observationTableStructure.finalEndJulianDate = JulianDate.fromDate(
          new Date(Math.max.apply(null, finishDates))
        );
        observationTableStructure.columns = observationTableStructure.getColumnsWithFeatureRowsAtStartAndEndDates(
          "date",
          "value"
        );
      }
      if (!defined(item._tableStructure)) {
        observationTableStructure.name = item.name;
        item.initializeFromTableStructure(observationTableStructure);
      } else {
        observationTableStructure.setActiveTimeColumn(
          item.tableStyle.timeColumn
        );
        // Moving this isActive statement earlier stops all points appearing on the map/globe.
        observationTableStructure.columns.filter(
          column => column.id === "value"
        )[0].isActive = true;
        item._tableStructure.columns = observationTableStructure.columns; // TODO: doesn't do anything.
        // Force the timeline (terria.clock) to update by toggling "isShown" (see CatalogItem's isShownChanged).
        if (item.isShown) {
          item.isShown = false;
          item.isShown = true;
        }
        // Changing the columns triggers a knockout change of the TableDataSource that uses this table.
      }
    });
}
function loadObservationData ( item ) { if ( ! item . _featureMapping ) { return ; } var featuresOfInterest = Object . keys ( item . _featureMapping ) ; // Are there too many features to load observations (or we've been asked not to try)? if ( ! item . tryToLoadObservationData || featuresOfInterest . length > item . requestSizeLimit * item . requestNumberLimit ) { // MODE 1. Do not load observation data for the features. // Just show where the features are, and when the feature info panel is opened, then load the feature's observation data // (via the 'chart' column in _tableStructure, which generates a call to item.loadIntoTableStructure). var tableStructure = item . _tableStructure ; if ( ! defined ( tableStructure ) ) { tableStructure = new TableStructure ( item . name ) ; } var columns = createColumnsFromMapping ( item , tableStructure ) ; tableStructure . columns = columns ; if ( ! defined ( item . _tableStructure ) ) { item . _tableStyle . dataVariable = null ; // Turn off the legend and give all the points a single colour. item . initializeFromTableStructure ( tableStructure ) ; } else { item . _tableStructure . columns = tableStructure . columns ; } return when ( ) ; } // MODE 2. Create a big time-varying tableStructure with all the observations for all the features. // In this mode, the feature info panel shows a chart through as a standard time-series, like it would for any time-varying csv. return item . loadIntoTableStructure ( featuresOfInterest ) . then ( function ( observationTableStructure ) { if ( ! defined ( observationTableStructure ) || observationTableStructure . columns [ 0 ] . values . length === 0 ) { throw new TerriaError ( { sender : item , title : item . name , message : "The Sensor Observation Service did not return any features matching your query." } ) ; } // Add the extra columns from the mapping into the table. var identifiers = observationTableStructure . getColumnWithName ( "identifier" ) . values ; var newColumns = createColumnsFromMapping ( item , observationTableStructure , identifiers ) ; observationTableStructure . activeTimeColumnNameIdOrIndex = undefined ; observationTableStructure . columns = observationTableStructure . columns . concat ( newColumns ) ; observationTableStructure . idColumnNames = item . _idColumnNames ; if ( item . showFeaturesAtAllTimes ) { // Set finalEndJulianDate so that adding new null-valued feature rows doesn't mess with the final date calculations. // To do this, we need to set the active time column, so that finishJulianDates is calculated. observationTableStructure . setActiveTimeColumn ( item . tableStyle . timeColumn ) ; var finishDates = observationTableStructure . finishJulianDates . map ( d => Number ( JulianDate . toDate ( d ) ) ) ; // I thought we'd need to unset the time column, because we're about to change the columns again, and there can be interactions // - but it works without unsetting it. // observationTableStructure.setActiveTimeColumn(undefined); observationTableStructure . finalEndJulianDate = JulianDate . fromDate ( new Date ( Math . max . apply ( null , finishDates ) ) ) ; observationTableStructure . columns = observationTableStructure . getColumnsWithFeatureRowsAtStartAndEndDates ( "date" , "value" ) ; } if ( ! defined ( item . _tableStructure ) ) { observationTableStructure . name = item . name ; item . initializeFromTableStructure ( observationTableStructure ) ; } else { observationTableStructure . setActiveTimeColumn ( item . tableStyle . timeColumn ) ; // Moving this isActive statement earlier stops all points appearing on the map/globe. observationTableStructure . columns . filter ( column => column . id === "value" ) [ 0 ] . isActive = true ; item . _tableStructure . columns = observationTableStructure . columns ; // TODO: doesn't do anything. // Force the timeline (terria.clock) to update by toggling "isShown" (see CatalogItem's isShownChanged). if ( item . isShown ) { item . isShown = false ; item . isShown = true ; } // Changing the columns triggers a knockout change of the TableDataSource that uses this table. } } ) ; }
Given the features already loaded into item._featureMap, this loads the observations according to the user-selected concepts,
and puts them into item._tableStructure.
If there are too many features, fall back to a tableStructure without the observation data.
@param  {SensorObservationServiceCatalogItem} item This catalog item.
@return {Promise} A promise which, when it resolves, sets item._tableStructure.
@private
Given the features already loaded into item . _featureMap this loads the observations according to the user - selected concepts and puts them into item . _tableStructure . If there are too many features fall back to a tableStructure without the observation data .