IWMTSLayer wmtsLayer = new WMTSLayerClass(); IDataLayer dLayer = new WMTSLayerClass(); IPropertySet propSet = new PropertySetClass(); propSet.SetProperty("URL", "http://localhost/erdas-iws/ogc/wmts/?Service=WMTS&Request=GetCapabilities"); IWMTSConnectionFactory wmtsConnFactory = new WMTSConnectionFactoryClass(); IWMTSConnection wmtsConnection = wmtsConnFactory.Open(propSet, 0, null); ESRI.ArcGIS.GISClient.IWMTSServiceDescription wmtsServiceDescription = wmtsConnection as IWMTSServiceDescription; wmtsLayer.WMTSConnection(wmtsConnection); for (int i = 0; i < wmtsServiceDescription.LayerDescriptionCount; i++) { IWMTSLayerDescription layerDescription = wmtsServiceDescription.get_LayerDescription(i); if (layerDescription.Identifier.Equals(Wmts_Name, StringComparison.InvariantCultureIgnoreCase)) { //We have a match //Maybe need something here to open the correct WMTSLayer? } } if (wmtsLayer != null) { IMxDocument mxDocument = (IMxDocument)mxApp.Document; mxDocument.FocusMap.AddLayer((ILayer)wmtsLayer); return true; }
Hi,
I reviewed your code and corrected it like below:
public static ILayer GetWMTSLayer(string url = "http://IP-Address:Port/Service/rest/services/OSM/MapServer/WMTS")
{
IWMTSLayer wmtsLayer = new WMTSLayerClass();
IPropertySet propSet = new PropertySetClass();
propSet.SetProperty("URL", url);
try
{
IWMTSConnectionFactory wmtsConnFactory = new WMTSConnectionFactoryClass();
IWMTSConnection wmtsConnection = wmtsConnFactory.Open(propSet, 0, null);
var con = wmtsLayer.Connect(wmtsConnection.FullName);
//ESRI.ArcGIS.GISClient.IWMTSServiceDescription wmtsServiceDescription = wmtsConnection as IWMTSServiceDescription;
//string layerName = "GoogleMapsRoad",
//for (int i = 0; i < wmtsServiceDescription.LayerDescriptionCount; i++)
//{
// IWMTSLayerDescription layerDescription = wmtsServiceDescription.get_LayerDescription(i);
// if (layerDescription.Identifier.Equals(layerName, StringComparison.InvariantCultureIgnoreCase))
// {
// //We have a match
// //Maybe need something here to open the correct WMTSLayer?
// }
// }
if (con)
return (ILayer)wmtsLayer;
}
catch (COMException ex)
{
MessageBox.Show("Couldn't Get the service:" + url);
}
catch (Exception ex)
{
MessageBox.Show("Couldn't Get the service:" + url);
}
return null;
}
Thanks for your reply but I was already at a point where I could connect to a WMTS service and add a layer. The issue here is retrieving anything other than the first layer.
Hy,
I have the same problem:
I need to get a specific sublayer of a WMTS-mapservice.
I'm also getting listed all the sublayers in the IWMTSLayerDescription but can't return a single sublayer as ILayer.
I'm also always getting the first sublayer from the list returned as ILayer.
Any solution or workaround?
Thanks,
Tom
I am facing similar problem. I want to add all the layers in my WMTS service to ArcMap, but I am able to get only one. Has someone got any solution for this.
Thanks
Regards
Nitin Kandpal
I got solution for adding all layers at ones, as well as a particular layer to ArcMap:
public static void GetWMTSLayer(string url = "http://IP-Address:Port/Service/rest/services/OSM/MapServer/WMTS")
{
IProperySet propSet= new PropertySetClass();
propSet.SetProperty("URL",url);
IWMTSConnectionFactory wmtsConnFactory=new WMTSConnectionFactoryClass();
IWMTSConnection wmtsConnection=wmtsConnFactory.Open(propSet,0,null);
IWMTSServiceDescription wmtsServceDescriotion=wmtsConnection as IWMTSServiceDescription ;
for(int i=0;i< wmtsServceDescriotion.LayerDescriptionCount;i++)
{
IWMTSLayerDescription layerDescription=wmtsServceDescriotion.getLayerDescription(i);
IWMTSLayer wmtsLayer=new WMTSLayerClass();
IPropertySet propSet_1=new PropertySetClass();
propSet_1.SetProperty("URL", url);
propSet_1.SetProperty("LayerName",layerDescription.Identifier);
WMTSConnectionName connectonName= new WMTSConnectionNameClass();
connectionName.ConnectionProperties=propSet_1;
wmtsLayer.Connect((IName)connectionName);
addData(wmtslayer);
}
}
public static void addData(IWMTSLayer wmtslayer)
{
IMap pMap=(IMap)((IMxDocument)ArcMap.Application.Document).FocusMap);
ILayer pLayer=new FeatureLayer();
pLayer=(ILayer)wmtslayer;
pMap.AddLayer(pLayer);
}