# About WmtsLayer

**URL:** <https://community.thinkgeo.com/t/about-wmtslayer/9037>\
**Category:** WPF\
**Created:** [April 2, 2018, 3:28am UTC](https://community.thinkgeo.com/t/about-wmtslayer/9037 "2018-04-02T03:28:41Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Zhangming](https://community.thinkgeo.com/letter_avatar_proxy/v4/letter/z/b19c9b/32.png) [@Zhangming](https://community.thinkgeo.com/u/Zhangming)\
**Post date:** [April 2, 2018, 3:28am UTC](https://community.thinkgeo.com/t/about-wmtslayer/9037/1 "2018-04-02T03:28:42Z")

</div>

Hello

I want to add a local Wmtslayer to my project use this code，and got error message,Program crashes. But the same service is normal in arcgis map. I don’t know what the problem is.  
this is server xml [Server Wmts.xml](https://community.thinkgeo.com/uploads/default/original/3X/4/f/4f9903fa433bbd6d94395dfc1f4bebc9fec59611.xml) (11.1 KB)

```
      map.MapUnit = GeographyUnit.Meter;
       // map.CurrentExtent = new RectangleShape(1254901.87822449, 6785639.16296541, 1734313.72055747, 6441979.14333386);
      // map.CurrentExtent = new RectangleShape(-80, 60, 80, -60);

        ThinkGeo.MapSuite.Layers.WmtsLayer wmtsLayer = new ThinkGeo.MapSuite.Layers.WmtsLayer();
        wmtsLayer.DrawingExceptionMode = DrawingExceptionMode.DrawException;
        wmtsLayer.WmtsSeverEncodingType = ThinkGeo.MapSuite.Layers.WmtsSeverEncodingType.Kvp;
        wmtsLayer.ServerUris.Add(new Uri("http://localhost:9009/arctiler/ogc/services/GoogleEarthSatelliteMap/WMTS?"));
        wmtsLayer.ActiveLayerName = "GoogleEarthSatelliteMap";
        wmtsLayer.ActiveStyleName = "default";
        wmtsLayer.TileMatrixSetName = "AZMap_GoogleEarthSatelliteMap";
        wmtsLayer.OutputFormat = "image/jpg";

        wmtsLayer.SendingWebRequest += WmtsLayer_SendingWebRequest;
        wmtsLayer.Open();

        LayerOverlay layerOverlay = new LayerOverlay();
        layerOverlay.Layers.Add(wmtsLayer);

        map.Overlays.Add(layerOverlay);
        map.CurrentExtent = layerOverlay.GetBoundingBox();
        map.Refresh();

```

private void WmtsLayer\_SendingWebRequest(object sender, SendingWebRequestEventArgs e)  
{  
System.Diagnostics.Debug.WriteLine(e.WebRequest.RequestUri.ToString());  
}  
show log:  
[http://localhost:9009/arctiler/ogc/services/GoogleEarthSatelliteMap/WMTS](http://localhost:9009/arctiler/ogc/services/GoogleEarthSatelliteMap/WMTS)??service=WMTS&request=GetTile&version=1.0.0&layer=GoogleEarthSatelliteMap&style=default&format=image/jpg&TileMatrixSet=AZMap\_GoogleEarthSatelliteMap&TileMatrix=AZMap\_GoogleEarthSatelliteMap:0&TileRow=3&TileCol=11  
[http://localhost:9009/arctiler/ogc/services/GoogleEarthSatelliteMap/WMTS](http://localhost:9009/arctiler/ogc/services/GoogleEarthSatelliteMap/WMTS)??service=WMTS&request=GetTile&version=1.0.0&layer=GoogleEarthSatelliteMap&style=default&format=image/jpg&TileMatrixSet=AZMap\_GoogleEarthSatelliteMap&TileMatrix=AZMap\_GoogleEarthSatelliteMap:0&TileRow=4&TileCol=15  
[http://localhost:9009/arctiler/ogc/services/GoogleEarthSatelliteMap/WMTS](http://localhost:9009/arctiler/ogc/services/GoogleEarthSatelliteMap/WMTS)??service=WMTS&request=GetTile&version=1.0.0&layer=GoogleEarthSatelliteMap&style=default&format=image/jpg&TileMatrixSet=AZMap\_GoogleEarthSatelliteMap&TileMatrix=AZMap\_GoogleEarthSatelliteMap:0&TileRow=4&TileCol=11  
[http://localhost:9009/arctiler/ogc/services/GoogleEarthSatelliteMap/WMTS](http://localhost:9009/arctiler/ogc/services/GoogleEarthSatelliteMap/WMTS)??service=WMTS&request=GetTile&version=1.0.0&layer=GoogleEarthSatelliteMap&style=default&format=image/jpg&TileMatrixSet=AZMap\_GoogleEarthSatelliteMap&TileMatrix=AZMap\_GoogleEarthSatelliteMap:0&TileRow=3&TileCol=12  
[http://localhost:9009/arctiler/ogc/services/GoogleEarthSatelliteMap/WMTS](http://localhost:9009/arctiler/ogc/services/GoogleEarthSatelliteMap/WMTS)??service=WMTS&request=GetTile&version=1.0.0&layer=GoogleEarthSatelliteMap&style=default&format=image/jpg&TileMatrixSet=AZMap\_GoogleEarthSatelliteMap&TileMatrix=AZMap\_GoogleEarthSatelliteMap:0&TileRow=3&TileCol=13  
[http://localhost:9009/arctiler/ogc/services/GoogleEarthSatelliteMap/WMTS](http://localhost:9009/arctiler/ogc/services/GoogleEarthSatelliteMap/WMTS)??service=WMTS&request=GetTile&version=1.0.0&layer=GoogleEarthSatelliteMap&style=default&format=image/jpg&TileMatrixSet=AZMap\_GoogleEarthSatelliteMap&TileMatrix=AZMap\_GoogleEarthSatelliteMap:0&TileRow=4&TileCol=12  
[http://localhost:9009/arctiler/ogc/services/GoogleEarthSatelliteMap/WMTS](http://localhost:9009/arctiler/ogc/services/GoogleEarthSatelliteMap/WMTS)??service=WMTS&request=GetTile&version=1.0.0&layer=GoogleEarthSatelliteMap&style=default&format=image/jpg&TileMatrixSet=AZMap\_GoogleEarthSatelliteMap&TileMatrix=AZMap\_GoogleEarthSatelliteMap:0&TileRow=3&TileCol=14  
[http://localhost:9009/arctiler/ogc/services/GoogleEarthSatelliteMap/WMTS](http://localhost:9009/arctiler/ogc/services/GoogleEarthSatelliteMap/WMTS)??service=WMTS&request=GetTile&version=1.0.0&layer=GoogleEarthSatelliteMap&style=default&format=image/jpg&TileMatrixSet=AZMap\_GoogleEarthSatelliteMap&TileMatrix=AZMap\_GoogleEarthSatelliteMap:0&TileRow=4&TileCol=13  
[http://localhost:9009/arctiler/ogc/services/GoogleEarthSatelliteMap/WMTS](http://localhost:9009/arctiler/ogc/services/GoogleEarthSatelliteMap/WMTS)??service=WMTS&request=GetTile&version=1.0.0&layer=GoogleEarthSatelliteMap&style=default&format=image/jpg&TileMatrixSet=AZMap\_GoogleEarthSatelliteMap&TileMatrix=AZMap\_GoogleEarthSatelliteMap:0&TileRow=4&TileCol=1

 ![](https://community.thinkgeo.com/uploads/default/original/3X/7/0/7088ed541c16228dce642b7fb45e0e8bf6a0f0b5.jpg)4

---

<div class="post-metadata">

**Author:** ![Ethan](https://community.thinkgeo.com/user_avatar/community.thinkgeo.com/ethan/32/19964_2.png) [@Ethan](https://community.thinkgeo.com/u/Ethan)\
**Post date:** [April 2, 2018, 8:11am UTC](https://community.thinkgeo.com/t/about-wmtslayer/9037/2 "2018-04-02T08:11:23Z")

</div>

Hi Zhangming,

I guess the problem is parse capability met problem.

The problem is we cannot test it because it’s a local WMTS server, please open the test service so we can debug to see where is the problem.

Regards,

Ethan

---

<div class="post-metadata">

**Author:** ![karl\_barkmann](https://community.thinkgeo.com/letter_avatar_proxy/v4/letter/k/a8b319/32.png) [@karl\_barkmann](https://community.thinkgeo.com/u/karl_barkmann)\
**Post date:** [April 9, 2018, 5:20am UTC](https://community.thinkgeo.com/t/about-wmtslayer/9037/3 "2018-04-09T05:20:56Z")

</div>

Try this one:  
[http://t0.tianditu.com/cia\_w/wmts?service=WMTS&version=1.0.0&request=GetCapabilities](http://t0.tianditu.com/cia_w/wmts?service=WMTS&version=1.0.0&request=GetCapabilities)

---

<div class="post-metadata">

**Author:** ![karl\_barkmann](https://community.thinkgeo.com/letter_avatar_proxy/v4/letter/k/a8b319/32.png) [@karl\_barkmann](https://community.thinkgeo.com/u/karl_barkmann)\
**Post date:** [April 9, 2018, 5:35am UTC](https://community.thinkgeo.com/t/about-wmtslayer/9037/4 "2018-04-09T05:35:20Z")

</div>

// ThinkGeo.MapSuite.Wpf.WmtsLayer  
private Collection MakeTileValidInCapabilities(Collection cells, TileMatrix tileMatrix)  
{  
Collection collection = new Collection();  
if (this.wmtsServerLayers[0].2kI=.Count != 0)  
{  
foreach (uUI= current in this.wmtsServerLayers[0].2kI=)  
{  
if (tileMatrix.Id == current.jxQ=)  
{  
foreach (TileMatrixCell current2 in cells)  
{  
if (double.Parse(current2.Column.ToString(CultureInfo.InvariantCulture)) \>= current.w0I= && double.Parse(current2.Column.ToString(CultureInfo.InvariantCulture)) \<= current.xUI= && double.Parse(current2.Row.ToString(CultureInfo.InvariantCulture)) \>= current.v0I= && double.Parse(current2.Row.ToString(CultureInfo.InvariantCulture)) \<= current.wUI=)  
{  
collection.Add(current2);  
}  
}  
}  
}  
return collection;  
}  
return cells;  
}  
You guys should check the source code of WmtsLayer,especially MakeTileValidInCapabilities method.Why wmtsServerLayers[0] ?  
I believe you guys should have a lot of bug to fix.

---

<div class="post-metadata">

**Author:** ![karl\_barkmann](https://community.thinkgeo.com/letter_avatar_proxy/v4/letter/k/a8b319/32.png) [@karl\_barkmann](https://community.thinkgeo.com/u/karl_barkmann)\
**Post date:** [April 9, 2018, 5:39am UTC](https://community.thinkgeo.com/t/about-wmtslayer/9037/5 "2018-04-09T05:39:33Z")

</div>

Please confirm that WmtsLayer is ok after enable tile cache.Thank you.  
Sorry for my poor english.

---

<div class="post-metadata">

**Author:** ![Ethan](https://community.thinkgeo.com/user_avatar/community.thinkgeo.com/ethan/32/19964_2.png) [@Ethan](https://community.thinkgeo.com/u/Ethan)\
**Post date:** [April 9, 2018, 7:37am UTC](https://community.thinkgeo.com/t/about-wmtslayer/9037/6 "2018-04-09T07:37:25Z")

</div>

Hi karl\_barkmann,

As below is the sample about your server:

```
 map.MapUnit = GeographyUnit.Meter;

        LayerOverlay layerOverlay = new LayerOverlay();

        WmtsLayer wmtsLayer = new WmtsLayer();
        wmtsLayer.SendingWebRequest += WmtsLayer_SendingWebRequest;
        wmtsLayer.ServerUris.Add(new Uri("https://t0.tianditu.com/cia_w/wmts"));
        wmtsLayer.DrawingExceptionMode = DrawingExceptionMode.DrawException;
        wmtsLayer.WmtsSeverEncodingType = ThinkGeo.MapSuite.Layers.WmtsSeverEncodingType.Kvp;
        wmtsLayer.Open();
        wmtsLayer.ActiveLayerName = "cia";
        wmtsLayer.ActiveStyleName = "default";
        wmtsLayer.TileMatrixSetName = "w";
        wmtsLayer.OutputFormat = "image/png";

        layerOverlay.Layers.Add(wmtsLayer);

        wmtsLayer.Open();
        map.CurrentExtent = new RectangleShape(-20037508.3427892, 20037508.3427892, 20037508.3427892, -20037508.3427892);

        map.Overlays.Add(layerOverlay);
        map.Refresh();

```

The problem is, when it works the tile request url looks is not suitable the server, please find a valid tile request url and you can adjust the parameters to make it works.

The currently url is for example:  
[https://t0.tianditu.com/cia\_w/wmts?service=WMTS&request=GetTile&version=1.0.0&layer=cia&style=default&format=image/png&TileMatrixSet=w&TileMatrix=w:0&TileRow=0&TileCol=1](https://t0.tianditu.com/cia_w/wmts?service=WMTS&request=GetTile&version=1.0.0&layer=cia&style=default&format=image/png&TileMatrixSet=w&TileMatrix=w:0&TileRow=0&TileCol=1)

Regards,

Ethan
