function UpdateHelper(thresholdRange){
this._screens=[];
if(typeof thresholdRange!="undefined"){
this._thresholdRange=thresholdRange;}else{
this._thresholdRange=.75;}}
UpdateHelper.prototype.reset=function(){
this._screens=[];}
UpdateHelper.prototype.addScreen=function(gBounds,zoomLevel,isPruned){
if(gBounds.isEmpty())return;
var mapScreen=new MapScreen();
mapScreen.bounds=gBounds;
mapScreen.pruned=isPruned;
mapScreen.zoomLevel=zoomLevel;
this._screens.push(mapScreen);}
UpdateHelper.prototype.needsUpdate=function(gBounds,zoomLevel){
var window=new MapWindow(gBounds,this._thresholdRange);
if(this._screens.length==0){
return "NOTINITIALIZED";}
if(isDefined(this._limitPages)&&this._limitPages<this._screens.length){
return "ERASE";}
this._screens.sort(orderByZoomLevel);
if(this._screens[0].zoomLevel>zoomLevel+1)return "ERASE";
for(var i=0;i<this._screens.length;i++){
window.blockout(this._screens[i].bounds);
if(window.isCovered()){
if(this._screens[i].pruned){
if(this._screens[i].zoomLevel<zoomLevel){
return "UPDATE_PRUNED";}else{
return "NOUPDATE_PRUNED";}}
return "NOUPDATE";}}
return "UPDATE";}
function MapWindow(gBounds){
this.bounds=gBounds;
this.ne=gBounds.getNorthEast();
this.sw=gBounds.getSouthWest();
this.nw=new GLatLng(this.ne.lat(),this.sw.lng());
this.se=new GLatLng(this.sw.lat(),this.ne.lng());}
MapWindow.prototype.blockout=function(gBounds){
if(!gBounds.intersects(this.bounds))return;
var coveringLayer=new MapWindow(gBounds);
if(gBounds.contains(this.ne)){
this.ne=coveringLayer.sw;}
if(gBounds.contains(this.nw)){
this.nw=coveringLayer.se;}
if(gBounds.contains(this.se)){
this.se=coveringLayer.nw;}
if(gBounds.contains(this.sw)){
this.sw=coveringLayer.ne;}}
MapWindow.prototype.isCovered=function(){
if(this.nw.lng()<this.se.lng()||this.nw.lat()>this.se.lat())return false;
if(this.sw.lng()<this.ne.lng()||this.sw.lat()<this.ne.lat())return false;
return true;}
function orderByZoomLevel(mapUpdateA,mapUpdateB){
return mapUpdateB.zoomLevel-mapUpdateA.zoomLevel;}
function MapScreen(){};
