public IGroupLayer getGroupLayerName(com.esri.arcgis.carto.Map map, AGSConnection agsconn){ ILayer layer = null; try { UID id = (UID) agsconn.getContext().createObject(UID.getClsid()); id.setValue(com.esri.arcgis.carto.IGroupLayer.class); // getLayers(UID, true) uses recursion to the get the layer name in a GroupLayer IEnumLayer enumLayer = map.getLayers(id, true); enumLayer.reset(); layer = enumLayer.next(); while(!(layer == null)){ if(layer.getName().equalsIgnoreCase("Transportation")){ break; } else { layer = enumLayer.next(); } } } catch (AutomationException ae) { ae.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } try { System.out.println(layer.getName()); } catch (AutomationException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } return (IGroupLayer) layer; }
public IRasterLayer getRasterLayerName(com.esri.arcgis.carto.Map map, AGSConnection agsconn){ ILayer layer = null; try { UID id = (UID) agsconn.getContext().createObject(UID.getClsid()); id.setValue(com.esri.arcgis.carto.IRasterLayer.class); // getLayers(UID, true) uses recursion to the get the layer name in a GroupLayer IEnumLayer enumLayer = map.getLayers(id, true); enumLayer.reset(); layer = enumLayer.next(); while(!(layer == null)){ if(layer.getName().equalsIgnoreCase("Image")){ break; } else { layer = enumLayer.next(); } } } catch (AutomationException ae) { ae.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } return (IRasterLayer) layer; }
public ILayer getGroupLayerName(com.esri.arcgis.carto.Map map, AGSConnection agsconn){ ILayer layer = null; try { UID id = (UID) agsconn.getContext().createObject(UID.getClsid()); id.setValue(com.esri.arcgis.carto.IGroupLayer.class); // getLayers(UID, true) uses recursion to the get the layer name in a GroupLayer IEnumLayer enumLayer = map.getLayers(id, true); enumLayer.reset(); layer = enumLayer.next(); while(!(layer == null)){ if(layer instanceof MosaicLayer){ if(layer.getName().equalsIgnoreCase("Aerial2011Sep_2011Oct_Ortho")){ System.out.println(((MosaicLayer) layer).getName()); break; } else { layer = enumLayer.next(); } } else { System.out.println(layer.getName() + " is not an instance of MosaicLayer"); layer = enumLayer.next(); } } } catch (AutomationException ae) { ae.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } return (ILayer) layer; }
INFO: Server startup in 23074 ms
com.esri.arcgis.carto.GroupLayer Transportation // yes! this is one of the group layers
Jul 29, 2013 3:46:51 PM com.sun.faces.application.ActionListenerImpl processAction
SEVERE: java.lang.ClassCastException: A COM object reference via iid 34c20002-4d3c-11d0-92d8-00805f7c28b0 does not support COM interface edad6644-1810-11d1-86ae-0000f8751720
javax.faces.el.EvaluationException: java.lang.ClassCastException: A COM object reference via iid 34c20002-4d3c-11d0-92d8-00805f7c28b0 does not support COM interface edad6644-1810-11d1-86ae-0000f8751720
at javax.faces.component.MethodBindingMethodExpressionAdapter.invoke(MethodBindingMethodExpressionAdapter.java:98)
at com.sun.faces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:98)
at javax.faces.component.UICommand.broadcast(UICommand.java:311)
at javax.faces.component.UIViewRoot.broadcastEvents(UIViewRoot.java:781)
at javax.faces.component.UIViewRoot.processApplication(UIViewRoot.java:1246)
at com.sun.faces.lifecycle.InvokeApplicationPhase.execute(InvokeApplicationPhase.java:77)
at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:97)
at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:114)
at javax.faces.webapp.FacesServlet.service(FacesServlet.java:308)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:222)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:171)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:99)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:936)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:407)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1004)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:589)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:312)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:895)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:918)
at java.lang.Thread.run(Thread.java:662)
Caused by: java.lang.ClassCastException: A COM object reference via iid 34c20002-4d3c-11d0-92d8-00805f7c28b0 does not support COM interface edad6644-1810-11d1-86ae-0000f8751720
at com.esri.arcgis.interop.Dispatch.c(Unknown Source)
at com.esri.arcgis.interop.Dispatch.vtblInvoke(Unknown Source)
at com.esri.arcgis.carto.ILayerProxy.getName(Unknown Source)
at com.esri.arcgis.carto.GroupLayer.getName(Unknown Source)
at blah.blah.blah.printMosaicLayerName(MyClassName.java:92)
public void printMosaicLayerName(com.esri.arcgis.carto.Map map, AGSConnection agsconn){
ILayer layer = null;
try {
UID id = (UID) agsconn.getContext().createObject(UID.getClsid());
id.setValue(com.esri.arcgis.carto.ICompositeLayer.class);
// getLayers(UID, true) uses recursion to the get the layer name in a GroupLayer
IEnumLayer enumLayer = map.getLayers(id, true);
enumLayer.reset();
layer = (ILayer) enumLayer.next();
while(!(layer == null)){
System.out.println(layer.getClass().getName() + " " + layer.getName());
layer = (ILayer) enumLayer.next();
}
} catch (AutomationException ae) {
ae.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
public void printMosaicLayerName(com.esri.arcgis.carto.Map map, AGSConnection agsconn){
ILayer2 layer = null;
try {
UID id = (UID) agsconn.getContext().createObject(UID.getClsid());
id.setValue(com.esri.arcgis.carto.ILayer2.class);
// getLayers(UID, true) uses recursion to the get the layer name in a GroupLayer
IEnumLayer enumLayer = map.getLayers(id, true);
enumLayer.reset();
layer = (ILayer2) enumLayer.next();
while(!(layer == null)){
System.out.println(layer.getClass().getName() + " " + layer.getName()); // this is line #93
if(layer instanceof IMosaicDataset){
MosaicDataset md = (MosaicDataset)layer;
System.out.println(md.getRelativePath().toString());
}
layer = (ILayer2) enumLayer.next();
}
} catch (AutomationException ae) {
ae.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
Jul 31, 2013 7:37:43 AM org.apache.catalina.startup.Catalina start INFO: Server startup in 23085 ms com.esri.arcgis.carto.FeatureLayer Zoning Case com.esri.arcgis.carto.GroupLayer Transportation // The next 5 layers are part of the Transporation GroupLayer com.esri.arcgis.carto.FeatureLayer Residential Streets com.esri.arcgis.carto.FeatureLayer Major Roads com.esri.arcgis.carto.FeatureLayer State Highway com.esri.arcgis.carto.FeatureLayer US Highway com.esri.arcgis.carto.FeatureLayer Interstates com.esri.arcgis.carto.FeatureLayer County Boundary com.esri.arcgis.carto.FeatureLayer Parcels // Right after this layer is the mosaic Jul 31, 2013 7:38:16 AM com.sun.faces.application.ActionListenerImpl processAction SEVERE: java.lang.ClassCastException: A COM object reference via iid 34c20002-4d3c-11d0-92d8-00805f7c28b0 does not support COM interface edad6644-1810-11d1-86ae-0000f8751720 javax.faces.el.EvaluationException: java.lang.ClassCastException: A COM object reference via iid 34c20002-4d3c-11d0-92d8-00805f7c28b0 does not support COM interface edad6644-1810-11d1-86ae-0000f8751720 at javax.faces.component.MethodBindingMethodExpressionAdapter.invoke(MethodBindingMethodExpressionAdapter.java:98) at com.sun.faces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:98) at javax.faces.component.UICommand.broadcast(UICommand.java:311) at javax.faces.component.UIViewRoot.broadcastEvents(UIViewRoot.java:781) at javax.faces.component.UIViewRoot.processApplication(UIViewRoot.java:1246) at com.sun.faces.lifecycle.InvokeApplicationPhase.execute(InvokeApplicationPhase.java:77) at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:97) at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:114) at javax.faces.webapp.FacesServlet.service(FacesServlet.java:308) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210) at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:222) at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123) at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472) at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:171) at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:99) at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:936) at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118) at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:407) at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1004) at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:589) at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:312) at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:895) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:918) at java.lang.Thread.run(Thread.java:662) Caused by: java.lang.ClassCastException: A COM object reference via iid 34c20002-4d3c-11d0-92d8-00805f7c28b0 does not support COM interface edad6644-1810-11d1-86ae-0000f8751720 at com.esri.arcgis.interop.Dispatch.c(Unknown Source) at com.esri.arcgis.interop.Dispatch.vtblInvoke(Unknown Source) at com.esri.arcgis.carto.ILayerProxy.getName(Unknown Source) at com.esri.arcgis.carto.GroupLayer.getName(Unknown Source) at blah.blah.blah.printMosaicLayerName(MyClassName.java:93)
com.esri.arcgis.carto.FeatureLayer com.esri.arcgis.carto.GroupLayer com.esri.arcgis.carto.FeatureLayer com.esri.arcgis.carto.FeatureLayer com.esri.arcgis.carto.FeatureLayer com.esri.arcgis.carto.FeatureLayer com.esri.arcgis.carto.FeatureLayer com.esri.arcgis.carto.FeatureLayer com.esri.arcgis.carto.FeatureLayer com.esri.arcgis.carto.GroupLayer com.esri.arcgis.carto.FeatureLayer com.esri.arcgis.carto.FeatureLayer
....however, how do you use those methods?
public IRasterLayer getRasterLayerName(com.esri.arcgis.carto.Map map, AGSConnection agsconn)
Public Sub ToggleMosaicLayerVis() Dim pMxDoc As IMxDocument Set pMxDoc = ThisDocument Dim pCpsLyr As ILayer2 'ILayer works too 'accessing 1st layer in TOC; incidentally a mosaic layer Set pCpsLyr = pMxDoc.FocusMap.Layer(0) 'this works, but obviously did not apply any layer prop testing If pCpsLyr.Visible = True Then pCpsLyr.Visible = False Else pCpsLyr.Visible = True End If Debug.Print "Your 'composite mosaic' layer name = " & pCpsLyr.Name Debug.Print "...and the layer visibility is set " & pCpsLyr.Visible ' some interesting lyr testing; both composite and mosaic tested true If TypeOf pCpsLyr Is IMosaicLayer Then Debug.Print "True mosaic" End If If TypeOf pCpsLyr Is ICompositeLayer Then Debug.Print "True composite" End If If TypeOf pCpsLyr Is IFeatureLayer Then Debug.Print "True feature" End If ' stupid pet trick to see how ILayer2 obj is extended as IMosaicLayer obj ' now access is extended to set visibility on sublayers associated with mosaic lyr Dim pMscLyr As IMosaicLayer Set pMscLyr = pCpsLyr If pCpsLyr.Visible = True Then If pMscLyr.BoundaryLayer.Visible = True Then pMscLyr.BoundaryLayer.Visible = False Else: pMscLyr.BoundaryLayer.Visible = True End If End If 'Debug.Print pMscLyr.MosaicDataset.VisibleFields 'Debug.Print pMscLyr.PreviewLayer.Name End Sub