function IFactorLayersHandler(A){this.stormCenter=A;this.visibilitiesHandler=null;this.stylesHandler=null;this.shapeLayerNames=new Array();this.shapeLayers=new Object();this.tileLayerNames=new Array();this.tileLayers=new Object();this.allLayerNames=new Array();this.allLayers=new Object();this.layerPreviouslyLoaded=new Object();this.layerCachedDataSourceDirectories=new Object()}IFactorLayersHandler.configLayersDefinition=[];IFactorLayersHandler.prototype.loadLayersConfiguration=function(D,E){var B;this.visibilitiesHandler=D;this.stylesHandler=E;for(B=0;B<IFactorLayersHandler.configLayersDefinition.length;B++){var C=IFactorLayersHandler.configLayersDefinition[B];layer=new IFactorLayer(C);var A=layer.layerName;if(layer.isShapeLayer()){this.shapeLayerNames[this.shapeLayerNames.length]=A;this.shapeLayers[A]=layer}else{if(layer.isTileLayer()){this.tileLayerNames[this.tileLayerNames.length]=A;this.tileLayers[A]=layer}else{continue}}this.allLayerNames[this.allLayerNames.length]=A;this.allLayers[A]=layer}};IFactorLayersHandler.prototype.getProperty=function(A){return this[A]};IFactorLayersHandler.prototype.setProperty=function(A,B){if(A in this){this[A]=B;return B}else{return undefined}};IFactorLayersHandler.prototype.getLayer=function(A){return this.allLayers[A]};IFactorLayersHandler.prototype.getShapeLayer=function(A){return this.shapeLayers[A]};IFactorLayersHandler.prototype.getTileLayer=function(A){return this.tileLayers[A]};IFactorLayersHandler.prototype.isShapeLayer=function(A){var B=this.allLayers[A];if(B!=null){return B.isShapeLayer()}return false};IFactorLayersHandler.prototype.isTileLayer=function(A){var B=this.allLayers[A];if(B!=null){return B.isTileLayer()}return false};IFactorLayersHandler.prototype.setForceReloadLayer=function(A,B){this.setForceReloadLayers([A],B)};IFactorLayersHandler.prototype.setForceCleanLayer=function(A,B){this.setForceCleanLayers([A],B)};IFactorLayersHandler.prototype.setForceReloadLayers=function(A,B){this.setForceLayers(A,B,"forceReload")};IFactorLayersHandler.prototype.setForceCleanLayers=function(A,B){this.setForceLayers(A,B,"forceClean")};IFactorLayersHandler.prototype.setForceLayers=function(A,F,B){if(F==null){F=false}var E;for(E=0;E<A.length;E++){var C=A[E];var D=this.allLayers[C];if(D!=null){D.setProperty(B,F)}}};IFactorLayersHandler.prototype.setForceReloadForLayersWithEvents=function(A,B){this.setForceForLayersWithEvents(A,B,"forceReload")};IFactorLayersHandler.prototype.setForceCleanForLayersWithEvents=function(A,B){this.setForceForLayersWithEvents(A,B,"forceClean")};IFactorLayersHandler.prototype.setForceForLayersWithEvents=function(I,G,F){if(G==null){G=false}var B;var A;var H=this.allLayerNames;for(B=0;B<H.length;B++){var E=H[B];var D=this.allLayers[E];for(A=0;A<I.length;A++){var C=I[A];if(D.layerRespondsToEvent(C)){D.setProperty(F,G)}}}};IFactorLayersHandler.prototype.getForceReloadLayer=function(A){return this.getForceLayer(A,"forceReload")};IFactorLayersHandler.prototype.getForceCleanLayer=function(A){return this.getForceLayer(A,"forceClean")};IFactorLayersHandler.prototype.getForceLayer=function(B,A){var C=this.getLayer(B);if(C!=null){var D=C.getProperty(A);if(D!=null){return D}}return false};IFactorLayersHandler.prototype.isLayerVisibleAtZoomLevel=function(B,D){var A=false;var C=this.allLayers[B];if(C!=null){A=C.isLayerVisibleAtZoomLevel(D)}return A};IFactorLayersHandler.prototype.updateTileLayers=function(){var E=false;var A=null;var A=null;var D=this.tileLayerNames;for(var C=0;C<D.length;C++){var B=D[C];if(this.getForceReloadLayer(B)){this.removeTileLayer(B);this.setForceReloadLayer(B,false);this.addTileLayer(B)}}};IFactorLayersHandler.prototype.addTileLayer=function(F){var E=this.getTileLayer(F);if(E!=null){var C;var H=E.getLayerDefinitionProperty("source");for(C=0;C<H.length;C++){var G=H[C];var B=this.getSourceTilesDirectory(G);if(B!=null){var A=B;var I=new VETileSourceSpecification(A,B+E.fileSufix);this.setTileSourceSpecification(E,I,G.bounds);E.addPhysicalLayer(A,I,I.Bounds,[B]);var D=this.visibilitiesHandler.isLayerVisible(F);this.stormCenter.map.AddTileLayer(I,D);if(D){this.stormCenter.map.ShowTileLayer(A);this.stormCenter.map.ShowTileLayer(A)}else{this.stormCenter.map.HideTileLayer(A);this.stormCenter.map.HideTileLayer(A)}}}}};IFactorLayersHandler.prototype.getFullDataDirectory=function(E){var G=E.data_directory;if(iFactor.common.valueIsTypeOf(G,"String")){return G}else{var A=null;for(var D=0;D<G.length;D++){var F=G[D];for(var C in F){var B=F[C];if(A==null){A=""}else{A+="/"}if(C=="path"){A+=B}else{if(C=="datamonitor_variable"){A+=this.stormCenter.dataMonitor.getVariableValue(B)}}}}return A}};IFactorLayersHandler.prototype.getFullPathSourceDirectories=function(M,G){var J=new Array();if(M!=null){if(G==null){G=false}var F=this.getFullDataDirectory(M);if(F==null){F==""}var A=null;var H=null;var K=M.metadata;if(K!=null){if(iFactor.common.valueIsTypeOf(K,"String")){A=K;H="directory"}else{A=K.file;if(A==null){A="metadata.xml"}H=K.field;if(H==null){H="directory"}}var I=iFactor.common.createXMLRequest();var E=null;if(F==""||F=="/"){E=F+A}else{E=F+"/"+A}E=E+iFactor.common.uniqueRequestTag(true);I.open("GET",E,false);I.send(null);if((I.readyState==4)&&(I.status!=404)){var L=I.responseXML;var B=L.getElementsByTagName(H)[0];var D=iFactor.common.getXMLNodeValue(B);var C=null;if(F==""||F=="/"){C=F+D}else{C=F+"/"+D}J.push(C);if(G){return J}}}else{J.push(F)}}return J};IFactorLayersHandler.prototype.getSourceTilesDirectory=function(A){if(A!=null){var B=this.getFullPathSourceDirectories(A,true);if(B.length==0){return null}else{return B[0]}}return null};IFactorLayersHandler.prototype.setTileSourceSpecification=function(D,I,C){var H=D.getLayerDefinitionProperty("min_zoom");if(H!=null&&H!=""){I.MinZoomLevel=H}var B=D.getLayerDefinitionProperty("max_zoom");if(B!=null&&B!=""){I.MaxZoomLevel=B}var G=D.getLayerDefinitionProperty("zindex");if(G!=null&&G!=""){I.ZIndex=G}var A=null;if(C!=null&&C!=""&&C!=[]){A=C}else{A=D.getProperty("bounds")}if(A!=null&&A!=""&&A!=[]){I.Bounds=A}var E=D.getLayerDefinitionProperty("opacity");if(E!=null&&E!=""){var F=null;if(/MSIE (\d+\.\d+);/.test(navigator.userAgent)){F=new Number(RegExp.$1)}if(F!=6){I.Opacity=E}}};IFactorLayersHandler.prototype.removeTileLayer=function(A){var B=this.getTileLayer(A);if(B!=null){for(physicalTileLayerName in B.physicalLayers){this.stormCenter.map.DeleteTileLayer(physicalTileLayerName)}B.physicalLayers=new Object()}};IFactorLayersHandler.prototype.updateVectorLayers=function(D,C,E){var B;for(B=0;B<this.shapeLayerNames.length;B++){var A=this.shapeLayerNames[B];this.readIfNecessaryVectorLayer(A,D,C,E)}};IFactorLayersHandler.prototype.readIfNecessaryVectorLayer=function(I,N,P,L){var H=this.shapeLayers[I];if(H!=null){var G=this.visibilitiesHandler.isLayerVisible(I);if(!G){if(this.layerNeedToBeReloaded(H,N,P,L)){this.setForceReloadLayer(I,true)}else{if(this.layerNeedToBeCleaned(H,N,P,L)){this.setForceCleanLayer(I,true)}}if((this.getForceReloadLayer(I)||this.getForceCleanLayer(I))&&(!H.layerEmpty)){H.deleteAllPhysicalLayers(this.stormCenter.map)}return }if(!H.layerBoundsOverlaps(this.stormCenter.getStoredMapBounds())){return }var C=this.getForceReloadLayer(I);var O=this.getForceCleanLayer(I);this.setForceReloadLayer(I,false);this.setForceCleanLayer(I,false);if(C||O||this.layerNeedToBeUpdated(H,N,P,L)){var D=false;var F=this.layerPreviouslyLoaded[I];if(F!=true){D=true;this.layerCachedDataSourceDirectories[I]=new Array()}this.layerPreviouslyLoaded[I]=true;var B=this.layerNeedToBeReloaded(H,N,P,L);var A=this.layerNeedToBeCleaned(H,N,P,L);if(C||O||B||A){H.deleteAllPhysicalLayers(this.stormCenter.map);if((C||B)&&F==true){D=true;this.layerCachedDataSourceDirectories[I]=new Array()}}if(!H.useMultiplePhysicalLayers){var M=H.physicalLayers[I];if(M==null){M=H.createAndAddNewPhysicalLayer(I,null)}}var E;var K=H.getLayerDefinitionProperty("source");for(E=0;E<K.length;E++){var J=K[E];if(J!=null){this.readVectorLayer(H,J,G,D)}}}}};IFactorLayersHandler.prototype.readVectorLayer=function(C,D,A,B){if(B){this.getDataSourceDirectories(C,D)}if(!IFactorLayer.boundsOverlaps(this.stormCenter.getStoredMapBounds(),D.bounds)){return }this.doReadVectorLayer(C,D,A,B)};IFactorLayersHandler.prototype.getDataSourceDirectories=function(B,C){var A=B.layerName;var D=this.getFullPathSourceDirectories(C);if(D!=null){this.layerCachedDataSourceDirectories[A]=D}};IFactorLayersHandler.prototype.doReadVectorLayer=function(D,F,C,A){var E=D.layerName;var H=this.layerCachedDataSourceDirectories[E];if(H!=null){var G=D.type;var B;for(B=0;B<H.length;B++){var I=H[B];if(G=="indexvectorlayer"){this.doReadIndexVectorLayer(D,I,C)}else{if(G=="simplevectorlayer"){this.doReadSimpleVectorLayer(D,I,F.files,C)}}}}};IFactorLayersHandler.prototype.doReadIndexVectorLayer=function(E,I,D){var C;var B=null;var A=this.stormCenter.getStoredZoom();var H=E.getIndicesLevelForZoomLevel(A);var F=E.getEnlargingFactorForZoomLevel(A);var G=this.stormCenter.getMapSpatialIndices(H,F);for(C=0;C<G.length;C++){B=I+"/"+G[C]+E.fileSufix;this.importVectorLayer(B,E,D)}};IFactorLayersHandler.prototype.doReadSimpleVectorLayer=function(C,E,F,A){if(F!=null&&F!=""){var B;for(B=0;B<F.length;B++){var D=F[B];var G;if(iFactor.common.valueIsTypeOf(D,"String")){G=D}else{G=this[D.custom]()}geoRssName=E+"/"+G;this.importVectorLayer(geoRssName,C,A)}}};IFactorLayersHandler.prototype.importVectorLayer=function(C,D,A){var F;if(D.useMultiplePhysicalLayers){F=C}else{F=D.layerName}var B=D.physicalLayers[F];if(B==null){if(D.useMultiplePhysicalLayers){D.physicalLayers[F]=true}else{B=D.createAndAddNewPhysicalLayer(F,null)}}else{if(D.useMultiplePhysicalLayers){return }else{if(B.physicalDataSources[C]==true){return }}}var E=null;if(!D.useMultiplePhysicalLayers){B.physicalDataSources[C]=true;E=B.physicalVELayer}else{E=new VEShapeLayer();E.SetTitle(D.layerName)}this.doImportVectorLayer(null,C,D,F,A,E)};IFactorLayersHandler.prototype.doImportVectorLayer=function(B,C,D,G,A,E){if(!A){E.Hide()}if(iFactor.common.config.disable_map_msg_box==true||iFactor.common.config.disable_map_msg_box=="true"){this.stormCenter.map.ShowMessageBox=false}var F=D.loadCraftily;if(!F){this.doImportVectorLayerAutomatically(C,D,G,E)}else{this.doImportVectorLayerCraftily(C,D,G,E)}};IFactorLayersHandler.prototype.doImportVectorLayerAutomatically=function(A,B,F,D){var C=new VEShapeSourceSpecification(VEDataType.GeoRSS,A+iFactor.common.uniqueRequestTag(true),D);var E=this;this.stormCenter.map.ImportShapeLayerData(C,function(G){E.vectorLayerLoaded(G,B,F,A)},false)};IFactorLayersHandler.prototype.doImportVectorLayerCraftily=function(C,D,G,E){var A=C+iFactor.common.uniqueRequestTag(true);A=A.fixUrlSeparator();var F=this;var B=iFactor.common.createXMLRequest();B.onreadystatechange=function(){F.doLoadShapesCraftily(B,C,D,G,E)};B.open("GET",A,true);B.send(null)};IFactorLayersHandler.prototype.createShape=function(D,E,F,C,B){var A=new VEShape(D,E);if(F!=null){A.SetTitle(F)}if(C!=null){A.SetDescription(C)}if(B!=null){A.IconId=B}return A};IFactorLayersHandler.prototype.doLoadShapesCraftily=function(D,C,Z,I,a){if((D.readyState==4)&&(D.status!=404)){var B=D.responseXML;var G=B.getElementsByTagName("item");var J=false;for(var S=0;S<G.length;S++){itemNode=G[S];var N=iFactor.common.getXMLChildNamed(itemNode,"title");var E=iFactor.common.getXMLChildNamed(itemNode,"description");var Y=iFactor.common.getXMLChildNamed(itemNode,"icon");var b=null;var Q=null;var U=null;if(N!=null){b=iFactor.common.getXMLNodeValue(N)}if(E!=null){Q=iFactor.common.getXMLNodeValue(E)}if(Y!=null){U=iFactor.common.getXMLNodeValue(Y)}var V=false;var L=new Array();var H=null;var M=new Array();var P;var K=iFactor.common.getXMLChildrenNamed(itemNode,"georss:polygon");var A=iFactor.common.getXMLChildrenNamed(itemNode,"georss:line");var F=iFactor.common.getXMLChildrenNamed(itemNode,"georss:point");if(K.length!=0&&A.length!=0){V=true;J=true}for(P=0;P<K.length;P++){var O=K[P];var X;if(V){X=VEShapeType.Polyline}else{X=VEShapeType.Polygon}var R=this.getCoordinateArray(iFactor.common.getXMLNodeValue(O));var W=this.createShape(X,R,b,Q,U);a.AddShape(W);if(V){if(H==null){H=R[0];L=L.concat(R,H)}else{L=L.concat(R,R[0],H)}}}for(P=0;P<A.length;P++){var O=A[P];var X=VEShapeType.Polyline;var R=this.getCoordinateArray(iFactor.common.getXMLNodeValue(O));var W=this.createShape(X,R,b,Q,U);a.AddShape(W);if(V){if(H==null){H=R[0];L=L.concat(R,H)}else{L=L.concat(R,R[0],H)}}}for(P=0;P<F.length;P++){var O=F[P];var X=VEShapeType.Pushpin;var R=this.getCoordinateArray(iFactor.common.getXMLNodeValue(O));var W=this.createShape(X,R,b,Q,U);a.AddShape(W)}if(V&&L.length!=0){var W=this.createShape(VEShapeType.Polygon,L,b,Q,U);a.AddShape(W);W.SetLineColor(new VEColor(0,0,0,0))}try{this.stormCenter.map.AddShapeLayer(a)}catch(T){}}this.vectorLayerLoaded(a,Z,I,C,J)}};IFactorLayersHandler.prototype.getCoordinateArray=function(B){var G=new Array();var A=B.replace(/^\s+|\s+$/g,"");if(A==""){return G}var C=A.split(" ");var F;var D;for(var E=0;E<C.length/2;E++){F=parseFloat(C[E*2]);D=parseFloat(C[E*2+1]);G.push(new VELatLong(F,D))}return G};IFactorLayersHandler.prototype.vectorLayerLoaded=function(S,Q,F,E,H){if(Q!=null){var D=null;var L=null;var G=null;var K=null;var J;if(Q.useMultiplePhysicalLayers){var E=F;var B=null;J=Q.addPhysicalLayer(F,S,B,[F])}else{J=Q.physicalLayers[F]}J.bounds=[S.GetBoundingRectangle()];var R=Q.layerName;var P=S.GetShapeCount();D=Q.getLayerDefinitionProperty("min_zoom");L=Q.getLayerDefinitionProperty("max_zoom");var G=Q.getLayerDefinitionProperty("zindex_icon");var K=Q.getLayerDefinitionProperty("zindex_shape");if(G==""){G=null}if(K==""){K=null}var M;for(M=0;M<P;M++){var I=S.GetShapeByIndex(M);if(I.cached==true){continue}if(Q.hideInfoBox==true){I.hideInfoBox=true}this.stylesHandler.setShapeStyle(I,R,H);var A=this.getExtraInfoBox(I,R);if(A!=null){var N=I.GetDescription();I.SetDescription(I.GetDescription()+A)}try{if(G!=null||K!=null){I.SetZIndex(G,K)}}catch(O){}I.cached=true}if(Q.getLayerDefinitionProperty("best_zoom_in_load")&&P>0){var C=S.GetBoundingRectangle();this.stormCenter.map.SetMapView(C)}}};IFactorLayersHandler.prototype.getExtraInfoBox=function(B,A){var C=null;var D=B.IconId;D=D.split("/");D=D[D.length-1];D=D.split(".")[0];C=iFactor.common.config[D+"_extra_infobox"];if(C==null){C=iFactor.common.config[A+"_extra_infobox"]}return C};IFactorLayersHandler.prototype.layerNeedToBeUpdated=function(B,E,D,F){var C=B.type;var A=B.layerName;if(this.layerPreviouslyLoaded[A]==true||this.layerPreviouslyLoaded[A]!=true&&(B.layerRespondsToEvent("OnMapLoad")||B.layerRespondsToEvent("OnPan")&&D||B.layerRespondsToEvent("OnZoom")&&E&&!F)){if(this.layerPreviouslyLoaded[A]==true&&B.layerOnlyRespondsToEvent("OnMapLoad")){return false}else{return true}}else{return false}};IFactorLayersHandler.prototype.layerNeedToBeReloaded=function(A,D,C,E){var B=A.type;if(B=="simplevectorlayer"){if(A.layerRespondsToEvent("OnZoom")&&D&&!E){return true}else{if(A.layerRespondsToEvent("OnPan")&&C){return true}}}return false};IFactorLayersHandler.prototype.layerNeedToBeCleaned=function(A,D,C,E){var B=A.type;if(B=="indexvectorlayer"&&D){return true}return false};
