HSLayers.namespace("HSLayers.Control","HSLayers.Control.ArgParser");HSLayers.Control.ArgParser=OpenLayers.Class(OpenLayers.Control.ArgParser,{layer:null,handlers:{},scope:null,setMap:function(map){OpenLayers.Control.ArgParser.prototype.setMap.apply(this,arguments);var markers=[];var args=OpenLayers.Util.getParameters();if(args.markers){args.markers=args.markers.toString();var markersUnParsed=args.markers.replace(/^\[/,"").replace(/\]$/,"").split(";");for(var i=0;i<markersUnParsed.length;i++){var attrs=markersUnParsed[i].split("@");var lon=null;var lat=null;var title=null;var desc=null;for(var j=0;j<attrs.length;j++){var val=attrs[j].split("=");switch(val[0]){case"title":title=val[1];break;case"desc":desc=val[1];break;case"lon":lon=val[1];break;case"lat":lat=val[1];break;default:break;}}
markers.push({'title':title,'desc':desc,'lonlat':new OpenLayers.LonLat(lon,lat)});}}
if(markers.length){this.renderMarkers(markers);}
if(args.vectors){args.vectors=args.vectors.toString();this.renderVectors(args.vectors);}
if(args.ows){this.renderOWS(args.ows);}
if(args.cgimapserver){this.renderCgiMapServer(args.cgimapserver);}},renderCgiMapServer:function(mapServerParams){var json=new OpenLayers.Format.JSON();var params=json.read(mapServerParams);if(params.map&&params.mapServer&&params.getLayersUrl&&params.name){var options={ratio:1};if(params.projection){options.projections=[params.projection]}
var layer=new HSLayers.Layer.MapServer.CgiMapServer(params.name,params.mapServer,{map:params.map,map_imagetype:params.format,transparent:"true"},options);layer.getLayersUrl=params.getLayersUrl;this.map.addLayer(layer);}},renderMarkers:function(markers){if(this.layer){for(var i=0;i<markers.length;i++){var icon=OpenLayers.Util.getImagesLocation()+"icons/blue.png";var geometry=new OpenLayers.Geometry.Point(markers[i].lonlat.lon,markers[i].lonlat.lat)
if(this.displayProjection){geometry=geometry.transform(this.displayProjection,this.map.projection);}
var style=OpenLayers.Util.extend(OpenLayers.Feature.Vector.style['default'],{externalGraphic:icon,fillOpacity:1,pointRadius:12});var feature=new OpenLayers.Feature.Vector(geometry,{title:markers[i].title,description:markers[i].desc},style);feature.closeBox=true;feature.popupClass=HSLayers.Popup;feature.data.popupContentHTML=feature.data.description;this.layer.addFeatures([feature]);}
this.layer.redraw();}},renderVectors:function(wkt){var wktFormat=new OpenLayers.Format.WKT();if(this.layer){this.map.setLayerZIndex(this.layer,this.map.layers.length+1);this.layer.addFeatures(wktFormat.read(wkt));}},renderOWS:function(url){url=unescape(url.replace("[","").replace("]",""));var params=OpenLayers.Util.getParameters(url)
if(params.layers){this.addLayer(url,params);}
else{if(this.handlers.ows){this.handlers.ows.apply(this.scope,[url]);}
else{var cls=(url.toLowerCase().search("service=wfs")>-1?HSLayers.OWS.WFS:HSLayers.OWS.WMS);var ows=new cls(this.map,{useTiles:this.wmsUseTiles,onLayersAddedDone:function(){},asSingleLayers:false,findTabPanel:true,owsUrl:url});}}},addLayer:function(url,params){var name=(params.name?params.name:params.layers.toString().replace(/ /g,","));if(this.map.getLayersByName(name).length>0){this.map.getLayersByName(name)[0].setVibility(true);}
else{if(params.service.toLowerCase()=="wms"){var layers=params.layers.toString().replace(/ /g,",");var layer=new OpenLayers.Layer.WMS(layers,url.split("?")[0],{layers:layers,transparent:true},{isBaseLayer:false,singleTile:params.singleTile,displayInLayerSwitcher:true});this.map.addLayer(layer);}
else if(params.service.toLowerCase()=="wfs"){var features=params.features.toString().replace(/ /g,",");this.map.addLayer(new OpenLayers.Layer.WFS(name,url.split("?")[0],{features:features}));}}},configureLayers2:function(){if(this.layers.length==this.map.layers.length){var args=OpenLayers.Util.getParameters();for(var i=0,len=this.map.layers.length;i<len;i++){var layer=this.map.layers[i];if(layer.CLASS_NAME.search("HSLayers.Layer.MapServer")>-1){if(args["msLayer"+i]){var msLayers=args["msLayer"+i];layer.setInitialVisibleLayers(msLayers);}}}
this.configureLayers();}},CLASS_NAME:"HSLayers.Control.ArgParser"});
