cankorusa

WMSLayer (WMSServiceDescripion/WMSLayerDescription) programatically

Discussion created by cankorusa on Feb 8, 2011
Hi,

I have a generic WMS server with the GetCapabilities turned off. I know the service info and the layer info for layers that I want to display in ArcMap via my addin. I can confirm that the GetMap works as per my info.

Any ideas on how to create my layer in the java API? It seems that I would need to create the WMSLayerDescription programatically (and possibly the WMSServiceDescription) but I can't seem to find an interface to let me do that. By default the com.esri.arcgis.gisclient makes a getcaps call to the server and I need to get around that.

Any code samples would be greatly appreciated. My current code is located below...

-Jerry
/// code snippet
IWMSGroupLayer wmsMapLayer = new WMSMapLayer();
    
PropertySet propSet = new PropertySet();

//REQUEST=GetCapabilities&VERSION=1.3.0&SERVICE=WMS
propSet.setProperty("URL", "http://"+serverPost.getmServer()+":"+serverPost.getmPort()+"/mapserver?");
    
 WMSConnectionName connName = new WMSConnectionName();
 connName.setConnectionProperties(propSet);
 IDataLayer dataLayer =  new com.esri.arcgis.carto.IDataLayerProxy (wmsMapLayer);
 dataLayer.connect(connName);

//want to avoid this... I know what the service info is and want to populate automatically ... I don't want a getcapabilities to go off to the server...    
 IWMSServiceDescription serviceDesc  = wmsMapLayer.getWMSServiceDescription();
 ILayer newLayer = null;
         
for(int i = 0;i < serviceDesc.getLayerDescriptionCount();i++){
    // I know what the layer description is and I want to generate this myself in code         
    IWMSLayerDescription layerDesc = serviceDesc.getLayerDescription(i);
           
           
 if (layerDesc.getLayerDescriptionCount() ==0){
     IWMSLayer newWMSLayer = wmsMapLayer.createWMSLayer(layerDesc);
 newLayer = new com.esri.arcgis.carto.ILayerProxy (newWMSLayer);               
  }else{
 // this traverses through all of the layers to find the one we want
   for (int s=0; s <= layerDesc.getLayerDescriptionCount();s++){
   IWMSLayer newWMSLayer = wmsMapLayer.createWMSLayer(layerDesc.getLayerDescription(s));              
   newLayer = new com.esri.arcgis.carto.ILayerProxy (newWMSLayer);
            
   //if (newLayer.getName().equalsIgnoreCase("1metercalif")){
   if (newLayer.getName().equalsIgnoreCase(title)){
   wmsMapLayer.clear();
   wmsMapLayer.insertLayer(newLayer,0);
   break;
            }
        }
     } 
 }
ILayer layer = new com.esri.arcgis.carto.ILayerProxy (wmsMapLayer);
layer.setName(serviceDesc.getWMSTitle());
      
mxDocument.getFocusMap().addLayer(new com.esri.arcgis.carto.ILayerProxy (layer) );
       
 IActiveView activeView = mxDocument.getActiveView();
activeView.refresh();

Outcomes