History.js
	
	
Summary
	
		No overview generated for 'History.js'
	
    
    
 
        
mapbuilder.loadScript(baseDir+"/tool/ToolBase.js");
function History(toolNode, model) {
  ToolBase.apply(this, new Array(toolNode, model));
  
	this.init = function(objRef) {
		objRef.model.active = -1;
    objRef.model.historyList = new Array();
    objRef.add(objRef);
  }
  
  this.add = function(objRef) {
    if (objRef.model.active!=null) {
      var place = objRef.model.active;
      var list = objRef.model.historyList;
      var center = objRef.targetModel.map.getExtent().getCenterLonLat();
      var scale = objRef.targetModel.map.getScale()-1;
      if (place > -1) {
        if (center.toString() == list[place].center.toString() &&
            scale == list[place].scale) {
          return;
        }
      }
      var newExtent = new Object({center:center, scale:scale});
      if( place==(list.length-1)) { //If we are already at the end of the list add a new item
        list.push(newExtent); 
        place = place+1; 
      }
      else { //If we are somewhere in the middle of the list clear the rest of the list and add a new item
        place = place+1;
        list = list.slice(0,place);
        list.push(newExtent);
      }
      objRef.model.active = place;
      objRef.model.historyList = list;
    }
  }
  
  this.back = function(objRef){
    var place = objRef.model.active;
    if(place<1) {
      objRef.model.previousExtent = null;
      alert(mbGetMessage("cantGoBack"));
    }
    else {
      place = place -1;
      objRef.model.active = place;
      objRef.model.previousExtent = objRef.model.historyList[place];
    }
  }
  
  this.forward = function(objRef) {
    var place = objRef.model.active;
    if(place<(objRef.model.historyList.length-1)) {
      place = place +1;
      objRef.model.active = place;
      objRef.model.nextExtent = objRef.model.historyList[place];
    }
    else {
      objRef.model.nextExtent = null;
      alert(mbGetMessage("cantGoForward"));
    }
  }
  
  this.stop = function(objRef) {
    objRef.model.removeListener("bbox",objRef.add, objRef);
  }
  
  
  this.start = function(objRef) {
    objRef.model.addListener("bbox",objRef.add, objRef);
  }
  
  this.initReset = function(objRef) {
    objRef.targetModel.addListener("bbox", objRef.add, objRef);
    objRef.targetModel.addListener("loadModel", objRef.init, objRef);
	}
	this.model.addListener("historyBack", this.back, this);
	this.model.addListener("historyForward", this.forward, this);
	this.model.addListener("historyStart", this.start, this);
	this.model.addListener("historyStop", this.stop, this);
	this.model.addListener("init", this.initReset, this);
}
	
Documentation generated by 
JSDoc on Tue Aug 21 08:12:28 2007