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];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+"/%4"+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.getSourceTilesDirectory=function(D){if(D!=null){var G=D.data_directory;var E=iFactor.common.createXMLRequest();var A=G+"/metadata.xml";A=A+iFactor.common.uniqueRequestTag(true);E.open("GET",A,false);E.send(null);if((E.readyState==4)&&(E.status!=404)){var F=E.responseXML;var C=F.getElementsByTagName("directory")[0];var B=iFactor.common.getXMLNodeValue(C);return G+"/"+B}}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 Object()}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 Object()}}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(F,H){var K=H.data_directory;if(K!=null&&K!=""){requestStr=K+"/metadata.xml";requestStr=requestStr+iFactor.common.uniqueRequestTag(true);var C=iFactor.common.createXMLRequest();C.open("GET",requestStr,false);C.send(null);if((C.readyState==4)&&(C.status!=404)){var J=C.responseXML;var G=F.layerName;var I=this.layerCachedDataSourceDirectories[G][K]=new Array();var A=J.getElementsByTagName("directory");var E;for(E=0;E<A.length;E++){var B=A[E];var D=iFactor.common.getXMLNodeValue(B);I.push(D)}}}};IFactorLayersHandler.prototype.doReadVectorLayer=function(E,G,D,A){var J=G.data_directory;if(J!=null&&J!=""){var F=E.layerName;var I=this.layerCachedDataSourceDirectories[F][J];if(I!=null){var H=E.type;var K;var C;for(C=0;C<I.length;C++){var B=I[C];if(B==""){K=J}else{K=J+"/"+B}if(H=="indexvectorlayer"){this.doReadIndexVectorLayer(E,K,D)}else{if(H=="simplevectorlayer"){this.doReadSimpleVectorLayer(E,K,G.files,D)}}}}}};IFactorLayersHandler.prototype.doReadIndexVectorLayer=function(D,E,A){var C;var B=null;var H=this.stormCenter.getStoredZoom();var G=D.getIndicesLevelForZoomLevel(H);var F=this.stormCenter.getMapSpatialIndices(G);for(C=0;C<F.length;C++){B=E+"/"+F[C]+D.fileSufix;this.importVectorLayer(B,D,A)}};IFactorLayersHandler.prototype.doReadSimpleVectorLayer=function(C,D,E,A){if(E!=null&&E!=""){var B;for(B=0;B<E.length;B++){geoRssName=D+"/"+E[B];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(E,I,G,B,H){if(I!=null){var M=null;var A=null;var N=null;var L=null;var K;if(I.useMultiplePhysicalLayers){var B=G;var D=null;K=I.addPhysicalLayer(G,E,D,[G])}else{K=I.physicalLayers[G]}K.bounds=[E.GetBoundingRectangle()];var F=I.layerName;var P=E.GetShapeCount();M=I.getLayerDefinitionProperty("min_zoom");A=I.getLayerDefinitionProperty("max_zoom");var N=I.getLayerDefinitionProperty("zindex_icon");var L=I.getLayerDefinitionProperty("zindex_shape");if(N==""){N=null}if(L==""){L=null}var C;for(C=0;C<P;C++){var O=E.GetShapeByIndex(C);this.stylesHandler.setShapeStyle(O,F,H);try{if(N!=null||L!=null){O.SetZIndex(N,L)}}catch(J){}}}};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};
