WebGIS={version:"1.2.0",MapAction:{},OpenLayers:{Control:{},Layer:{}}};(function(){var A=[];WebGIS.MapAction=function(D){var E=D.map;WebGIS.MapAction.superclass.constructor.call(this,D);if(D.cls==="x-btn-text-icon"){D.text=D.text||this.titleText}D.tooltip=D.tooltip||this.tooltipText;var B=D.olcontrol;if(!B){return }var C=function(F,H){for(var G in A){var I=A[G];if(I.deactivate){I.deactivate()}}this.activate();if(F.toggle){F.toggle(true)}};E.addControl(B);A.push(B);D.handler=C;D.scope=B;D.enableToggle=true;D.toggleGroup="WebGIS.MapAction"};Ext.extend(WebGIS.MapAction,Ext.Action)})();WebGIS.MapAction.ZoomInBox=function(A){A.iconCls="webgis-mapaction-zoominbox";A.enableToggle=true;A.toggleGroup="WebGIS.MapAction";A.olcontrol=new OpenLayers.Control.ZoomBox();WebGIS.MapAction.ZoomInBox.superclass.constructor.call(this,A)};Ext.extend(WebGIS.MapAction.ZoomInBox,WebGIS.MapAction);WebGIS.MapAction.ZoomOutBox=function(A){A.iconCls="webgis-mapaction-zoomoutbox";A.olcontrol=new OpenLayers.Control.ZoomBox({out:true});WebGIS.MapAction.ZoomOutBox.superclass.constructor.call(this,A)};Ext.extend(WebGIS.MapAction.ZoomOutBox,WebGIS.MapAction);WebGIS.MapAction.ZoomIn=function(A){A.iconCls="webgis-mapaction-zoomin";A.handler=function(){this.map.zoomIn()};WebGIS.MapAction.ZoomIn.superclass.constructor.call(this,A)};Ext.extend(WebGIS.MapAction.ZoomIn,WebGIS.MapAction);WebGIS.MapAction.ZoomOut=function(A){A.iconCls="webgis-mapaction-zoomout";A.handler=function(){this.map.zoomOut()};WebGIS.MapAction.ZoomOut.superclass.constructor.call(this,A)};Ext.extend(WebGIS.MapAction.ZoomOut,WebGIS.MapAction);WebGIS.MapAction.FullExtent=function(A){A.iconCls="webgis-mapaction-fullextent";A.handler=function(){this.map.zoomToMaxExtent()};WebGIS.MapAction.FullExtent.superclass.constructor.call(this,A)};Ext.extend(WebGIS.MapAction.FullExtent,WebGIS.MapAction);WebGIS.MapAction.DragPan=function(A){A.iconCls="webgis-mapaction-dragpan";A.enableToggle=true;A.toggleGroup="WebGIS.MapAction";A.olcontrol=new OpenLayers.Control.DragPan();WebGIS.MapAction.DragPan.superclass.constructor.call(this,A)};Ext.extend(WebGIS.MapAction.DragPan,WebGIS.MapAction);(function(){var B=function(D){var G=D.map;var F=0;var E=[];this.addEvents("historystatuschange");this.back=function(){if(F<(E.length-1)){F++;G.zoomToExtent(E[F])}};this.next=function(){if(F>0){F--;G.zoomToExtent(E[F])}};var C=function(){var H=E[F],I=true,J=true;if(E.length<2){I=false;J=false}else{if(F===E.length-1){I=false}else{if(F===0){J=false}}}this.fireEvent("historystatuschange",{previousHistory:I,nextHistory:J});if(G.getExtent().equals(H)){return }E.splice(0,0,G.getExtent())};G.events.register("zoomend",this,C);G.events.register("moveend",this,C);E.push(G.getExtent())};Ext.extend(B,Ext.util.Observable);var A;WebGIS.MapAction.PreviousExtent=function(C){C.iconCls="webgis-mapaction-previousextent";C.disabled=true;if(!A){A=new B({map:C.map})}C.handler=A.back;A.on("historystatuschange",function(D){D.previousHistory?this.enable():this.disable()},this);WebGIS.MapAction.PreviousExtent.superclass.constructor.call(this,C)};Ext.extend(WebGIS.MapAction.PreviousExtent,WebGIS.MapAction);WebGIS.MapAction.NextExtent=function(C){C.iconCls="webgis-mapaction-nextextent";C.disabled=true;if(!A){A=new B({map:C.map})}C.handler=A.next;A.on("historystatuschange",function(D){D.nextHistory?this.enable():this.disable()},this);WebGIS.MapAction.NextExtent.superclass.constructor.call(this,C)};Ext.extend(WebGIS.MapAction.NextExtent,WebGIS.MapAction)})();WebGIS.MapAction.DrawFeature=function(A){if(A.geometryType==="OpenLayers.Geometry.Point"){handler=OpenLayers.Handler.Point;A.iconCls="webgis-mapaction-drawpoint";this.titleText=this.titlePointText;this.tooltipText=this.tooltipPointText}else{if(A.geometryType==="OpenLayers.Geometry.Curve"){handler=OpenLayers.Handler.Path;A.iconCls="webgis-mapaction-drawline";this.titleText=this.titleCurveText;this.tooltipText=this.tooltipCurveText}else{if(A.geometryType==="OpenLayers.Geometry.Polygon"){handler=OpenLayers.Handler.Polygon;A.iconCls="webgis-mapaction-drawpolygon";this.titleText=this.titlePolygonText;this.tooltipText=this.tooltipPolygonText}}}A.olcontrol=new OpenLayers.Control.DrawFeature(A.layer,handler);WebGIS.MapAction.DrawFeature.superclass.constructor.call(this,A)};Ext.extend(WebGIS.MapAction.DrawFeature,WebGIS.MapAction);WebGIS.MapAction.SelectFeature=function(B,A){B.iconCls="webgis-mapaction-selectfeature";B.olcontrol=new OpenLayers.Control.SelectFeature(B.layer,B.options);WebGIS.MapAction.SelectFeature.superclass.constructor.call(this,B)};Ext.extend(WebGIS.MapAction.SelectFeature,WebGIS.MapAction);WebGIS.MapAction.RemoveSelectedFeatures=function(A){A.iconCls="webgis-mapaction-removefeature";var B=A.layer;var C=function(){if(B.selectedFeatures){B.removeFeatures(B.selectedFeatures)}};A.handler=C;WebGIS.MapAction.RemoveSelectedFeatures.superclass.constructor.call(this,A)};Ext.extend(WebGIS.MapAction.RemoveSelectedFeatures,WebGIS.MapAction);WebGIS.MapAction.ModifyFeature=function(A){A.iconCls="webgis-mapaction-modifyfeature";A.olcontrol=new OpenLayers.Control.ModifyFeature(A.layer);WebGIS.MapAction.ModifyFeature.superclass.constructor.call(this,A)};Ext.extend(WebGIS.MapAction.ModifyFeature,WebGIS.MapAction);WebGIS.MapAction.DragFeature=function(A){A.iconCls="webgis-mapaction-dragfeature";A.olcontrol=new OpenLayers.Control.DragFeature(A.layer);WebGIS.MapAction.DragFeature.superclass.constructor.call(this,A)};Ext.extend(WebGIS.MapAction.DragFeature,WebGIS.MapAction);WebGIS.MapAction.Identify=function(A){A.iconCls="webgis-mapaction-identify";A.enableToggle=true;A.toggleGroup="WebGIS.MapAction";if(A.resultTo===null){A.resultTo=new Ext.Window({title:A.text,closeAction:"hide",width:300,autoHeight:true})}A.olcontrol=new OpenLayers.Control.Identify({toc:A.toc,resultTo:A.resultTo});WebGIS.MapAction.Identify.superclass.constructor.call(this,A)};Ext.extend(WebGIS.MapAction.Identify,WebGIS.MapAction);WebGIS.MapAction.MeasureLine=function(B){B.iconCls="webgis-mapaction-measurelength";var C=function(){if(this.tip){this.tip.destroy()}};var A=function(D){var G=this.handler.line.geometry.getLength(),E,F;if(G===0){return }if((G%1000)===G){G=Math.round(G).toString()+" m"}else{G=((Math.round(G*10/1000)/10)).toString()+" km"}if(this.tip){this.tip.destroy()}this.tip=new Ext.Tip({html:G,style:"width:150",autoHeight:true});E=this.map.getViewPortPxFromLonLat(new OpenLayers.LonLat(D.x,D.y));F=Ext.Element(this.map.div);this.tip.showAt([E.x+5+F.getLeft(),E.y+5+F.getTop()])};B.olcontrol=new OpenLayers.Control.DrawFeature(B.layer,OpenLayers.Handler.Path,{callbacks:{done:C,point:A,cancel:C}});WebGIS.MapAction.MeasureLine.superclass.constructor.call(this,B)};WebGIS.MapAction.MeasureLine.prototype={};Ext.extend(WebGIS.MapAction.MeasureLine,WebGIS.MapAction);WebGIS.MapAction.MeasureArea=function(B){B.iconCls="webgis-mapaction-measurearea";var C=function(){if(this.tip){this.tip.destroy()}};var A=function(D){var G=this.handler.polygon.geometry.getArea(),E,F;if(G===0){return }if((G%1000000)===G){G=Math.round(G).toString()+" m&#178;"}else{G=(Math.round(G*10/1000000)/10).toString()+" km&#178;"}if(this.tip){this.tip.destroy()}this.tip=new Ext.Tip({html:G,style:"width:150",autoHeight:true});E=this.map.getViewPortPxFromLonLat(new OpenLayers.LonLat(D.x,D.y));F=Ext.Element(this.map.div);this.tip.showAt([E.x+5+F.getLeft(),E.y+5+F.getTop()])};B.olcontrol=new OpenLayers.Control.DrawFeature(B.layer,OpenLayers.Handler.Polygon,{callbacks:{done:C,point:A,cancel:C}});WebGIS.MapAction.MeasureArea.superclass.constructor.call(this,B)};Ext.extend(WebGIS.MapAction.MeasureArea,WebGIS.MapAction);WebGIS.OpenLayers.Control.Identify=OpenLayers.Class(OpenLayers.Control,{type:OpenLayers.Control.TYPE_TOOL,initialize:function(A){OpenLayers.Control.prototype.initialize.apply(this,[A]);this.handler=new OpenLayers.Handler.Click(this,{click:this.identify})},identify:function(D){var C=this.toc.getSelectionModel().getSelectedNode(),A;if(C===null){Ext.MessageBox.show({title:"Information",msg:"Requires selected layer in a WMS service",buttons:Ext.MessageBox.OK,icon:Ext.MessageBox.INFO});return }if(C.layer.CLASS_NAME!="OpenLayers.Layer.WMS"){Ext.MessageBox.show({title:"Information",msg:"Can only identify on WMS layers",buttons:Ext.MessageBox.OK,icon:Ext.MessageBox.INFO});return }A=C.layer.getFullRequestString({REQUEST:"GetFeatureInfo",EXCEPTIONS:"application/vnd.ogc.se_xml",BBOX:C.layer.map.getExtent().toBBOX(),X:D.xy.x,Y:D.xy.y,INFO_FORMAT:"text/html",QUERY_LAYERS:C.name,WIDTH:C.layer.map.size.w,HEIGHT:C.layer.map.size.h});try{Ext.Ajax.request({url:A,scope:this,success:function(E,F){var G=E.responseText;this.resultTo.show();this.resultTo.body.update(G)},failure:function(E,F){Ext.MessageBox.show({title:"Error",msg:"Could not complete GetFeatureInfo request",buttons:Ext.MessageBox.OK,icon:Ext.MessageBox.ERROR})}})}catch(B){Ext.MessageBox.show({title:"Error",msg:"Exception occured in AJAX-request.",buttons:Ext.MessageBox.OK,icon:Ext.MessageBox.ERROR})}},CLASS_NAME:"OpenLayers.Control.Identify"});WebGIS.OpenLayers.Layer.WebGISTileServer=OpenLayers.Class(OpenLayers.Layer.Grid,{isBaseLayer:true,tileSize:new OpenLayers.Size(250,250),initialize:function(C,B,E,D){var A=[];A.push(C,B,{},E);OpenLayers.Layer.Grid.prototype.initialize.apply(this,A);this.provider=E;this.token=D},initGriddedTiles:function(A){var B=this.map.resolutions.length-1-this.map.getZoom();this.maxExtent=new OpenLayers.Bounds(this.provider.MINX[B],this.provider.MINY[B],this.provider.MAXX[B],this.provider.MAXY[B]);this.map.maxExtent=this.maxExtent;this.tileOrigin=new OpenLayers.LonLat(this.provider.MINX[B],this.provider.MINY[B]);OpenLayers.Layer.Grid.prototype.initGriddedTiles.apply(this,arguments)},getURL:function(C){var B=this.map.getResolution(),E=this.map.resolutions.length-1-this.map.getZoom(),A=Math.floor((C.left-this.tileOrigin.lon)/(B*this.tileSize.w)),F=Math.floor((C.bottom-this.tileOrigin.lat)/(B*this.tileSize.h)),D=(this.provider.MAXY[E]-this.provider.MINY[E])/this.provider.SIZES[E];F=D-1-F;return this.url+"?providerId="+this.provider.providerId+"&token="+this.token+"&zoomlevel="+E+"&x="+A+"&y="+F},addTile:function(B,A){return new OpenLayers.Tile.Image(this,A,B,null,this.tileSize)},CLASS_NAME:"WebGIS.OpenLayers.Layer.WebGISTileServer"});WebGIS.ScaleList=function(C){var A=new Ext.data.SimpleStore({fields:["res","scale"]});var F=C.map;Ext.apply(this,{valueField:"zoomlevel",displayField:"scale",mode:"local",triggerAction:"all",forceSelection:true,editable:false,autoWidth:true,autoHeight:true,store:A});WebGIS.ScaleList.superclass.constructor.apply(this,arguments);var B=function(K,I,J){F.zoomTo(I.get("zoomlevel"))};this.on("select",B);var E=function(){this.setValue(F.getZoomForResolution(F.getResolution()))};F.events.register("zoomend",this,E);for(var D=0;D<F.getNumZoomLevels();D++){var H=OpenLayers.Util.getScaleFromResolution(F.getResolutionForZoom(D),"m"),G=new Ext.data.Record({zoomlevel:D,scale:"1:"+Math.round(H)});A.add(G)}this.setValue(F.getZoomForResolution(F.getResolution()))};Ext.extend(WebGIS.ScaleList,Ext.form.ComboBox);Ext.reg("webgis-scalelist",WebGIS.ScaleList);WebGIS.Toc=function(A){Ext.apply(this,{rootVisible:false,useMetadata:false,root:new Ext.tree.TreeNode({draggable:false})});var F=function(I,H){var G=function(K,N){var L="";if(K.node.metadata){if(K.node.metadata.openlayers){L+='<h3 class="webgis-metadatalist">OpenLayers</h3>';L+='<dl class="webgis-metadatalist">';L+="<dt>Type</dt>";L+="<dd>"+K.node.metadata.openlayers.type+"</dd>";L+="<dt>Source</dt>";L+="<dd>"+K.node.metadata.openlayers.source+"</dd>";L+="</dl><br>"}if(K.node.metadata.wms){if(K.node.metadata.wms.service){L+="<h3>WMS Service</h3>";L+="<dl>";L+="<dt>Name</dt>";L+="<dd>"+K.node.metadata.wms.service.name+"</dd>";L+="<dt>Title</dt>";L+="<dd>"+K.node.metadata.wms.service.title+"</dd>";L+="<dt>Abstract</dt>";L+="<dd>"+K.node.metadata.wms.service.abstacttext+"</dd>";L+="</dl><br>"}if(K.node.metadata.wms.layer){L+="<h3>WMS Layer</h3>";L+="<dl>";L+="<dt>Name</dt>";L+="<dd>"+K.node.metadata.wms.layer.name+"</dd>";L+="<dt>Title</dt>";L+="<dd>"+K.node.metadata.wms.layer.title+"</dd>";L+="<dt>SRS</dt>";L+="<dd>"+K.node.metadata.wms.layer.srs+"</dd>";L+="</dl><br>"}}}var M=new Ext.Window({title:this.windowTitleMetadataText,border:false,width:400,autoHeight:true,resizable:false,layout:"fit",items:[{cls:"webgis-metadatalist",border:false,bodyStyle:"padding:5px",autoWidth:true,autoHeight:true,html:L}]});M.show()};var J=new Ext.menu.Menu();J.add({text:this.contextMenuMetadataText,handler:G,node:I});J.showAt(H.getXY())};var C=function(I,H){var J="",G;this.subLayers[I.layerIndex].visibility=H;for(G=0;G<this.subLayers.length;G++){if(this.subLayers[G].visibility){J=this.subLayers[G].name+","+J}}if(J===""){this.layer.setVisibility(false)}else{J=J.slice(0,-1);this.layer.params.LAYERS=J;this.layer.setVisibility(true);this.layer.redraw()}};var D=function(I,P,L,M){var J,H,N,O,G,K;for(K=0;K<P.length;K++){J=P[K];H=Ext.DomQuery.selectNode("Name",J).firstChild.nodeValue;N=Ext.DomQuery.selectNode("Title",J).firstChild.nodeValue;O=false;if(L.params.LAYERS.indexOf(H)!==-1){O=true}if(M===null){M=I}G=new Ext.tree.TreeNode({text:N,checked:O});G.name=H;G.layer=L;G.layerIndex=K;if(this.useMetadata){G.metadata={wms:{layer:{name:H,title:N,srs:Ext.DomQuery.selectNode("SRS",J).firstChild.nodeValue}}};G.on("contextmenu",F,this)}G.on("checkchange",C,M);I.appendChild(G);M.subLayers.push({name:H,visibility:O});D(I,Ext.DomQuery.select("Layer",J),L,M)}};var E=function(H,I){var J=function(M,N){var K=Ext.DomQuery.selectNode("Layer:first",M.responseXML),L=Ext.DomQuery.selectNode("Service:first",M.responseXML),O=Ext.DomQuery.select("Layer",K);N.node.name=Ext.DomQuery.selectNode("Name",K).firstChild.nodeValue;N.node.setText(Ext.DomQuery.selectNode("Title",K).firstChild.nodeValue);if(this.useMetadata){N.node.metadata.wms={};N.node.metadata.wms.service={};N.node.metadata.wms.service.name=Ext.DomQuery.selectNode("Name",L).firstChild.nodeValue;N.node.metadata.wms.service.title=Ext.DomQuery.selectNode("Title",L).firstChild.nodeValue;N.node.metadata.wms.service.abstracttext=Ext.DomQuery.selectNode("Abstract",L).firstChild.nodeValue}this.fillTree(N.node,O,N.layer,null)};var G=function(K,L){Ext.MessageBox.show({title:"Error",msg:"Could not get WMS GetCapabilities",buttons:Ext.MessageBox.OK,icon:Ext.MessageBox.ERROR})};Ext.Ajax.request({url:H.capabilitiesUrl+"?REQUEST=GetCapabilities&SERVICE=WMS&VERSION=1.1.1",scope:this,layer:H,node:I,success:J,failure:G})};var B=function(H,G){this.setVisibility(G)};this.update=function(){var H,G,I;for(H=0;H<this.map.layers.length;H++){G=this.map.layers[this.map.layers.length-1-H];if(G.visibleInToc===false){continue}I=new Ext.tree.TreeNode({text:G.name,checked:G.getVisibility()});I.layer=G;this.getRootNode().appendChild(I);I.on("checkchange",B,G);if(this.useMetadata){I.metadata={openlayers:{type:G.CLASS_NAME,source:G.url}};I.on("contextmenu",F,this)}if(G.CLASS_NAME==="OpenLayers.Layer.WMS"){if(G.capabilitiesUrl){I.subLayers=[];E(G,I)}}}};WebGIS.Toc.superclass.constructor.call(this,A)};Ext.extend(WebGIS.Toc,Ext.tree.TreePanel);Ext.reg("webgis-toc",WebGIS.Toc);WebGIS.Locale={};WebGIS.Locale.errorText="Error message";Ext.apply(WebGIS.Toc.prototype,{windowTitleMetadataText:"Metadata for this layer",contextMenuMetadataText:"Show metadata"});Ext.apply(WebGIS.MapAction.ZoomInBox.prototype,{titleText:"Zoom in",tooltipText:"Zoom in by drawing a rectangle"});Ext.apply(WebGIS.MapAction.ZoomOutBox.prototype,{titleText:"Zoom out",tooltipText:"Zoom out by drawing a rectangle"});Ext.apply(WebGIS.MapAction.ZoomIn.prototype,{titleText:"Zoom in",tooltipText:"Zoom in one step"});Ext.apply(WebGIS.MapAction.ZoomOut.prototype,{titleText:"Zoom out",tooltipText:"Zoom out one step"});Ext.apply(WebGIS.MapAction.FullExtent.prototype,{titleText:"Full extent",tooltipText:"Zoom to the full map extent"});Ext.apply(WebGIS.MapAction.DragPan.prototype,{titleText:"Pan",tooltipText:"Pan by dragging the map"});Ext.apply(WebGIS.MapAction.PreviousExtent.prototype,{titleText:"Previous extent",tooltipText:"Go to previous extent"});Ext.apply(WebGIS.MapAction.NextExtent.prototype,{titleText:"Next extent",tooltipText:"Go to next extent"});Ext.apply(WebGIS.MapAction.DrawFeature.prototype,{titlePointText:"Draw",tooltipPointText:"Draw point",titleCurveText:"Draw",tooltipCurveText:"Draw line",titlePolygonText:"Draw",tooltipPolygonText:"Draw polygon"});Ext.apply(WebGIS.MapAction.SelectFeature.prototype,{titleText:"Select",tooltipText:"Select geometry"});Ext.apply(WebGIS.MapAction.RemoveSelectedFeatures.prototype,{titleText:"Remove",tooltipText:"Remove geometry"});Ext.apply(WebGIS.MapAction.ModifyFeature.prototype,{titleText:"Modify",tooltipText:"Modify geometry"});Ext.apply(WebGIS.MapAction.DragFeature.prototype,{titleText:"Move",tooltipText:"Move geometry"});Ext.apply(WebGIS.MapAction.MeasureLine.prototype,{titleText:"Measure distance",tooltipText:"Measure distance by drawing a line"});Ext.apply(WebGIS.MapAction.MeasureArea.prototype,{titleText:"Measure area",tooltipText:"Measure distance by drawing a polygon"});Ext.apply(WebGIS.MapAction.Identify.prototype,{titleText:"Identify",tooltipText:"Shows attributes for an object in the map (only WMS-layers)"});
