var Styler=function(){this.addEvents("layerchanged","ruleadded","ruleremoved","ruleupdated");Styler.dispatch([function(done){Ext.onReady(function(){this.createLayout();done();},this);},function(done){this.getCapabilities(done);}],function(){this.createLayers();this.getSchemas(this.initEditor.createDelegate(this));},this);};Ext.extend(Styler,Ext.util.Observable,{map:null,wmsLayerList:null,wfsLayerList:null,layerList:null,currentLayer:null,sldManager:null,schemaManager:null,symbolTypes:null,ruleDlg:null,featureDlg:null,getFeatureControl:null,saving:null,windowPositions:{featureDlg:{},ruleDlg:{}},getCapabilities:function(callback){Styler.dispatch([function(done){this.getWMSCapabilities(done);},function(done){this.getWFSCapabilities(done);}],function(){this.mergeCapabilities();callback();},this);},getWMSCapabilities:function(callback){Ext.Ajax.request({url:"/geoserver/wms?",method:"GET",disableCaching:false,success:this.parseWMSCapabilities,failure:function(){throw("Unable to read capabilities from WMS");},params:{VERSION:"1.1.1",REQUEST:"GetCapabilities"},options:{callback:callback},scope:this});},getWFSCapabilities:function(callback){Ext.Ajax.request({url:"/geoserver/wfs?",method:"GET",disableCaching:false,success:this.parseWFSCapabilities,failure:function(){throw("Unable to read capabilities from WFS");},params:{VERSION:"1.1.0",REQUEST:"GetCapabilities"},options:{callback:callback},scope:this});},parseWMSCapabilities:function(response,request){var capabilities=new OpenLayers.Format.WMSCapabilities().read(response.responseXML.documentElement?response.responseXML:response.responseText);this.wmsLayerList=capabilities.capability.layers;request.options.callback();},parseWFSCapabilities:function(response,request){var capabilities=new OpenLayers.Format.WFSCapabilities().read(response.responseXML.documentElement?response.responseXML:response.responseText);this.wfsLayerList=capabilities.featureTypeList.featureTypes;request.options.callback();},mergeCapabilities:function(){this.layerList=[];var layer,name;for(var i=0;i<this.wmsLayerList.length;++i){layer=this.wmsLayerList[i];name=layer.name;for(var j=0;j<this.wfsLayerList.length;++j){if(this.wfsLayerList[j].name===name){this.layerList.push(layer);break;}}}},createLayout:function(){this.getFeatureControl=new OpenLayers.Control.WFSGetFeature();this.getFeatureControl.events.on({"featureselected":function(e){this.showFeatureInfo(this.currentLayer,e.feature);},scope:this});this.mapPanel=new GeoExt.widgets.map.MapPanel({border:true,region:"center",mapOptions:{controls:[new OpenLayers.Control.Navigation(),new OpenLayers.Control.PanPanel()],projection:new OpenLayers.Projection("EPSG:900913"),units:"m",theme:null,maxResolution:156543.0339,maxExtent:new OpenLayers.Bounds(-20037508.34,-20037508.34,20037508.34,20037508.34)},controls:[this.getFeatureControl]});this.legendContainer=new Ext.Panel({title:"Legend",height:200,items:[{html:""}],bbar:[{text:"Add new",iconCls:"add",disabled:true,handler:function(){var panel=this.getLegend();var symbolizer={};symbolizer[panel.symbolType]=OpenLayers.Format.SLD.v1.prototype.defaultSymbolizer;var rule=new OpenLayers.Rule({symbolizer:symbolizer});panel.rules.push(rule);this.fireEvent("ruleadded",rule);this.showRule(this.currentLayer,rule,panel.symbolType,function(){if(!this.saving){panel.rules.remove(rule);this.fireEvent("ruleremoved",rule);}});},scope:this},{text:"Delete selected",iconCls:"delete",disabled:true,handler:function(){var panel=this.getLegend();var rule=panel.selectedRule;var message="Are you sure you want to delete the "+
panel.getRuleTitle(rule)+" rule?";Ext.Msg.confirm("Delete rule",message,function(yesno){if(yesno=="yes"){panel.rules.remove(rule);this.fireEvent("ruleremoved",rule);sldMgr=this.sldManager;sldMgr.saveSld(this.currentLayer,function(){this.ruleDlg.close();this.repaint();},this);}},this);},scope:this}]});this.layersContainer=new Ext.Panel({autoScroll:true,title:"Layers",anchor:"100%, -200"});var westPanel=new Ext.Panel({border:true,layout:"anchor",region:"west",width:250,split:true,collapsible:true,collapseMode:"mini",items:[this.layersContainer,this.legendContainer]});var viewport=new Ext.Viewport({layout:"fit",hideBorders:true,items:{layout:"border",deferredRender:false,items:[this.mapPanel,westPanel]}});this.map=this.mapPanel.map;},createLayers:function(){var layerList=this.layerList;var num=layerList.length;var layers=new Array(num+1);layers[0]=new OpenLayers.Layer.Google("Google Physical",{type:G_PHYSICAL_MAP,sphericalMercator:true});for(var i=0;i<num;++i){layers[i+1]=new OpenLayers.Layer.WMS(layerList[i].title,"/geoserver/wms?",{layers:layerList[i].name,styles:layerList[i].styles[0].name,transparent:"true",tileOrigin:[layerList[i].llbbox[0],layerList[i].llbbox[1]],format:OpenLayers.Util.alphaHack()?"image/gif":"image/png"},{isBaseLayer:false,displayOutsideMaxExtent:true,visibility:false,maxExtent:new OpenLayers.Bounds(layerList[i].llbbox[0],layerList[i].llbbox[1],layerList[i].llbbox[2],layerList[i].llbbox[3]).transform(new OpenLayers.Projection("EPSG:4326"),new OpenLayers.Projection("EPSG:900913"))});}
this.layerTree=new Ext.tree.TreePanel({border:false,loader:new Ext.tree.TreeLoader({clearOnLoad:true}),root:{nodeType:"async",children:[{nodeType:"olOverlayLayerContainer",text:"Layers",expanded:true}]},rootVisible:false,lines:false,listeners:{"checkchange":this.changeLayer,scope:this}});this.layersContainer.add(this.layerTree);this.layersContainer.doLayout();this.map.addLayers(layers);var slider=new Styler.ScaleSlider({plugins:new Styler.ScaleSliderTip(),vertical:true,height:120,map:this.map}).addToMap();this.setCurrentLayer(this.map.layers[1]);},getSchemas:function(callback){this.schemaManager=new Styler.SchemaManager(this.map);this.schemaManager.loadAll(callback);},getStyles:function(callback){this.sldManager=new Styler.SLDManager(this.map);this.sldManager.loadAll(callback);},initEditor:function(){this.symbolTypes={};this.sldManager=new Styler.SLDManager(this.map);this.getFeatureControl.activate();this.setCurrentLayer(this.currentLayer);this.on({"ruleadded":function(){this.refreshLegend();this.refreshFeatureDlg();},"ruleremoved":function(){this.refreshLegend();this.refreshFeatureDlg();},"ruleupdated":function(){this.refreshLegend();this.refreshFeatureDlg();},"layerchanged":function(layer){this.showLegend(layer);},scope:this});this.showLegend(this.currentLayer);},changeLayer:function(node,checked){if(checked===true&&this.currentLayer!=node.layer){this.setCurrentLayer(node.layer);}},setCurrentLayer:function(layer){if(layer!=this.currentLayer){if(this.currentLayer){this.currentLayer.setVisibility(false);}
this.map.zoomToExtent(layer.maxExtent);this.currentLayer=layer;if(this.ruleDlg){this.ruleDlg.destroy();delete this.ruleDlg;}
if(this.featureDlg){this.featureDlg.destroy();delete this.featureDlg;}
this.fireEvent("layerchanged",this.currentLayer);}
if(layer.getVisibility()===false){layer.setVisibility(true);}
if(this.getFeatureControl.active){this.getFeatureControl.layer=layer;this.getFeatureControl.geometryName=this.schemaManager.getGeometryName(layer);}},getRules:function(layer,callback){var rules;var style=this.sldManager.getStyle(layer);if(style){callback.call(this,style.rules);}else{this.sldManager.loadSld(layer,layer.params["STYLES"],function(result){callback.call(this,result.style.rules);}.createDelegate(this));}},showLegend:function(layer){var old=this.legendContainer.items.length&&this.legendContainer.getComponent(0);if(old){this.getAddButton().disable();this.legendContainer.remove(old);}
Styler.dispatch([function(done,context){this.getSymbolType(layer,function(type){context.symbolType=type;done();});},function(done,context){this.getRules(layer,function(rules){context.rules=rules;done();});}],function(context){if(layer===this.currentLayer){this.addLegend(layer,context.rules,context.symbolType);}},this);},addLegend:function(layer,rules,type){var deleteButton=this.getDeleteButton();var legend=new Styler.LegendPanel({rules:rules,symbolType:type,border:false,style:{padding:"10px"},selectOnClick:true,listeners:{"ruleselected":function(panel,rule){this.showRule(this.currentLayer,rule,panel.symbolType);deleteButton.enable();},"ruleunselected":function(panel,rule){deleteButton.disable();},"rulemoved":function(panel,rule){legend.disable();this.sldManager.saveSld(this.currentLayer,function(){legend.enable();this.repaint();},this);},scope:this}});this.legendContainer.add(legend);this.legendContainer.doLayout();this.getAddButton().enable();},refreshLegend:function(){var legend=this.legendContainer.items.length&&this.legendContainer.getComponent(0);if(legend){legend.update();}},refreshFeatureDlg:function(){if(this.featureDlg&&!this.featureDlg.hidden){var feature=this.featureDlg.getFeature();this.showFeatureInfo(this.currentLayer,feature);}},setSymbolType:function(layer,type){this.symbolTypes[layer.id]=type;return type;},getSymbolTypeFromFeature:function(feature){return feature.geometry.CLASS_NAME.replace(/OpenLayers\.Geometry\.(Multi)?|String/g,"");},getSymbolType:function(layer,callback){var type=this.symbolTypes[layer.id];if(type){callback.call(this,type);}else{type=this.schemaManager.getSymbolType(layer);if(type){this.setSymbolType(layer,type);callback.call(this,type);}else{this.getOneFeature(layer,function(features){type=this.setSymbolType(layer,this.getSymbolTypeFromFeature(features[0]));callback.call(this,type);});}}},showFeatureInfo:function(layer,feature){if(this.featureDlg){this.featureDlg.destroy();}
this.getRules(layer,function(rules){this.displayFeatureDlg(layer,feature,rules);});},displayFeatureDlg:function(layer,feature,rules){feature.layer=layer;var matchingRules=[];var rule;for(var i=0;i<rules.length;++i){rule=rules[i];if(rule.evaluate(feature)){matchingRules.push(rule);}}
this.featureDlg=new Ext.Window({title:"Feature: "+feature.fid||feature.id,layout:"fit",resizable:false,width:220,x:this.windowPositions.featureDlg.x,y:this.windowPositions.featureDlg.y,items:[{hideBorders:true,border:false,autoHeight:true,items:[{xtype:"gx_legendpanel",title:"Rules used to render this feature:",bodyStyle:{paddingLeft:"5px"},symbolType:this.getSymbolTypeFromFeature(feature),rules:matchingRules,clickableSymbol:true,listeners:{"symbolclick":function(panel,rule){this.showRule(this.currentLayer,rule,panel.symbolType);},scope:this}},{xtype:"propertygrid",title:"Attributes of this feature:",height:120,source:feature.attributes,autoScroll:true,listeners:{"beforepropertychange":function(){return false;}}}]}],listeners:{"move":function(cp,x,y){this.windowPositions["featureDlg"]={x:x,y:y};},scope:this},getFeature:function(){return feature}});this.featureDlg.show();},showRule:function(layer,rule,symbolType,closeCallback){var newRule=rule.clone();if(this.ruleDlg){this.ruleDlg.destroy();}
this.ruleDlg=new Ext.Window({title:"Style: "+(rule.title||rule.name||"Untitled"),layout:"fit",x:this.windowPositions.ruleDlg.x,y:this.windowPositions.ruleDlg.y,width:265,constrainHeader:true,items:[{xtype:"gx_rulepanel",autoHeight:false,autoScroll:true,rule:newRule,symbolType:Styler.Util.getSymbolTypeFromRule(rule),nestedFilters:false,scaleLevels:this.map.baseLayer.numZoomLevels,minScaleLimit:OpenLayers.Util.getScaleFromResolution(this.map.baseLayer.resolutions[this.map.baseLayer.numZoomLevels-1],this.map.units),maxScaleLimit:OpenLayers.Util.getScaleFromResolution(this.map.baseLayer.resolutions[0],this.map.units),scaleSliderTemplate:"<div>{zoomType} Zoom Level: {zoom}</div>"+"<div>Current Map Zoom: {mapZoom}</div>",modifyScaleTipContext:(function(panel,data){data.mapZoom=this.map.getZoom();}).createDelegate(this),attributes:new Styler.data.AttributesStore({url:"/geoserver/wfs?",baseParams:{version:"1.1.1",request:"DescribeFeatureType",typename:layer.params["LAYERS"]},ignore:{name:this.schemaManager.getGeometryName(layer)}}),pointGraphics:[{display:"circle",value:"circle",mark:true,preview:"theme/img/circle.gif"},{display:"square",value:"square",mark:true,preview:"theme/img/square.gif"},{display:"triangle",value:"triangle",mark:true,preview:"theme/img/triangle.gif"},{display:"star",value:"star",mark:true,preview:"theme/img/star.gif"},{display:"cross",value:"cross",mark:true,preview:"theme/img/cross.gif"},{display:"x",value:"x",mark:true,preview:"theme/img/x.gif"},{display:"custom..."}]}],bbar:["->",{text:"cancel",iconCls:"cancel",handler:function(){this.ruleDlg.close();},scope:this},{text:"save",iconCls:"save",handler:function(){this.saving=true;this.ruleDlg.disable();this.updateRule(rule,newRule);this.sldManager.saveSld(layer,function(){this.ruleDlg.close();this.repaint();this.saving=false;},this);},scope:this}],listeners:{close:function(){this.getLegend().unselect();if(closeCallback){closeCallback.call(this);}},move:function(cp,x,y){this.windowPositions["ruleDlg"]={x:x,y:y};},scope:this}});this.ruleDlg.show();},updateRule:function(rule,newRule){rule.title=newRule.title;rule.symbolizer=newRule.symbolizer;rule.filter=newRule.filter;rule.minScaleDenominator=newRule.minScaleDenominator;rule.maxScaleDenominator=newRule.maxScaleDenominator;this.fireEvent("ruleupdated",rule);},repaint:function(){this.currentLayer.redraw(true);},getOneFeature:function(layer,callback){Ext.Ajax.request({url:"/geoserver/wfs?",method:"GET",disableCaching:false,params:{version:"1.0.0",request:"GetFeature",typeName:layer.params["LAYERS"],maxFeatures:"1"},success:function(response){var features=new OpenLayers.Format.GML().read(response.responseXML||response.responseText);if(features.length){callback.call(this,features);}else{throw("Could not load features from the WFS");}},failure:function(response){throw("Could not load features from the WFS");},scope:this});},getLegend:function(){return this.legendContainer.getComponent(0);},getAddButton:function(){return this.legendContainer.getBottomToolbar().items.get(0);},getDeleteButton:function(){return this.legendContainer.getBottomToolbar().items.get(1);}});OpenLayers.DOTS_PER_INCH=25.4/0.28;Ext.namespace("Styler.form");Styler.form.ComarisonComboBox=Ext.extend(Ext.form.ComboBox,{allowedTypes:[[OpenLayers.Filter.Comparison.EQUAL_TO,"="],[OpenLayers.Filter.Comparison.NOT_EQUAL_TO,"<>"],[OpenLayers.Filter.Comparison.LESS_THAN,"<"],[OpenLayers.Filter.Comparison.GREATER_THAN,">"],[OpenLayers.Filter.Comparison.LESS_THAN_OR_EQUAL_TO,"<="],[OpenLayers.Filter.Comparison.GREATER_THAN_OR_EQUAL_TO,">="],[OpenLayers.Filter.Comparison.LIKE,"like"]],allowBlank:false,mode:"local",triggerAction:"all",width:50,editable:false,initComponent:function(){var defConfig={displayField:"name",valueField:"value",store:new Ext.data.SimpleStore({data:this.allowedTypes,fields:["value","name"]}),value:(this.value===undefined)?this.allowedTypes[0][0]:this.value};Ext.applyIf(this,defConfig);Styler.form.ComarisonComboBox.superclass.initComponent.call(this);}});Ext.reg("gx_comparisoncombo",Styler.form.ComarisonComboBox);Ext.namespace("Styler");Styler.SliderTip=Ext.extend(Ext.Tip,{hover:true,dragging:false,minWidth:10,minWidth:10,offsets:[0,-10],init:function(slider){slider.on('dragstart',this.onSlide,this);slider.on('drag',this.onSlide,this);slider.on('dragend',this.hide,this);slider.on('destroy',this.destroy,this);if(this.hover){slider.on('render',this.registerThumbListeners,this);}
this.slider=slider;},registerThumbListeners:function(){this.slider.thumb.on({"mouseover":function(){this.onSlide(this.slider);this.dragging=false;},"mouseout":function(){if(!this.dragging){this.hide.apply(this,arguments);}},scope:this});},onSlide:function(slider){this.dragging=true;this.show();this.body.update(this.getText(slider));this.doAutoWidth();this.el.alignTo(slider.thumb,'b-t?',this.offsets);},getText:function(slider){return slider.getValue();}});Ext.namespace("Styler");Styler.StrokeSymbolizer=Ext.extend(Ext.FormPanel,{symbolizer:null,defaultSymbolizer:null,dashStyles:[["solid",["solid"]],["dash","dash"],["dot","dot"]],border:false,initComponent:function(){if(!this.symbolizer){this.symbolizer={};}
Ext.applyIf(this.symbolizer,this.defaultSymbolizer);this.items=[{xtype:"fieldset",title:"Stroke",autoHeight:true,defaults:{width:100},items:[{xtype:"combo",name:"style",fieldLabel:"Style",store:new Ext.data.SimpleStore({data:this.dashStyles,fields:["value","display"]}),displayField:"display",valueField:"value",value:this.symbolizer["strokeDashstyle"],mode:"local",allowBlank:true,triggerAction:"all",editable:false,listeners:{select:function(combo,record){this.symbolizer["strokeDashstyle"]=record.get("value");this.fireEvent("change",this.symbolizer);},scope:this}},{xtype:"gx_colorfield",name:"color",fieldLabel:"Color",value:this.symbolizer["strokeColor"],plugins:new Styler.ColorManager(),listeners:{valid:function(field){this.symbolizer["strokeColor"]=field.getValue();this.fireEvent("change",this.symbolizer);},scope:this}},{xtype:"textfield",name:"width",fieldLabel:"Width",value:this.symbolizer["strokeWidth"],listeners:{change:function(field,value){this.symbolizer["strokeWidth"]=value;this.fireEvent("change",this.symbolizer);},scope:this}},{xtype:"slider",name:"opacity",fieldLabel:"Opacity",value:(this.symbolizer["strokeOpacity"]==null)?100:this.symbolizer["strokeOpacity"]*100,isFormField:true,listeners:{changecomplete:function(slider,value){this.symbolizer["strokeOpacity"]=value/100;this.fireEvent("change",this.symbolizer);},scope:this},plugins:[new Styler.SliderTip({getText:function(slider){return slider.getValue()+"%";}})]}]}];this.addEvents("change");Styler.StrokeSymbolizer.superclass.initComponent.call(this);}});Ext.reg('gx_strokesymbolizer',Styler.StrokeSymbolizer);Ext.namespace("Styler");Styler.FilterPanel=Ext.extend(Ext.Panel,{filter:null,attributes:null,attributesComboConfig:null,initComponent:function(){var defConfig={plain:true,border:false};Ext.applyIf(this,defConfig);if(!this.filter){this.filter=this.createDefaultFilter();}
if(!this.attributes){this.attributes=new Styler.data.AttributesStore();}
var defAttributesComboConfig={xtype:"combo",store:this.attributes,editable:false,triggerAction:"all",hideLabel:true,allowBlank:false,displayField:"name",valueField:"name",value:this.filter.property,listeners:{select:function(combo,record){this.filter.property=record.get("name");this.fireEvent("change",this.filter);},scope:this},width:120};this.attributesComboConfig=this.attributesComboConfig||{};Ext.applyIf(this.attributesComboConfig,defAttributesComboConfig);this.items=this.createFilterItems();this.addEvents("change");Styler.FilterPanel.superclass.initComponent.call(this);},createDefaultFilter:function(){return new OpenLayers.Filter.Comparison();},createFilterItems:function(){return[{layout:"column",border:false,defaults:{border:false},items:[{width:this.attributesComboConfig.width,items:[this.attributesComboConfig]},{items:[{xtype:"gx_comparisoncombo",value:this.filter.type,listeners:{select:function(combo,record){this.filter.type=record.get("value");this.fireEvent("change",this.filter);},scope:this}}]},{items:[{xtype:"textfield",width:120,value:this.filter.value,allowBlank:false,listeners:{change:function(el,value){this.filter.value=value;this.fireEvent("change",this.filter);},scope:this}}]}]}];}});Ext.reg('gx_filterpanel',Styler.FilterPanel);Ext.namespace("Styler.form");Styler.form.FontComboBox=Ext.extend(Ext.form.ComboBox,{fonts:["Arial","Courier New","Tahoma","Times New Roman","Verdana"],defaultFont:"Tahoma",allowBlank:false,mode:"local",triggerAction:"all",editable:false,initComponent:function(){var defConfig={displayField:"text",valueField:"text",store:this.fonts,value:this.defaultFont,tpl:new Ext.XTemplate('<tpl for=".">'+'<div class="x-combo-list-item">'+'<span style="font-family: {text};">{text}</span>'+'</div></tpl>')};Ext.applyIf(this,defConfig);Styler.form.FontComboBox.superclass.initComponent.call(this);}});Ext.reg("gx_fontcombo",Styler.form.FontComboBox);Ext.namespace("Styler.form");Styler.form.ColorField=Ext.extend(Ext.form.TextField,{cssColors:{aqua:"#00FFFF",black:"#000000",blue:"#0000FF",fuchsia:"#FF00FF",gray:"#808080",green:"#008000",lime:"#00FF00",maroon:"#800000",navy:"#000080",olive:"#808000",purple:"#800080",red:"#FF0000",silver:"#C0C0C0",teal:"#008080",white:"#FFFFFF",yellow:"#FFFF00"},initComponent:function(){Styler.form.ColorField.superclass.initComponent.call(this);this.on({valid:this.colorField,scope:this});},isDark:function(hex){var dark=false;if(hex){var r=parseInt(hex.substring(1,3),16)/255;var g=parseInt(hex.substring(3,5),16)/255;var b=parseInt(hex.substring(5,7),16)/255;var brightness=(r*0.299)+(g*0.587)+(b*0.144);dark=brightness<0.5;}
return dark;},colorField:function(){var color=this.getValue();var hex=this.colorToHex(color)||"#ffffff";this.getEl().setStyle({"background":hex,"color":this.isDark(hex)?"#ffffff":"#000000"});},getHexValue:function(){return this.colorToHex(this.getValue());},colorToHex:function(color){var hex;if(color.match(/^#[0-9a-f]{6}$/i)){hex=color;}else{hex=this.cssColors[color.toLowerCase()]||null;}
return hex;}});Ext.reg("gx_colorfield",Styler.form.ColorField);Ext.namespace("Styler");Styler.PolygonSymbolizer=Ext.extend(Ext.Panel,{symbolizer:null,initComponent:function(){this.items=[{xtype:"gx_fillsymbolizer",symbolizer:this.symbolizer,listeners:{change:function(symbolizer){this.fireEvent("change",this.symbolizer);},scope:this}},{xtype:"gx_strokesymbolizer",symbolizer:this.symbolizer,listeners:{change:function(symbolizer){this.fireEvent("change",this.symbolizer);},scope:this}}];this.addEvents("change");Styler.PolygonSymbolizer.superclass.initComponent.call(this);}});Ext.reg('gx_polygonsymbolizer',Styler.PolygonSymbolizer);Ext.namespace("Styler");Styler.ColorManager=function(config){Ext.apply(this,config);};Ext.apply(Styler.ColorManager.prototype,{field:null,init:function(field){this.register(field);},destroy:function(){if(this.field){this.unregister(this.field);}},register:function(field){if(this.field){this.unregister(this.field);}
this.field=field;field.on({focus:this.fieldFocus,destroy:this.destroy,scope:this});},unregister:function(field){field.un("focus",this.fieldFocus,this);field.un("destroy",this.destroy,this);if(Styler.ColorManager.picker&&field==this.field){Styler.ColorManager.picker.un("pickcolor",this.setFieldValue,this);}
this.field=null;},fieldFocus:function(field){if(!Styler.ColorManager.pickerWin){Styler.ColorManager.picker=new Ext.ux.ColorPanel({hidePanel:false,autoHeight:false});Styler.ColorManager.pickerWin=new Ext.Window({title:"Color Picker",layout:"fit",closeAction:"hide",width:405,height:300,plain:true,items:Styler.ColorManager.picker});}
Styler.ColorManager.picker.purgeListeners();this.setPickerValue();Styler.ColorManager.picker.on({pickcolor:this.setFieldValue,scope:this});Styler.ColorManager.pickerWin.show();},setFieldValue:function(picker,color){if(this.field.isVisible()){this.field.setValue("#"+color);}},setPickerValue:function(){var field=this.field;var hex=field.getHexValue?field.getHexValue():field.getValue();if(hex){Styler.ColorManager.picker.setColor(hex.substring(1));}}});Styler.ColorManager.picker=null;Styler.ColorManager.pickerWin=null;Ext.namespace("Styler");Styler.TextSymbolizer=Ext.extend(Ext.Panel,{symbolizer:null,defaultSymbolizer:null,attributes:null,haloCache:null,border:false,layout:"form",initComponent:function(){if(!this.symbolizer){this.symbolizer={};}
Ext.applyIf(this.symbolizer,this.defaultSymbolizer);this.haloCache={};var defAttributesComboConfig={xtype:"combo",fieldLabel:"Label values",store:this.attributes,editable:false,triggerAction:"all",allowBlank:false,displayField:"name",valueField:"name",value:this.symbolizer.label&&this.symbolizer.label.replace(/^\${(.*)}$/,"$1"),listeners:{select:function(combo,record){this.symbolizer.label="${"+record.get("name")+"}";this.fireEvent("change",this.symbolizer);},scope:this},width:120};this.attributesComboConfig=this.attributesComboConfig||{};Ext.applyIf(this.attributesComboConfig,defAttributesComboConfig);this.labelWidth=80;this.items=[this.attributesComboConfig,{cls:"x-html-editor-tb",style:"background: transparent; border: none; padding: 0 0em 0.5em;",xtype:"toolbar",items:[{xtype:"gx_fontcombo",width:110,value:this.symbolizer.fontFamily,listeners:{select:function(combo,record){this.symbolizer.fontFamily=record.get("text");this.fireEvent("change",this.symbolizer);},scope:this}},{xtype:"tbtext",text:"Size: "},{xtype:"textfield",value:this.symbolizer.fontSize,width:30,listeners:{valid:function(field){this.symbolizer.fontSize=Number(field.getValue());this.fireEvent("change",this.symbolizer);},scope:this}},{enableToggle:true,cls:"x-btn-icon x-edit-bold",pressed:this.symbolizer.fontWeight==="bold",listeners:{toggle:function(button,pressed){this.symbolizer.fontWeight=pressed?"bold":"normal";this.fireEvent("change",this.symbolizer);},scope:this}},{enableToggle:true,cls:"x-btn-icon x-edit-italic",pressed:this.symbolizer.fontStyle==="italic",listeners:{toggle:function(button,pressed){this.symbolizer.fontStyle=pressed?"italic":"normal";this.fireEvent("change",this.symbolizer);},scope:this}}]},{xtype:"gx_fillsymbolizer",symbolizer:this.symbolizer,width:213,labelWidth:70,listeners:{change:function(symbolizer){this.fireEvent("change",this.symbolizer);},scope:this}},{xtype:"fieldset",title:"Halo",checkboxToggle:true,collapsed:!(this.symbolizer.haloRadius||this.symbolizer.haloColor||this.symbolizer.haloOpacity),autoHeight:true,labelWidth:50,items:[{xtype:"textfield",fieldLabel:"Size",anchor:"89%",value:this.symbolizer.haloRadius,listeners:{valid:function(field){this.symbolizer.haloRadius=field.getValue();this.fireEvent("change",this.symbolizer);},scope:this}},{xtype:"gx_fillsymbolizer",symbolizer:{fillColor:this.symbolizer.haloColor,fillOpacity:this.symbolizer.haloOpacity},width:190,labelWidth:60,listeners:{change:function(symbolizer){this.symbolizer.haloColor=symbolizer.fillColor;this.symbolizer.haloOpacity=symbolizer.fillOpacity;this.fireEvent("change",this.symbolizer);},scope:this}}],listeners:{collapse:function(){this.haloCache={haloRadius:this.symbolizer.haloRadius,haloColor:this.symbolizer.haloColor,haloOpacity:this.symbolizer.haloOpacity};delete this.symbolizer.haloRadius;delete this.symbolizer.haloColor;delete this.symbolizer.haloOpacity;this.fireEvent("change",this.symbolizer)},expand:function(){Ext.apply(this.symbolizer,this.haloCache);this.fireEvent("change",this.symbolizer);},scope:this}}];this.addEvents("change");Styler.TextSymbolizer.superclass.initComponent.call(this);}});Ext.reg('gx_textsymbolizer',Styler.TextSymbolizer);Ext.namespace("Styler");Styler.MultiSlider=Ext.extend(Ext.BoxComponent,{count:2,vertical:false,minValue:0,maxValue:100,increment:0,clickRange:[5,15],clickToChange:true,animate:true,dragging:false,initComponent:function(){if(this.values===undefined){this.values=new Array(this.count);this.values[0]=this.minValue;if(this.count>1){var delta=(this.maxValue-this.minValue)/(this.count-1);for(var i=1;i<this.count;++i){this.values[i]=this.minValue+(i*delta);}}}else{this.count=this.values.length;}
Styler.MultiSlider.superclass.initComponent.call(this);this.addEvents('beforechange','change','changecomplete','dragstart','drag','dragend');if(this.vertical){Ext.apply(this,Styler.MultiSlider.Vertical);}},onRender:function(){var autoThumbs=new Array(this.count);for(var i=0;i<this.count;++i){autoThumbs[i]={cls:"x-slider-thumb "+"x-slider-thumb"+i};}
this.autoEl={cls:'x-slider '+(this.vertical?'x-slider-vert':'x-slider-horz'),cn:{cls:'x-slider-end',cn:{cls:'x-slider-inner',cn:autoThumbs}}};Styler.MultiSlider.superclass.onRender.apply(this,arguments);this.endEl=this.el.first();this.innerEl=this.endEl.first();this.thumbs=new Array(this.count);for(var i=0;i<this.count;++i){this.thumbs[i]=new Ext.Element(this.innerEl.dom.childNodes[i]);}
this.halfThumb=(this.vertical?this.thumbs[0].getHeight():this.thumbs[0].getWidth())/2;this.initEvents();},initEvents:function(){for(var i=0,len=this.thumbs.length;i<len;++i){this.thumbs[i].addClassOnOver('x-slider-thumb-over');}
this.mon(this.el,'mousedown',this.onMouseDown,this);this.trackers=new Array(this.count);for(var i=0;i<this.count;++i){this.trackers[i]=this.initTracker(i);}},initTracker:function(index){var tracker=new Ext.dd.DragTracker({onBeforeStart:this.onBeforeDragStart.createDelegate(this,[index],true),onStart:this.onDragStart.createDelegate(this,[index],true),onDrag:this.onDrag.createDelegate(this,[index],true),onEnd:this.onDragEnd.createDelegate(this,[index],true),tolerance:3,autoStart:300});tracker.initEl(this.thumbs[index]);this.on('beforedestroy',tracker.destroy,tracker);return tracker;},onMouseDown:function(e){if(this.disabled||!this.clickToChange){return;}
var over=false;for(var i=0;i<this.count;++i){over=over||e.target==this.thumbs[i].dom;}
if(!over){var local=this.innerEl.translatePoints(e.getXY());this.onClickChange(local);}},onClickChange:function(local){if(local.top>this.clickRange[0]&&local.top<this.clickRange[1]){var target=Math.round(this.reverseValue(local.left));var index=this.getClosestIndex(target);var values=this.values.slice();values[index]=target;this.setValues(values,undefined,true);}},getClosestIndex:function(target){var index=0;var value=this.values[0];var minDiff=Math.abs(target-value);var diff;if(this.count>1&&(target>=value)){for(var i=1;i<this.count;++i){value=this.values[i];diff=Math.abs(target-value);if(diff<=minDiff){if(diff==minDiff){if(target>value){index=i;}}else{index=i;minDiff=diff;}}else{break;}}}
return index;},doSnap:function(value){if(!this.increment||this.increment==1||!value){return value;}
var newValue=value,inc=this.increment;var m=value%inc;if(m>0){if(m>(inc/2)){newValue=value+(inc-m);}else{newValue=value-m;}}
return newValue.constrain(this.minValue,this.maxValue);},afterRender:function(){Styler.MultiSlider.superclass.afterRender.apply(this,arguments);if(this.values!==undefined){var v,value,changed;var newValues=this.values.slice();for(var i=0;i<this.count;++i){value=newValues[i];v=this.normalizeValue(value);if(v!==value){newValues[i]=v;changed=true;}}
if(changed){this.setValues(newValues,false);}else{this.moveThumbs(this.translateValues(this.values),false);}}},getRatio:function(){var w=this.innerEl.getWidth();var v=this.maxValue-this.minValue;return v==0?w:(w/v);},normalizeValue:function(v){if(typeof v!='number'){v=parseInt(v);}
v=Math.round(v);v=this.doSnap(v);v=v.constrain(this.minValue,this.maxValue);return v;},setValues:function(values,animate,changeComplete){var changed=false;for(var i=0;i<this.count;++i){values[i]=this.normalizeValue(values[i]);if(values[i]!==this.values[i]){changed=true;}}
var changed=(values[this.count-1]!==this.values[this.count-1]);if(this.count>1){var next,current;for(var i=this.count-2;i>=0;--i){next=values[i+1];current=values[i];if(current>next){values[i]=next;}
changed=changed||(values[i]!==this.values);}}
if(changed&&this.fireEvent('beforechange',this,values,this.values)!==false){this.values=values;this.moveThumbs(this.translateValues(values),animate!==false);this.fireEvent('change',this,values);if(changeComplete){this.fireEvent('changecomplete',this,values);}}},translateValues:function(values){var ratio=this.getRatio();var len=values.length;var newValues=new Array(len);for(var i=0;i<len;++i){newValues[i]=(values[i]*ratio)-(this.minValue*ratio)-this.halfThumb;}
return newValues;},reverseValue:function(pos){var ratio=this.getRatio();return(pos+this.halfThumb+(this.minValue*ratio))/ratio;},moveThumbs:function(values,animate){if(!animate||this.animate===false){for(var i=0;i<this.count;++i){this.thumbs[i].setLeft(values[i]);}}else{for(var i=0;i<this.count;++i){this.thumbs[i].shift({left:values[i],stopFx:true,duration:.35});}}},onBeforeDragStart:function(e,index){return!this.disabled;},onDragStart:function(e,index){this.thumbs[index].addClass('x-slider-thumb-drag');this.dragging=true;this.dragStartValue=this.values[index];this.fireEvent('dragstart',this,index,e);},onDrag:function(e,index){var pos=this.innerEl.translatePoints(this.trackers[index].getXY());var newValues=this.values.slice();newValues[index]=Math.round(this.reverseValue(pos.left));this.setValues(newValues,false);this.fireEvent('drag',this,index,e);},onDragEnd:function(e,index){this.thumbs[index].removeClass('x-slider-thumb-drag');this.dragging=false;this.fireEvent('dragend',this,index,e);if(this.dragStartValue!=this.values[index]){this.fireEvent('changecomplete',this,this.values);}},onResize:function(w,h){this.innerEl.setWidth(w-(this.el.getPadding('l')+this.endEl.getPadding('r')));this.syncThumbs();},syncThumbs:function(){if(this.rendered){this.moveThumbs(this.translateValues(this.values));}},getValues:function(){return this.values;}});Ext.reg('gx_multislider',Styler.MultiSlider);Styler.MultiSlider.Vertical={onResize:function(w,h){this.innerEl.setHeight(h-(this.el.getPadding('t')+this.endEl.getPadding('b')));this.syncThumbs();},getRatio:function(){var h=this.innerEl.getHeight();var v=this.maxValue-this.minValue;return h/v;},moveThumbs:function(values,animate){if(!animate||this.animate===false){for(var i=0;i<this.count;++i){this.thumbs[i].setBottom(values[i]);}}else{for(var i=0;i<this.count;++i){this.thumbs[i].shift({bottom:values[i],stopFx:true,duration:.35});}}},onDrag:function(e,index){var pos=this.innerEl.translatePoints(this.trackers[index].getXY());var bottom=this.innerEl.getHeight()-pos.top;var newValues=this.values.slice();newValues[index]=Math.round(bottom/this.getRatio());this.setValues(newValues,false);this.fireEvent('drag',this,index,e);},onClickChange:function(local){if(local.left>this.clickRange[0]&&local.left<this.clickRange[1]){var bottom=this.innerEl.getHeight()-local.top;var target=Math.round(bottom/this.getRatio());var index=this.getClosestIndex(target);var values=this.values.slice();values[index]=target;this.setValues(values,undefined,true);}}};Ext.namespace("Styler");Styler.FilterBuilder=Ext.extend(Ext.Panel,{builderTypeNames:["any","all","none","not all"],allowedBuilderTypes:null,rowHeight:25,builderType:null,childFiltersPanel:null,customizeFilterOnInit:true,preComboText:"Match",postComboText:"of the following:",allowGroups:true,initComponent:function(){var defConfig={plain:true,border:false,defaultBuilderType:Styler.FilterBuilder.ANY_OF};Ext.applyIf(this,defConfig);if(this.customizeFilterOnInit){this.filter=this.customizeFilter(this.filter);}
this.builderType=this.getBuilderType();this.items=[{xtype:"panel",border:false,items:[{xtype:"panel",border:false,layout:"column",style:"margin-top: 0.25em;",defaults:{border:false},items:[{html:this.preComboText,cls:"x-form-item",style:"padding: 0.3em 0.5em 0;"},{items:[this.createBuilderTypeCombo()]},{html:this.postComboText,cls:"x-form-item",style:"padding: 0.3em 0.5em 0;"}]}]},this.createChildFiltersPanel()];this.bbar=this.createToolBar();this.addEvents("change");Styler.FilterBuilder.superclass.initComponent.call(this);},createToolBar:function(){var bar=[{text:"add condition",iconCls:"add",handler:function(){this.addCondition();},scope:this}];if(this.allowGroups){bar.push({text:"add group",iconCls:"add",handler:function(){this.addCondition(true);},scope:this});}
return bar;},getFilter:function(){var filter;if(this.filter){filter=this.filter.clone();if(filter instanceof OpenLayers.Filter.Logical){filter=this.cleanFilter(filter);}}
return filter;},cleanFilter:function(filter){if(filter instanceof OpenLayers.Filter.Logical){if(filter.type!==OpenLayers.Filter.Logical.NOT&&filter.filters.length===1){filter=this.cleanFilter(filter.filters[0]);}else{var child;for(var i=0,len=filter.filters.length;i<len;++i){child=filter.filters[i];if(child instanceof OpenLayers.Filter.Logical){filter.filters[i]=this.cleanFilter(child)}}}}
return filter;},customizeFilter:function(filter){if(!filter){filter=this.wrapFilter(this.createDefaultFilter());}else{filter=this.cleanFilter(filter);switch(filter.type){case OpenLayers.Filter.Logical.AND:case OpenLayers.Filter.Logical.OR:if(!filter.filters||filter.filters.length===0){filter.filters=[this.createDefaultFilter()];}else{var child;for(var i=0,len=filter.filters.length;i<len;++i){child=filter.filters[i];if(child instanceof OpenLayers.Filter.Logical){filter.filters[i]=this.customizeFilter(child);}}}
filter=new OpenLayers.Filter.Logical({type:OpenLayers.Filter.Logical.OR,filters:[filter]});break;case OpenLayers.Filter.Logical.NOT:if(!filter.filters||filter.filters.length===0){filter.filters=[new OpenLayers.Filter.Logical({type:OpenLayers.Filter.Logical.OR,filters:[this.createDefaultFilter()]})];}else{var child=filter.filters[0];if(child instanceof OpenLayers.Filter.Logical){if(child.type!==OpenLayers.Filter.Logical.NOT){var grandchild;for(var i=0,len=child.filters.length;i<len;++i){grandchild=child.filters[i];if(grandchild instanceof OpenLayers.Filter.Logical){child.filters[i]=this.customizeFilter(grandchild);}}}else{if(child.filters&&child.filters.length>0){filter=this.customizeFilter(child.filters[0]);}else{filter=this.wrapFilter(this.createDefaultFilter());}}}else{var type;if(this.defaultBuilderType===Styler.FilterBuilder.NOT_ALL_OF){type=OpenLayers.Logical.Filter.AND;}else{type=OpenLayers.Logical.Filter.OR;}
filter.filters=[new OpenLayers.Filter.Logical({type:type,filters:[child]})];}}
break;default:filter=this.wrapFilter(filter);}}
return filter;},createDefaultFilter:function(){return new OpenLayers.Filter.Comparison();},wrapFilter:function(filter){var type;if(this.defaultBuilderType===Styler.FilterBuilder.ALL_OF){type=OpenLayers.Filter.Logical.AND;}else{type=OpenLayers.Filter.Logical.OR;}
return new OpenLayers.Filter.Logical({type:OpenLayers.Filter.Logical.OR,filters:[new OpenLayers.Filter.Logical({type:type,filters:[filter]})]});},addCondition:function(group){var filter,type;if(group){type="gx_filterbuilder";filter=this.wrapFilter(this.createDefaultFilter());}else{type="gx_filterpanel";filter=this.createDefaultFilter();}
var newChild=this.newRow({xtype:type,filter:filter,attributes:this.attributes,customizeFilterOnInit:group&&false,listeners:{change:function(){this.fireEvent("change",this);},scope:this}});this.childFiltersPanel.add(newChild);this.filter.filters[0].filters.push(filter);this.childFiltersPanel.doLayout();},removeCondition:function(panel,filter){var parent=this.filter.filters[0].filters;if(parent.length>1){parent.remove(filter);this.childFiltersPanel.remove(panel);}
this.fireEvent("change",this);},createBuilderTypeCombo:function(){var types=this.allowedBuilderTypes||[Styler.FilterBuilder.ANY_OF,Styler.FilterBuilder.ALL_OF,Styler.FilterBuilder.NONE_OF];var numTypes=types.length;var data=new Array(numTypes);var type;for(var i=0;i<numTypes;++i){type=types[i];data[i]=[type,this.builderTypeNames[type]];}
return{xtype:"combo",store:new Ext.data.SimpleStore({data:data,fields:["value","name"]}),value:this.builderType,displayField:"name",valueField:"value",triggerAction:"all",mode:"local",listeners:{select:function(combo,record){this.changeBuilderType(record.get("value"));this.fireEvent("change",this);},scope:this},width:60};},changeBuilderType:function(type){if(type!==this.builderType){this.builderType=type;var child=this.filter.filters[0];switch(type){case Styler.FilterBuilder.ANY_OF:this.filter.type=OpenLayers.Filter.Logical.OR;child.type=OpenLayers.Filter.Logical.OR;break;case Styler.FilterBuilder.ALL_OF:this.filter.type=OpenLayers.Filter.Logical.OR;child.type=OpenLayers.Filter.Logical.AND;break;case Styler.FilterBuilder.NONE_OF:this.filter.type=OpenLayers.Filter.Logical.NOT;child.type=OpenLayers.Filter.Logical.OR;break;case Styler.FilterBuilder.NOT_ALL_OF:this.filter.type=OpenLayers.Filter.Logical.NOT;child.type=OpenLayers.Filter.Logical.AND;break;}}},createChildFiltersPanel:function(){this.childFiltersPanel=new Ext.Panel({border:false,defaults:{border:false}});var grandchildren=this.filter.filters[0].filters;var grandchild;for(var i=0,len=grandchildren.length;i<len;++i){grandchild=grandchildren[i];this.childFiltersPanel.add(this.newRow({xtype:(grandchild instanceof OpenLayers.Filter.Logical)?"gx_filterbuilder":"gx_filterpanel",filter:grandchild,attributes:this.attributes,listeners:{change:function(){this.fireEvent("change",this);},scope:this}}));}
return this.childFiltersPanel;},newRow:function(filterPanel){var panel=new Ext.Panel({layout:"column",defaults:{border:false},style:"padding: 0.5em 0.25em;",items:[{border:false,columnWidth:0.1,items:[{xtype:"button",tooltip:"remove condition",cls:'x-btn-icon',iconCls:"delete",handler:function(){this.removeCondition(panel,filterPanel.filter);},scope:this}]},{items:[filterPanel],border:false,columnWidth:0.9}]});return panel;},getBuilderType:function(){var type=this.defaultBuilderType;if(this.filter){var child=this.filter.filters[0];if(this.filter.type===OpenLayers.Filter.Logical.NOT){switch(child.type){case OpenLayers.Filter.Logical.OR:type=Styler.FilterBuilder.NONE_OF;break;case OpenLayers.Filter.Logical.AND:type=Styler.FilterBuilder.NOT_ALL_OF;break;}}else{switch(child.type){case OpenLayers.Filter.Logical.OR:type=Styler.FilterBuilder.ANY_OF;break;case OpenLayers.Filter.Logical.AND:type=Styler.FilterBuilder.ALL_OF;break;}}}
return type;}});Styler.FilterBuilder.ANY_OF=0;Styler.FilterBuilder.ALL_OF=1;Styler.FilterBuilder.NONE_OF=2;Styler.FilterBuilder.NOT_ALL_OF=3;Ext.reg('gx_filterbuilder',Styler.FilterBuilder);Ext.namespace("Styler");Styler.FeatureRenderer=Ext.extend(Ext.BoxComponent,{feature:undefined,symbolizer:OpenLayers.Feature.Vector.style["default"],symbolType:"Point",resolution:1,minWidth:20,minHeight:20,renderers:['SVG','VML','Canvas'],rendererOptions:null,pointFeature:undefined,lineFeature:undefined,polygonFeature:undefined,renderer:null,initComponent:function(){Styler.FeatureRenderer.superclass.initComponent.call(this);Ext.applyIf(this,{pointFeature:new OpenLayers.Feature.Vector(new OpenLayers.Geometry.Point(0,0)),lineFeature:new OpenLayers.Feature.Vector(new OpenLayers.Geometry.LineString([new OpenLayers.Geometry.Point(-8,-3),new OpenLayers.Geometry.Point(-3,3),new OpenLayers.Geometry.Point(3,-3),new OpenLayers.Geometry.Point(8,3)])),polygonFeature:new OpenLayers.Feature.Vector(new OpenLayers.Geometry.Polygon([new OpenLayers.Geometry.LinearRing([new OpenLayers.Geometry.Point(-8,-4),new OpenLayers.Geometry.Point(-6,-6),new OpenLayers.Geometry.Point(6,-6),new OpenLayers.Geometry.Point(8,-4),new OpenLayers.Geometry.Point(8,4),new OpenLayers.Geometry.Point(6,6),new OpenLayers.Geometry.Point(-6,6),new OpenLayers.Geometry.Point(-8,4)])]))});if(!this.feature){this.setFeature(null,{draw:false});}
this.addEvents("click");},initClickEvents:function(){this.el.removeAllListeners();this.el.on("click",this.onClick,this);},onClick:function(){this.fireEvent("click",this);},onRender:function(ct,position){if(!this.el){this.el=document.createElement("div");this.el.id=this.getId();}
if(!this.renderer||!this.renderer.supported()){this.assignRenderer();}
this.renderer.map={getResolution:(function(){return this.resolution;}).createDelegate(this)};this.drawFeature();Styler.FeatureRenderer.superclass.onRender.call(this,ct,position);},afterRender:function(){Styler.FeatureRenderer.superclass.afterRender.call(this);this.initClickEvents();},onResize:function(w,h){this.setRendererDimensions();Styler.FeatureRenderer.superclass.onResize.call(this,w,h);},setRendererDimensions:function(){var gb=this.feature.geometry.getBounds();var gw=gb.getWidth();var gh=gb.getHeight();var resolution=this.initialConfig.resolution;if(!resolution){resolution=Math.max(gw/this.width||0,gh/this.height||0)||1;}
this.resolution=resolution;var width=Math.max(this.width||this.minWidth,gw/resolution);var height=Math.max(this.height||this.minHeight,gh/resolution);var center=gb.getCenterPixel();var bhalfw=width*resolution/2;var bhalfh=height*resolution/2;var bounds=new OpenLayers.Bounds(center.x-bhalfw,center.y-bhalfh,center.x+bhalfw,center.y+bhalfh);this.renderer.setSize(new OpenLayers.Size(Math.round(width),Math.round(height)));this.renderer.setExtent(bounds,true);},assignRenderer:function(){for(var i=0,len=this.renderers.length;i<len;++i){var rendererClass=OpenLayers.Renderer[this.renderers[i]];if(rendererClass&&rendererClass.prototype.supported()){this.renderer=new rendererClass(this.el,this.rendererOptions);break;}}},setSymbolizer:function(symbolizer,options){this.symbolizer=symbolizer;if(!options||options.draw){this.drawFeature();}},setGeometryType:function(type,options){this.symbolType=type;this.setFeature(null,options);},setFeature:function(feature,options){this.feature=feature||this[this.symbolType.toLowerCase()+"Feature"];if(!options||options.draw){this.drawFeature();}},drawFeature:function(){this.renderer.clear();this.setRendererDimensions();this.renderer.drawFeature(this.feature,Ext.apply({},this.symbolizer));},update:function(options){options=options||{};if(options.feature){this.setFeature(options.feature,{draw:false});}else if(options.symbolType){this.setGeometryType(options.symbolType,{draw:false});}
if(options.symbolizer){this.setSymbolizer(options.symbolizer,{draw:false});}
this.drawFeature();}});Ext.reg('gx_renderer',Styler.FeatureRenderer);Ext.namespace("Styler");Styler.ScaleSlider=Ext.extend(Ext.Slider,{map:null,minValue:null,maxValue:null,updating:false,initComponent:function(){this.minValue=this.minValue||this.map.getZoomForResolution(this.map.maxResolution||this.map.baseLayer.maxResolution);this.maxValue=this.maxValue||this.map.getZoomForResolution(this.map.minResolution||this.map.baseLayer.minResolution);Styler.ScaleSlider.superclass.initComponent.call(this);this.on({"changecomplete":this.changeHandler,scope:this});this.map.events.register("zoomend",this,this.update);},getZoom:function(){return this.getValue();},getScale:function(){return OpenLayers.Util.getScaleFromResolution(this.map.getResolutionForZoom(this.getValue()),this.map.getUnits());},getResolution:function(){return this.map.getResolutionForZoom(this.getValue());},changeHandler:function(){if(!this.updating){this.map.zoomTo(this.getValue());}},update:function(){this.updating=true;this.setValue(this.map.getZoom());this.updating=false;},addToMap:function(options){options=options||{};this.addClass(options.cls||"gx-scaleslider");this.render(this.map.viewPortDiv);var stopEvent=function(e){e.stopEvent();}
this.getEl().on({"mousedown":{fn:stopEvent},"click":{fn:stopEvent}});}});Ext.reg('gx_scaleslider',Styler.ScaleSlider);Ext.namespace("Styler");Styler.FillSymbolizer=Ext.extend(Ext.FormPanel,{symbolizer:null,defaultSymbolizer:null,border:false,initComponent:function(){if(!this.symbolizer){this.symbolizer={};}
Ext.applyIf(this.symbolizer,this.defaultSymbolizer);this.items=[{xtype:"fieldset",title:"Fill",autoHeight:true,defaults:{width:100},items:[{xtype:"gx_colorfield",fieldLabel:"Color",name:"color",value:this.symbolizer["fillColor"],plugins:new Styler.ColorManager(),listeners:{valid:function(field){this.symbolizer["fillColor"]=field.getValue();this.fireEvent("change",this.symbolizer);},scope:this}},{xtype:"slider",fieldLabel:"Opacity",name:"opacity",value:(this.symbolizer["fillOpacity"]==null)?100:this.symbolizer["fillOpacity"]*100,isFormField:true,listeners:{changecomplete:function(slider,value){this.symbolizer["fillOpacity"]=value/100;this.fireEvent("change",this.symbolizer);},scope:this},plugins:[new Styler.SliderTip({getText:function(slider){return slider.getValue()+"%";}})]}]}];this.addEvents("change");Styler.FillSymbolizer.superclass.initComponent.call(this);}});Ext.reg('gx_fillsymbolizer',Styler.FillSymbolizer);Ext.namespace("Styler.Util");Styler.Util={getSymbolTypeFromRule:function(rule){var symbolizer=rule.symbolizer
if(symbolizer["Line"]||symbolizer["Point"]||symbolizer["Polygon"]){for(var type in symbolizer){if(type!="Text"){return type;}}}}}
Ext.namespace("Styler");Styler.RulePanel=Ext.extend(Ext.TabPanel,{symbolType:"Point",rule:null,attributes:null,nestedFilters:true,minScaleLimit:Math.pow(0.5,19)*40075016.68*39.3701*OpenLayers.DOTS_PER_INCH/256,maxScaleLimit:40075016.68*39.3701*OpenLayers.DOTS_PER_INCH/256,scaleLevels:20,scaleSliderTemplate:"{type} Scale 1:{scale}",modifyScaleTipContext:Ext.emptyFn,initComponent:function(){var defConfig={plain:true,border:false};Ext.applyIf(this,defConfig);if(!this.rule){this.rule=new OpenLayers.Rule({name:this.uniqueRuleName()});}
this.activeTab=0;this.textSymbolizer=new Styler.TextSymbolizer({symbolizer:this.rule.symbolizer["Text"],attributes:this.attributes,listeners:{change:function(symbolizer){this.fireEvent("change",this,this.rule);},scope:this}});this.scaleLimitPanel=new Styler.ScaleLimitPanel({maxScaleDenominator:this.rule&&(this.rule.maxScaleDenominator||undefined),limitMaxScale:!!(this.rule&&this.rule.maxScaleDenominator),minScaleDenominator:this.rule&&(this.rule.minScaleDenominator||undefined),limitMinScale:!!(this.rule&&this.rule.minScaleDenominator),scaleLevels:this.scaleLevels,scaleSliderTemplate:this.scaleSliderTemplate,modifyScaleTipContext:this.modifyScaleTipContext,listeners:{change:function(comp,min,max){this.rule.minScaleDenominator=min;this.rule.maxScaleDenominator=max;this.fireEvent("change",this,this.rule);},scope:this}});this.filterBuilder=new Styler.FilterBuilder({allowGroups:this.nestedFilters,filter:this.rule&&this.rule.filter,attributes:this.attributes,listeners:{change:function(builder){var filter=builder.getFilter();this.rule.filter=filter;this.fireEvent("change",this,this.rule)},scope:this}});this.items=[{title:"Labels",autoScroll:true,bodyStyle:{"padding":"10px"},items:[{xtype:"fieldset",title:"Label Features",autoHeight:true,checkboxToggle:true,collapsed:!this.rule.symbolizer["Text"],items:[this.textSymbolizer],listeners:{collapse:function(){delete this.rule.symbolizer["Text"];this.fireEvent("change",this,this.rule);},expand:function(){this.rule.symbolizer["Text"]=this.textSymbolizer.symbolizer;this.fireEvent("change",this,this.rule);},scope:this}}]}];if(Styler.Util.getSymbolTypeFromRule(this.rule)||this.symbolType){this.items=[{title:"Basic",autoScroll:true,items:[this.createHeaderPanel(),this.createSymbolizerPanel()]},this.items[0],{title:"Advanced",defaults:{style:{margin:"7px"}},autoScroll:true,items:[{xtype:"fieldset",title:"Limit by scale",checkboxToggle:true,collapsed:!(this.rule&&(this.rule.minScaleDenominator||this.rule.maxScaleDenominator)),autoHeight:true,items:[this.scaleLimitPanel],listeners:{collapse:function(){delete this.rule.minScaleDenominator;delete this.rule.maxScaleDenominator;this.fireEvent("change",this,this.rule)},expand:function(){var changed=false;if(this.scaleLimitPanel.limitMinScale){this.rule.minScaleDenominator=this.scaleLimitPanel.minScaleDenominator;changed=true;}
if(this.scaleLimitPanel.limitMaxScale){this.rule.maxScaleDenominator=this.scaleLimitPanel.maxScaleDenominator;changed=true;}
if(changed){this.fireEvent("change",this,this.rule)}},scope:this}},{xtype:"fieldset",title:"Limit by condition",checkboxToggle:true,collapsed:!(this.rule&&this.rule.filter),autoHeight:true,items:[this.filterBuilder],listeners:{collapse:function(){delete this.rule.filter;this.fireEvent("change",this,this.rule)},expand:function(){var changed=false;this.rule.filter=this.filterBuilder.getFilter();this.fireEvent("change",this,this.rule)},scope:this}}]}]};this.items[0].autoHeight=true;this.addEvents("change");this.on({tabchange:function(panel,tab){tab.doLayout();},scope:this});Styler.RulePanel.superclass.initComponent.call(this);},uniqueRuleName:function(){return OpenLayers.Util.createUniqueID("rule_");},createHeaderPanel:function(){this.symbolizerSwatch=new Styler.FeatureRenderer({symbolType:this.symbolType,symbolizer:this.rule.symbolizer[this.symbolType],isFormField:true,fieldLabel:"Symbol"});return{xtype:"form",border:false,labelAlign:"top",defaults:{border:false},style:{"padding":"0.3em 0 0 1em"},items:[{layout:"column",defaults:{border:false,style:{"padding-right":"1em"}},items:[{layout:"form",width:150,items:[{xtype:"textfield",fieldLabel:"Name",anchor:"95%",value:this.rule&&(this.rule.title||this.rule.name||""),listeners:{change:function(el,value){this.rule.title=value;this.fireEvent("change",this,this.rule);},scope:this}}]},{layout:"form",width:70,items:[this.symbolizerSwatch]}]}]};},createSymbolizerPanel:function(){return{xtype:"gx_"+this.symbolType.toLowerCase()+"symbolizer",symbolizer:this.rule.symbolizer[this.symbolType],pointGraphics:(this.symbolType==="Point")?this.pointGraphics:undefined,bodyStyle:{"padding":"10px"},border:false,labelWidth:70,defaults:{labelWidth:70},listeners:{change:function(symbolizer){this.symbolizerSwatch.setSymbolizer(symbolizer);this.fireEvent("change",this,this.rule);},scope:this}};}});Ext.reg('gx_rulepanel',Styler.RulePanel);Ext.namespace("Styler");Styler.PointSymbolizer=Ext.extend(Ext.Panel,{symbolizer:null,pointGraphics:[{display:"circle",value:"circle",mark:true},{display:"square",value:"square",mark:true},{display:"triangle",value:"triangle",mark:true},{display:"star",value:"star",mark:true},{display:"cross",value:"cross",mark:true},{display:"x",value:"x",mark:true},{display:"external"}],defaultSymbolizer:{"graphicName":"circle","rotation":0,"pointRadius":3,"fillColor":"#ffffff","fillOpacity":1,"strokeDashstyle":"solid","strokeOpacity":1},external:null,layout:"form",initComponent:function(){if(!this.symbolizer){this.symbolizer={};}
Ext.applyIf(this.symbolizer,this.defaultSymbolizer);this.external=!!this.symbolizer["externalGraphic"];this.markPanel=new Ext.Panel({border:false,collapsed:this.external,layout:"form",items:[{xtype:"gx_fillsymbolizer",symbolizer:this.symbolizer,labelWidth:this.labelWidth,labelAlign:this.labelAlign,listeners:{change:function(symbolizer){this.fireEvent("change",this.symbolizer);},scope:this}},{xtype:"gx_strokesymbolizer",symbolizer:this.symbolizer,labelWidth:this.labelWidth,labelAlign:this.labelAlign,listeners:{change:function(symbolizer){this.fireEvent("change",this.symbolizer);},scope:this}}]});this.urlField=new Ext.form.TextField({name:"url",fieldLabel:"URL",value:this.symbolizer["externalGraphic"],hidden:true,listeners:{change:function(field,value){this.symbolizer["externalGraphic"]=value;this.fireEvent("change",this.symbolizer);},scope:this},width:100});this.graphicPanel=new Ext.Panel({border:false,collapsed:!this.external,layout:"form",items:[this.urlField,{xtype:"slider",name:"opacity",fieldLabel:"Opacity",width:100,value:(this.symbolizer["graphicOpacity"]==null)?100:this.symbolizer["graphicOpacity"]*100,isFormField:true,listeners:{changecomplete:function(slider,value){this.symbolizer["graphicOpacity"]=value/100;this.fireEvent("change",this.symbolizer);},scope:this},plugins:[new Styler.SliderTip({getText:function(slider){return slider.getValue()+"%";}})],width:100}]});this.items=[{xtype:"combo",name:"mark",fieldLabel:"Symbol",store:new Ext.data.JsonStore({data:{root:this.pointGraphics},root:"root",fields:["value","display","preview",{name:"mark",type:"boolean"}]}),value:this.external?0:this.symbolizer["graphicName"],displayField:"display",valueField:"value",tpl:new Ext.XTemplate('<tpl for=".">'+'<div class="x-combo-list-item gx-pointsymbolizer-mark-item">'+'<tpl if="preview">'+'<img src="{preview}" alt="{display}"/>'+'</tpl>'+'<span>{display}</span>'+'</div></tpl>'),mode:"local",allowBlank:false,triggerAction:"all",editable:false,listeners:{select:function(combo,record){var mark=record.get("mark");var value=record.get("value");if(!mark){if(value){this.urlField.hide();this.urlField.getEl().up('.x-form-item').setDisplayed(false);this.symbolizer["externalGraphic"]=value;}else{this.urlField.show();this.urlField.getEl().up('.x-form-item').setDisplayed(true);}
if(!this.external){this.external=true;this.updateGraphicDisplay();}}else{if(this.external){this.external=false;delete this.symbolizer["externalGraphic"];this.updateGraphicDisplay();}
this.symbolizer["graphicName"]=value;}
this.fireEvent("change",this.symbolizer);},scope:this},width:100},{xtype:"textfield",name:"size",fieldLabel:"Size",value:this.symbolizer["pointRadius"],listeners:{change:function(field,value){this.symbolizer["pointRadius"]=value;this.fireEvent("change",this.symbolizer);},scope:this},width:100},{xtype:"textfield",name:"rotation",fieldLabel:"Rotation",value:this.symbolizer["rotation"],listeners:{change:function(field,value){this.symbolizer["rotation"]=value;this.fireEvent("change",this.symbolizer);},scope:this},width:100},this.markPanel,this.graphicPanel];this.addEvents("change");Styler.PointSymbolizer.superclass.initComponent.call(this);},updateGraphicDisplay:function(){if(this.external){this.markPanel.collapse();this.graphicPanel.expand();}else{this.graphicPanel.collapse();this.markPanel.expand();}}});Ext.reg('gx_pointsymbolizer',Styler.PointSymbolizer);Ext.namespace("Styler");Styler.dispatch=function(functions,complete,scope){var requests=functions.length;var responses=0;var storage={};function respond(){++responses;if(responses===requests){complete.call(scope,storage);}}
function trigger(index){window.setTimeout(function(){functions[index].apply(scope,[respond,storage]);});}
for(var i=0;i<requests;++i){trigger(i);}};Styler.SLDManager=OpenLayers.Class({map:null,layerData:null,initialize:function(map){this.map=map;var layer;this.layers=[];this.layerData={};for(var i=0;i<this.map.layers.length;++i){layer=this.map.layers[i];if(layer instanceof OpenLayers.Layer.WMS){this.layers.push(layer);}}},loadAll:function(callback){var num=this.layers.length;var loaders=new Array(num);for(var i=0;i<num;++i){loaders[i]=this.createLoader(this.layers[i]);}
Styler.dispatch(loaders,callback);},createLoader:function(layer){return(function(done){this.loadSld(layer,layer.params["STYLES"],done);}).createDelegate(this);},getUrl:function(layer,styleName){var url;if(layer instanceof OpenLayers.Layer.WMS){url=layer.url.split("?")[0].replace("/wms","/rest/styles/"+styleName);}
return url;},loadSld:function(layer,styleName,callback){Ext.Ajax.request({url:this.getUrl(layer,styleName)+'.sld',method:"GET",success:function(request){var sld=new OpenLayers.Format.SLD().read(request.responseXML.documentElement?request.responseXML:request.responseText);for(var namedLayer in sld.namedLayers){break;}
this.layerData[layer.id]={style:sld.namedLayers[namedLayer].userStyles[0],sld:sld,styleName:styleName};callback(this.layerData[layer.id]);},scope:this});},saveSld:function(layer,callback,scope){Ext.Ajax.request({url:this.getUrl(layer,this.layerData[layer.id].styleName),method:"PUT",headers:{'Content-Type':'application/vnd.ogc.sld+xml'},xmlData:new OpenLayers.Format.SLD().write(this.layerData[layer.id].sld),success:function(request){callback.call(scope||this,request);}});},getStyle:function(layer){var data=this.layerData[layer.id];return data&&data.style;}});Ext.namespace("Styler");Styler.LegendPanel=Ext.extend(Ext.Panel,{symbolType:"Point",rules:null,untitledPrefix:"Untitled ",clickableSymbol:false,clickableTitle:false,selectOnClick:false,enableDD:true,selectedRule:null,untitledCount:0,initComponent:function(){var defConfig={plain:true,rules:[]};Ext.applyIf(this,defConfig);this.rulesContainer=new Ext.Panel({border:false});this.items=[this.rulesContainer];this.addEvents("titleclick","symbolclick","ruleclick","ruleselected","ruleunselected","rulemoved");Styler.LegendPanel.superclass.initComponent.call(this);this.update();},addRuleEntry:function(rule){this.rulesContainer.add(this.createRuleEntry(rule));},selectRuleEntry:function(rule){var newSelection=rule!=this.selectedRule;if(this.selectedRule){this.unselect();}
if(newSelection){var ruleEntry=this.rulesContainer.items.get(this.rules.indexOf(rule));ruleEntry.body.addClass("x-grid3-row-selected");this.selectedRule=rule;this.fireEvent("ruleselected",this,rule);}},unselect:function(){this.rulesContainer.items.each(function(item,i){if(this.rules[i]==this.selectedRule){item.body.removeClass("x-grid3-row-selected");this.selectedRule=null;this.fireEvent("ruleunselected",this,this.rules[i]);}},this);},createRuleEntry:function(rule){var symbolType=Styler.Util.getSymbolTypeFromRule(rule)||(rule[this.symbolType]?this.symbolType:"Point");return{xtype:"panel",layout:"column",border:false,bodyStyle:this.selectOnClick?{cursor:"pointer"}:undefined,defaults:{border:false},items:[{xtype:"gx_renderer",symbolType:symbolType,symbolizer:rule.symbolizer[symbolType]||rule.symbolizer,style:this.clickableSymbol?{cursor:"pointer"}:undefined,listeners:{click:function(){if(this.clickableSymbol){this.fireEvent("symbolclick",this,rule);this.fireEvent("ruleclick",this,rule);}},scope:this}},{cls:"x-form-item",style:"padding: 0.2em 0.5em 0;",bodyStyle:Ext.applyIf({background:"transparent"},this.clickableTitle?{cursor:"pointer"}:undefined),html:this.getRuleTitle(rule),listeners:{render:function(comp){this.clickableTitle&&comp.getEl().on({click:function(){this.fireEvent("titleclick",this,rule);this.fireEvent("ruleclick",this,rule);},scope:this});},scope:this}}],listeners:{render:function(comp){this.selectOnClick&&comp.getEl().on({click:function(comp){this.selectRuleEntry(rule);},scope:this});if(this.enableDD==true){this.addDD(comp);}},scope:this}}},addDD:function(component){var cursor=component.body.getStyle("cursor");var dd=new Ext.Panel.DD(component);component.body.setStyle("cursor",cursor||"move");var panel=this;var dropZone=new Ext.dd.DropTarget(component.getEl(),{notifyDrop:function(ddSource){var source=Ext.getCmp(ddSource.getEl().id);var target=Ext.getCmp(this.getEl().id);if(source&&target&&source!=target){var sourceCt=source.ownerCt;var targetCt=target.ownerCt;if(sourceCt==targetCt){panel.moveRule(sourceCt.items.indexOf(source),targetCt.items.indexOf(target));}}}});},update:function(){if(this.rulesContainer.items){var comp;for(var i=this.rulesContainer.items.length-1;i>=0;--i){comp=this.rulesContainer.getComponent(i);this.rulesContainer.remove(comp,true);}}
var len=this.rules.length;var entry;for(var i=0;i<len;++i){this.addRuleEntry(this.rules[i]);}
this.doLayout();},moveRule:function(sourcePos,targetPos){var srcRule=this.rules[sourcePos];this.rules.splice(sourcePos,1);this.rules.splice(targetPos,0,srcRule);this.update();this.fireEvent("rulemoved",this,srcRule);},getRuleTitle:function(rule){return rule.title||rule.name||(this.untitledPrefix+(++this.untitledCount));}});Ext.reg('gx_legendpanel',Styler.LegendPanel);Ext.namespace("Styler");Styler.ScaleSliderTip=Ext.extend(Styler.SliderTip,{template:'<div>Zoom Level: {zoom}</div>'+'<div>Resolution: {resolution}</div>'+'<div>Scale: 1 : {scale}</div>',compiledTemplate:null,init:function(slider){this.compiledTemplate=new Ext.Template(this.template);Styler.ScaleSliderTip.superclass.init.call(this,slider);},getText:function(slider){var data={zoom:slider.getZoom(),resolution:slider.getResolution(),scale:Math.round(slider.getScale())};return this.compiledTemplate.apply(data);}});Ext.namespace("Styler.data");Styler.data.AttributesStore=function(c){Styler.data.AttributesStore.superclass.constructor.call(this,Ext.apply(c,{proxy:c.proxy||(!c.data?new Ext.data.HttpProxy({url:c.url,disableCaching:false,method:"GET"}):undefined),reader:new Styler.data.AttributesReader(c,c.fields||["name","type"])}));};Ext.extend(Styler.data.AttributesStore,Ext.data.Store);Styler.SchemaManager=OpenLayers.Class({map:null,attributesStores:null,matchGeomProperty:/^gml:(Multi)?(Point|LineString|Polygon|Curve|Surface|Geometry)PropertyType$/,initialize:function(map){this.map=map;this.attributesStores={};var layer;for(var i=0;i<this.map.layers.length;++i){layer=this.map.layers[i];if(layer instanceof OpenLayers.Layer.WMS){this.attributesStores[layer.id]=new Styler.data.AttributesStore({url:layer.url.split("?")[0].replace("/wms","/wfs"),baseParams:{version:"1.1.1",request:"DescribeFeatureType",typename:layer.params["LAYERS"]}});}}},loadAll:function(callback){var loaders=[];for(var id in this.attributesStores){loaders.push(this.createLoader(this.attributesStores[id]));}
Styler.dispatch(loaders,callback);},createLoader:function(store){return function(done){store.load({callback:done});};},getGeometryName:function(layer){var store=this.attributesStores[layer.id];var index=store.find("type",this.matchGeomProperty);var name;if(index>-1){name=store.getAt(index).get("name");}
return name;},getSymbolType:function(layer){var store=this.attributesStores[layer.id];var index=store.find("type",this.matchGeomProperty);var type;if(index>-1){var match=store.getAt(index).get("type").match(this.matchGeomProperty);type=({"Point":"Point","LineString":"Line","Polygon":"Polygon","Curve":"Line","Surface":"Polygon"})[match[2]];}
return type;}});Ext.namespace("Styler");Styler.LineSymbolizer=Ext.extend(Ext.Panel,{symbolizer:null,initComponent:function(){this.items=[{xtype:"gx_strokesymbolizer",symbolizer:this.symbolizer,listeners:{change:function(symbolizer){this.fireEvent("change",this.symbolizer);},scope:this}}];this.addEvents("change");Styler.LineSymbolizer.superclass.initComponent.call(this);}});Ext.reg('gx_linesymbolizer',Styler.LineSymbolizer);Ext.namespace("Styler");Styler.MultiSliderTip=Ext.extend(Ext.Tip,{hover:true,dragging:false,minWidth:10,offsets:[0,-10],init:function(slider){slider.on('dragstart',this.onSlide,this);slider.on('drag',this.onSlide,this);slider.on('dragend',this.hide,this);slider.on('destroy',this.destroy,this);if(this.hover){slider.on('render',this.registerThumbListeners,this);}
this.slider=slider;},registerThumbListeners:function(){for(var i=0,len=this.slider.thumbs.length;i<len;++i){this.slider.thumbs[i].on({"mouseover":this.createHoverListener(i),"mouseout":function(){if(!this.dragging){this.hide.apply(this,arguments);}},scope:this});}},createHoverListener:function(index){return(function(){this.onSlide(this.slider,index);this.dragging=false;}).createDelegate(this);},onSlide:function(slider,index){this.dragging=true;this.show();this.body.update(this.getText(slider,index));this.doAutoWidth();this.el.alignTo(slider.thumbs[index],'b-t?',this.offsets);},getText:function(slider,index){return slider.getValues()[index];}});Ext.namespace("Styler");Styler.ScaleLimitPanel=Ext.extend(Ext.Panel,{maxScaleLimit:40075016.68*39.3701*OpenLayers.DOTS_PER_INCH/256,limitMaxScale:true,maxScaleDenominator:undefined,minScaleLimit:Math.pow(0.5,19)*40075016.68*39.3701*OpenLayers.DOTS_PER_INCH/256,limitMinScale:true,minScaleDenominator:undefined,scaleLevels:20,scaleSliderTemplate:"{type} Scale 1:{scale}",modifyScaleTipContext:Ext.emptyFn,scaleFactor:null,changing:false,border:false,initComponent:function(){this.layout="column";this.defaults={border:false,bodyStyle:"margin: 0 5px;"};this.bodyStyle={padding:"5px"};this.scaleSliderTemplate=new Ext.Template(this.scaleSliderTemplate);Ext.applyIf(this,{minScaleDenominator:this.minScaleLimit,maxScaleDenominator:this.maxScaleLimit});this.scaleFactor=Math.pow(this.maxScaleLimit/this.minScaleLimit,1/(this.scaleLevels-1));this.scaleSlider=new Styler.MultiSlider({vertical:true,height:100,listeners:{changecomplete:this.updateScaleValues,render:function(slider){slider.thumbs[0].setVisible(this.limitMaxScale);slider.thumbs[1].setVisible(this.limitMinScale);slider.setDisabled(!this.limitMinScale&&!this.limitMaxScale);},scope:this},plugins:[new Styler.MultiSliderTip({getText:(function(slider,index){var values=slider.getValues();var scales=this.sliderValuesToScale(values);var data={scale:String(scales[index]),zoom:(values[index]*(this.scaleLevels/100)).toFixed(1),type:(index===0)?"Max":"Min",zoomType:(index===0)?"Min":"Max"};this.modifyScaleTipContext(this,data);return this.scaleSliderTemplate.apply(data);}).createDelegate(this)})]});this.maxScaleInput=new Ext.form.TextField({width:100,fieldLabel:"1",value:Math.round(this.maxScaleDenominator),disabled:!this.limitMaxScale,listeners:{valid:function(field){var value=Number(field.getValue());var limit=Math.round(this.maxScaleLimit);if(value>limit){field.setValue(limit);}else if(value<this.minScaleDenominator){field.setValue(this.minScaleDenominator);}else{this.maxScaleDenominator=value;this.updateSliderValues();}},scope:this}});this.minScaleInput=new Ext.form.TextField({width:100,fieldLabel:"1",value:Math.round(this.minScaleDenominator),disabled:!this.limitMinScale,listeners:{valid:function(field){var value=Number(field.getValue());var limit=Math.round(this.minScaleLimit);if(value<limit){field.setValue(limit);}else if(value>this.maxScaleDenominator){field.setValue(this.maxScaleDenominator);}else{this.minScaleDenominator=value;this.updateSliderValues();}},scope:this}});this.items=[this.scaleSlider,{xtype:"panel",layout:"form",defaults:{border:false},items:[{labelWidth:90,layout:"form",width:150,items:[{xtype:"checkbox",checked:!!this.limitMinScale,fieldLabel:"Min scale limit",listeners:{check:function(box,checked){this.limitMinScale=checked;var slider=this.scaleSlider;var values=slider.getValues();values[1]=100;slider.setValues(values);slider.thumbs[1].setVisible(checked);this.minScaleInput.setDisabled(!checked);this.updateScaleValues(slider,values);slider.setDisabled(!this.limitMinScale&&!this.limitMaxScale);},scope:this}}]},{labelWidth:10,layout:"form",items:[this.minScaleInput]},{labelWidth:90,layout:"form",items:[{xtype:"checkbox",checked:!!this.limitMaxScale,fieldLabel:"Max scale limit",listeners:{check:function(box,checked){this.limitMaxScale=checked;var slider=this.scaleSlider;var values=slider.getValues();values[0]=0;slider.setValues(values);slider.thumbs[0].setVisible(checked);this.maxScaleInput.setDisabled(!checked);this.updateScaleValues(slider,values);slider.setDisabled(!this.limitMinScale&&!this.limitMaxScale);},scope:this}}]},{labelWidth:10,layout:"form",items:[this.maxScaleInput]}]}];this.addEvents("change");Styler.ScaleLimitPanel.superclass.initComponent.call(this);},updateScaleValues:function(slider,values){if(!this.changing){var resetSlider=false;if(!this.limitMaxScale){if(values[0]>0){values[0]=0;resetSlider=true;}}
if(!this.limitMinScale){if(values[1]<100){values[1]=100;resetSlider=true;}}
if(resetSlider){slider.setValues(values);}else{var scales=this.sliderValuesToScale(values);var max=scales[0];var min=scales[1];this.changing=true;this.minScaleInput.setValue(min);this.maxScaleInput.setValue(max);this.changing=false;this.fireEvent("change",this,(this.limitMinScale)?min:undefined,(this.limitMaxScale)?max:undefined);}}},updateSliderValues:function(){if(!this.changing){var min=this.minScaleDenominator;var max=this.maxScaleDenominator;var values=this.scaleToSliderValues([max,min]);this.changing=true;this.scaleSlider.setValues(values);this.changing=false;this.fireEvent("change",this,(this.limitMinScale)?min:undefined,(this.limitMaxScale)?max:undefined);}},sliderValuesToScale:function(values){var interval=100/(this.scaleLevels-1);return[Math.round(Math.pow(this.scaleFactor,(100-values[0])/interval)*this.minScaleLimit),Math.round(Math.pow(this.scaleFactor,(100-values[1])/interval)*this.minScaleLimit)];},scaleToSliderValues:function(scales){var interval=100/(this.scaleLevels-1);return[100-(interval*Math.log(scales[0]/this.minScaleLimit)/Math.log(this.scaleFactor)),100-(interval*Math.log(scales[1]/this.minScaleLimit)/Math.log(this.scaleFactor))];}});Ext.reg('gx_scalelimitpanel',Styler.ScaleLimitPanel);Ext.namespace("Styler.data");Styler.data.AttributesReader=function(meta,recordType){meta=meta||{};if(!meta.format){meta.format=new OpenLayers.Format.WFSDescribeFeatureType();}
Styler.data.AttributesReader.superclass.constructor.call(this,meta,recordType||meta.fields);};Ext.extend(Styler.data.AttributesReader,Ext.data.DataReader,{read:function(request){var data=request.responseXML;if(!data||!data.documentElement){data=request.responseText;}
return this.readRecords(data);},readRecords:function(data){var attributes;if(data instanceof Array){attributes=data;}else{attributes=this.meta.format.read(data);}
var recordType=this.recordType;var fields=recordType.prototype.fields;var numFields=fields.length;var attr,values,name,record,ignore,matches,value,records=[];for(var i=0,len=attributes.length;i<len;++i){ignore=false;attr=attributes[i];values={};for(var j=0;j<numFields;++j){name=fields.items[j].name;value=attr[name];if(this.meta.ignore&&this.meta.ignore[name]){matches=this.meta.ignore[name];if(typeof matches=="string"){ignore=(matches===value);}else if(matches instanceof Array){ignore=(matches.indexOf(value)>-1);}else if(matches instanceof RegExp){ignore=(matches.test(value));}
if(ignore){break;}}
values[name]=attr[name];}
if(!ignore){records[records.length]=new recordType(values);}}
return{success:true,records:records,totalRecords:records.length};}});