logo CNRS

ForeFire

logo UNIV
  1 
  2 if (typeof(Firesim) != 'undefined')
  3 {
  4     /**
  5      * Stores the results of all states into a TimeMapDataset
  6      * @param {TimeMap} timemap
  7      * @param {TimeMapDataset} dataset
  8      */
  9     Firesim.prototype.getAllStatesInTimemap = function(timemap, dataset) {
 10         this.getStateInTimemap(timemap, dataset, "all");
 11     };
 12 
 13     /**
 14      * Starts a simulation and displays the results into a TimeMapDataset
 15      * @see Firesim#setNumberOfSteps
 16      * @see Firesim#setOutputInterval
 17      * @param {TimeMap} timemap
 18      * @param {TimeMapDataset} dataset
 19      */
 20     Firesim.prototype.engageInTimemap = function(timemap, dataset) {
 21         var obj = this;
 22         var step = 0;
 23         var index = 0;
 24 
 25         setTimeout(function() {
 26             var stepCallInterval = setInterval(function() {
 27                 if (index != obj.getLastAvailable())
 28                 {
 29                     index = obj.getLastStateInTimemap(timemap, dataset);
 30                     obj.step();
 31                     step++;
 32                 }
 33 
 34                 if (step >= obj.getNumberOfSteps())
 35                     clearInterval(stepCallInterval);
 36             }, obj.getOutputInterval());
 37         }, 2000);
 38     };
 39 
 40     /**
 41      * Stores the results of the last state into a TimeMapDataset
 42      * @param {type} timemap
 43      * @param {type} dataset
 44      * @returns {Number} Index of the last processed state
 45      */
 46     Firesim.prototype.getLastStateInTimemap = function(timemap, dataset) {
 47         var lastAvailable = this.getLastAvailable();
 48         this.getStateInTimemap(timemap, dataset, lastAvailable);
 49         return lastAvailable;
 50     };
 51 
 52     /**
 53      * Stores the results of a specific state into a TimeMapDataset
 54      * @param {TimeMap} timemap
 55      * @param {TimeMapDataset} dataset
 56      * @param {Number} indice Index of the specific state
 57      */
 58     Firesim.prototype.getStateInTimemap = function(timemap, dataset, indice) {
 59         if (typeof(Firesim.noFillTheme) == "undefined")
 60         {
 61             Firesim.noFillTheme = TimeMapTheme.create("red", { 
 62                 fillColor: "none"
 63             });
 64         }
 65     
 66         this.getState("JSON", indice, function(data){
 67             var json = JSON.parse(data);
 68             var fronts = json["fronts"];
 69             var lastItem = null;
 70             
 71             for (var i = 0; i < fronts.length; i++)
 72             {
 73                 var area = fronts[i]["area"];
 74                 var date = fronts[i]["date"];
 75                 var coords = fronts[i]["coordinates"];
 76                 
 77                 var itemOpts = {
 78                     title: area,
 79                     start: date,
 80                     polygon: Firesim.coordsFormat(coords),
 81                     options: {
 82                         theme: Firesim.noFillTheme
 83                     }
 84                 };
 85                 
 86                 lastItem = dataset.loadItem(itemOpts);
 87             }
 88             
 89             if (lastItem != null)
 90             {
 91                 var newdate = lastItem.getStart();
 92                 var tiNDate = newdate.getTime();
 93                 tiNDate += 600000;
 94                 var scrollDate = new Date();
 95                 scrollDate.setTime(tiNDate);
 96                 timemap.scrollToDate(scrollDate, false, true);
 97                 timemap.timeline.layout();
 98             }
 99         });
100     };
101 }
102