TypeError: c is undefined

1642
7
07-19-2017 02:50 AM
feipu
by
New Contributor

       Thanks esri for publishing arcgis api for javascript v4.4, which supports wmts. But there are something wrong, when I try to using wmts services that are not privided by Global Imagery Browse Services (GIBS).

     The wmts url is:http://t6.tianditu.com/img_w/wmts ,while the site for this wmts services is :http://www.tianditu.com/service/info.html?sid=1061&type=info.

     Here is my code below:

<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8"></meta>
  <meta name="viewport" content="initial-scale=1,maximum-scale=1,user-scalable=no"></meta>

 <link rel="stylesheet" href="https://js.arcgis.com/4.4/esri/css/main.css"/>  
  <title>TDT</title>

  <style>
    html,
    body,
    #viewDiv {
      padding: 0;
      margin: 0;
      height: 95%; // allow space for sublayer switcher
      width: 100%;
    }

  </style>

 
</head>
<body>
 
  <div id="viewDiv"></div>
<script src="https://js.arcgis.com/4.4/"></script>

<!--   <script src="js/dojoExtend/WMTSLayer.js"></script> -->
<!-- <script src="js/dojoExtend/tdtWMTS.js"></script> -->
<script >

/**
 *
 */
    
        
      require([
          "esri/config",
        "esri/Map",
        "esri/geometry/Extent",
        "esri/views/MapView",
        "esri/layers/WMTSLayer",
        "dojo/domReady!"
      ], function(
        esriConfig,
        Map,
        Extent,
        MapView,
        WMTSLayer
      ) {
          esriConfig.request.corsEnabledServers.push("http://t6.tianditu.com");
          
          var tileExtent=new Extent({
            xmin: 120.64950513012732,
            ymin: 28.727049272378594,
            xmax: 121.86112667429612,
            ymax: 29.297168129375535,
            spatialReference: {
              wkid: 4490
            }
        });  
          var tdtFullExtent=new Extent({
            xmin: -180,
            ymin: -90,
            xmax: 180,
            ymax: 90,
            spatialReference: {
              wkid: 4490
            }
          });
      
          
                  
        
        var tdtWMTSLayer=new WMTSLayer({
            //Currently active sublayer. Defaults to the first sublayer in sublayers
            //activeLayer:"",
            //Use this to append different custom parameters to the WMTS tile requests. The custom layer parameters are applied to GetTile.
            //customLayerParameters:{},
            //Use this to append custom parameters to all WMTS requests
            
            //RESTful | KVP
            serviceMode:"KVP",
            //A collection of WMTSSublayer objects.            
            //The URL for the GetCapabilities is created based on the url and serviceMode properties.
            url:"http://t6.tianditu.com/img_w/wmts",
            version:"1.0.0"
            
        });
        
      var map=new Map({
          layers:[tdtWMTSLayer]
      });
      
      var view=new MapView({
          container:"viewDiv",
          map:map
      });
      
      view.then(function(){
          view.extent = tileExtent;
          var layerList = new LayerList({
              view: view
            });
          view.ui.add(layerList, "bottom-left");
      });
      
    });

</script>
 
</body>
</html>

Tags (1)
0 Kudos
7 Replies
ThomasSolow
Occasional Contributor III

When I try to add that layer, 2 requests are made to the server hosting the layer information, but neither request succeeds.  This may be a problem with how that server is configured or it may be an issue with how the requests are made.

If you have a url for a WMTS layer that works, that could help me narrow this down.

0 Kudos
feipu
by
New Contributor

Here is the site of WMTS resources:国家地理信息公共服务平台“天地图” , There are many WMTS resource, you can just try.

There is a WMTS services that I have tried and could be accessed: http://t3.tianditu.com/img_c/wmts

using arcgis onelien

0 Kudos
feipu
by
New Contributor

While, I have traced the request and response, the results revealed that  URL of WMTS if http://t0.tianditu.com/img_c/wmts?. But It can not be accessed directly, which confused me.

0 Kudos
feipu
by
New Contributor

Here is the result of getCapabilities:http://t0.tianditu.com/img_w/wmts?request=GetCapabilities&service=WMTS&version=1.0.0 

<?xml version="1.0" encoding="UTF-8"?><Capabilities    xsi:schemaLocation="http://www.opengis.net/wmts/1.0 http://schemas.opengis.net/wmts/1.0.0/wmtsGetCapabilities_response.xsd"    version="1.0.0" xmlns="http://www.opengis.net/wmts/1.0"    xmlns:ows="http://www.opengis.net/ows/1.1"    xmlns:gml="http://www.opengis.net/gml"    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xlink="http://www.w3.org/1999/xlink">    <ows:ServiceIdentification>        <ows:Title>在线地图服务</ows:Title>        <ows:Abstract>基于OGC标准的地图服务</ows:Abstract>        <ows:Keywords>            <ows:Keyword>OGC</ows:Keyword>        </ows:Keywords>        <ows:ServiceType codeSpace="wmts"/>        <ows:ServiceTypeVersion>1.0.0</ows:ServiceTypeVersion>        <ows:Fees>none</ows:Fees>        <ows:AccessConstraints>none</ows:AccessConstraints>    </ows:ServiceIdentification>    <ows:ServiceProvider>        <ows:ProviderName>国家基础地理信息中心</ows:ProviderName>        <ows:ProviderSite>http://www.tianditu.com</ows:ProviderSite>        <ows:ServiceContact>            <ows:IndividualName>Mr Liu</ows:IndividualName>            <ows:PositionName>Software Engineer</ows:PositionName>            <ows:ContactInfo>                <ows:Phone>                    <ows:Voice>010-88187700</ows:Voice>                    <ows:Facsimile>010-88187700</ows:Facsimile>                </ows:Phone>                <ows:Address>                    <ows:DeliveryPoint>北京市海淀区莲花池西路28号</ows:DeliveryPoint>                    <ows:City>北京市</ows:City>                    <ows:AdministrativeArea>北京市</ows:AdministrativeArea>                    <ows:Country>中国</ows:Country>                    <ows:PostalCode>101399</ows:PostalCode>                    <ows:ElectronicMailAddress>tianditu.com</ows:ElectronicMailAddress>                </ows:Address>                <ows:OnlineResource xlink:type="simple" xlink:href="http://www.tianditu.com"/>            </ows:ContactInfo>        </ows:ServiceContact>    </ows:ServiceProvider>    <ows:OperationsMetadata>        <ows:Operation name="GetCapabilities">            <ows:DCP>                <ows:HTTP>                    <ows:Get xlink:href="http://t0.tianditu.com/img_w/wmts?">                        <ows:Constraint name="GetEncoding">                            <ows:AllowedValues>                                <ows:Value>KVP</ows:Value>                            </ows:AllowedValues>                        </ows:Constraint>                    </ows:Get>                </ows:HTTP>            </ows:DCP>        </ows:Operation>        <ows:Operation name="GetTile">            <ows:DCP>                <ows:HTTP>                    <ows:Get xlink:href="http://t0.tianditu.com/img_w/wmts?">                        <ows:Constraint name="GetEncoding">                            <ows:AllowedValues>                                <ows:Value>KVP</ows:Value>                            </ows:AllowedValues>                        </ows:Constraint>                    </ows:Get>                </ows:HTTP>            </ows:DCP>        </ows:Operation>    </ows:OperationsMetadata>    <Contents>        <Layer>            <ows:Title>img</ows:Title>            <ows:Abstract>img</ows:Abstract>            <ows:Identifier>img</ows:Identifier>            <ows:WGS84BoundingBox>                <ows:LowerCorner>-20037508.3427892 -20037508.3427892</ows:LowerCorner>                <ows:UpperCorner>20037508.3427892 20037508.3427892</ows:UpperCorner>            </ows:WGS84BoundingBox>            <ows:BoundingBox>                <ows:LowerCorner>-20037508.3427892 -20037508.3427892</ows:LowerCorner>                <ows:UpperCorner>20037508.3427892 20037508.3427892</ows:UpperCorner>            </ows:BoundingBox>            <Style>                <ows:Identifier>default</ows:Identifier>            </Style>            <Format>tiles</Format>            <TileMatrixSetLink>                <TileMatrixSet>w</TileMatrixSet>            </TileMatrixSetLink>        </Layer>        <TileMatrixSet>            <ows:Identifier>w</ows:Identifier>            <ows:SupportedCRS>urn:ogc:def:crs:EPSG::900913</ows:SupportedCRS>            <TileMatrix>                <ows:Identifier>1</ows:Identifier>                <ScaleDenominator>2.958293554545656E8</ScaleDenominator>                <TopLeftCorner>20037508.3427892 -20037508.3427892</TopLeftCorner>                <TileWidth>256</TileWidth>                <TileHeight>256</TileHeight>                <MatrixWidth>2</MatrixWidth>                <MatrixHeight>2</MatrixHeight>            </TileMatrix>            <TileMatrix>                <ows:Identifier>2</ows:Identifier>                <ScaleDenominator>1.479146777272828E8</ScaleDenominator>                <TopLeftCorner>20037508.3427892 -20037508.3427892</TopLeftCorner>                <TileWidth>256</TileWidth>                <TileHeight>256</TileHeight>                <MatrixWidth>4</MatrixWidth>                <MatrixHeight>4</MatrixHeight>            </TileMatrix>            <TileMatrix>                <ows:Identifier>3</ows:Identifier>                <ScaleDenominator>7.39573388636414E7</ScaleDenominator>                <TopLeftCorner>20037508.3427892 -20037508.3427892</TopLeftCorner>                <TileWidth>256</TileWidth>                <TileHeight>256</TileHeight>                <MatrixWidth>8</MatrixWidth>                <MatrixHeight>8</MatrixHeight>            </TileMatrix>            <TileMatrix>                <ows:Identifier>4</ows:Identifier>                <ScaleDenominator>3.69786694318207E7</ScaleDenominator>                <TopLeftCorner>20037508.3427892 -20037508.3427892</TopLeftCorner>                <TileWidth>256</TileWidth>                <TileHeight>256</TileHeight>                <MatrixWidth>16</MatrixWidth>                <MatrixHeight>16</MatrixHeight>            </TileMatrix>            <TileMatrix>                <ows:Identifier>5</ows:Identifier>                <ScaleDenominator>1.848933471591035E7</ScaleDenominator>                <TopLeftCorner>20037508.3427892 -20037508.3427892</TopLeftCorner>                <TileWidth>256</TileWidth>                <TileHeight>256</TileHeight>                <MatrixWidth>32</MatrixWidth>                <MatrixHeight>32</MatrixHeight>            </TileMatrix>            <TileMatrix>                <ows:Identifier>6</ows:Identifier>                <ScaleDenominator>9244667.357955175</ScaleDenominator>                <TopLeftCorner>20037508.3427892 -20037508.3427892</TopLeftCorner>                <TileWidth>256</TileWidth>                <TileHeight>256</TileHeight>                <MatrixWidth>64</MatrixWidth>                <MatrixHeight>64</MatrixHeight>            </TileMatrix>                   <TileMatrix>                <ows:Identifier>7</ows:Identifier>                <ScaleDenominator>4622333.678977588</ScaleDenominator>                <TopLeftCorner>20037508.3427892 -20037508.3427892</TopLeftCorner>                <TileWidth>256</TileWidth>                <TileHeight>256</TileHeight>                <MatrixWidth>128</MatrixWidth>                <MatrixHeight>128</MatrixHeight>            </TileMatrix>            <TileMatrix>                <ows:Identifier>8</ows:Identifier>                <ScaleDenominator>2311166.839488794</ScaleDenominator>                <TopLeftCorner>20037508.3427892 -20037508.3427892</TopLeftCorner>                <TileWidth>256</TileWidth>                <TileHeight>256</TileHeight>                <MatrixWidth>256</MatrixWidth>                <MatrixHeight>256</MatrixHeight>            </TileMatrix>            <TileMatrix>                <ows:Identifier>9</ows:Identifier>                <ScaleDenominator>1155583.419744397</ScaleDenominator>                <TopLeftCorner>20037508.3427892 -20037508.3427892</TopLeftCorner>                <TileWidth>256</TileWidth>                <TileHeight>256</TileHeight>                <MatrixWidth>512</MatrixWidth>                <MatrixHeight>512</MatrixHeight>            </TileMatrix>            <TileMatrix>                <ows:Identifier>10</ows:Identifier>                <ScaleDenominator>577791.7098721985</ScaleDenominator>                <TopLeftCorner>20037508.3427892 -20037508.3427892</TopLeftCorner>                <TileWidth>256</TileWidth>                <TileHeight>256</TileHeight>                <MatrixWidth>1024</MatrixWidth>                <MatrixHeight>1024</MatrixHeight>            </TileMatrix>            <TileMatrix>                <ows:Identifier>11</ows:Identifier>                <ScaleDenominator>288895.85493609926</ScaleDenominator>                <TopLeftCorner>20037508.3427892 -20037508.3427892</TopLeftCorner>                <TileWidth>256</TileWidth>                <TileHeight>256</TileHeight>                <MatrixWidth>2048</MatrixWidth>                <MatrixHeight>2048</MatrixHeight>            </TileMatrix>            <TileMatrix>                <ows:Identifier>12</ows:Identifier>                <ScaleDenominator>144447.92746804963</ScaleDenominator>                <TopLeftCorner>20037508.3427892 -20037508.3427892</TopLeftCorner>                <TileWidth>256</TileWidth>                <TileHeight>256</TileHeight>                <MatrixWidth>4096</MatrixWidth>                <MatrixHeight>4096</MatrixHeight>            </TileMatrix>            <TileMatrix>                <ows:Identifier>13</ows:Identifier>                <ScaleDenominator>72223.96373402482</ScaleDenominator>                <TopLeftCorner>20037508.3427892 -20037508.3427892</TopLeftCorner>                <TileWidth>256</TileWidth>                <TileHeight>256</TileHeight>                <MatrixWidth>8192</MatrixWidth>                <MatrixHeight>8192</MatrixHeight>            </TileMatrix>            <TileMatrix>                <ows:Identifier>14</ows:Identifier>                <ScaleDenominator>36111.98186701241</ScaleDenominator>                <TopLeftCorner>20037508.3427892 -20037508.3427892</TopLeftCorner>                <TileWidth>256</TileWidth>                <TileHeight>256</TileHeight>                <MatrixWidth>16384</MatrixWidth>                <MatrixHeight>16384</MatrixHeight>            </TileMatrix>            <TileMatrix>                <ows:Identifier>15</ows:Identifier>                <ScaleDenominator>18055.990933506204</ScaleDenominator>                <TopLeftCorner>20037508.3427892 -20037508.3427892</TopLeftCorner>                <TileWidth>256</TileWidth>                <TileHeight>256</TileHeight>                <MatrixWidth>32768</MatrixWidth>                <MatrixHeight>32768</MatrixHeight>            </TileMatrix>            <TileMatrix>                <ows:Identifier>16</ows:Identifier>                <ScaleDenominator>9027.995466753102</ScaleDenominator>                <TopLeftCorner>20037508.3427892 -20037508.3427892</TopLeftCorner>                <TileWidth>256</TileWidth>                <TileHeight>256</TileHeight>                <MatrixWidth>65536</MatrixWidth>                <MatrixHeight>65536</MatrixHeight>            </TileMatrix>            <TileMatrix>                <ows:Identifier>17</ows:Identifier>                <ScaleDenominator>4513.997733376551</ScaleDenominator>                <TopLeftCorner>20037508.3427892 -20037508.3427892</TopLeftCorner>                <TileWidth>256</TileWidth>                <TileHeight>256</TileHeight>                <MatrixWidth>131072</MatrixWidth>                <MatrixHeight>131072</MatrixHeight>                    </TileMatrix>            <TileMatrix>                <ows:Identifier>18</ows:Identifier>                <ScaleDenominator>2256.998866688275</ScaleDenominator>                <TopLeftCorner>20037508.3427892 -20037508.3427892</TopLeftCorner>                <TileWidth>256</TileWidth>                <TileHeight>256</TileHeight>                <MatrixWidth>262144</MatrixWidth>                <MatrixHeight>262144</MatrixHeight>            </TileMatrix>        </TileMatrixSet>    </Contents></Capabilities>
0 Kudos
ThomasSolow
Occasional Contributor III

Okay, I think the issues I was having were due to doing this from jsbin.  I'm making requests from localhost now and things are working. 

I can load http://t0.tianditu.com/img_c/wmts 

I can confirm that http://t6.tianditu.com/img_w/wmts  is not working and I'm looking into the issue with that now.  The initial request does seem to be successful.

0 Kudos
ThomasSolow
Occasional Contributor III

Okay, it looks like this is a spatial reference issue.

For the layer that failed to load, the spatial reference wkid is 9009l3.  This looks to be another wkid for web mercator, so the view must have a spatialReference with wkid 102100 in order to add this layer.

In these situation it's probably best to be explicit, so you should set the view's spatialReference manually:

var tdtWMTSLayer=new WMTSLayer({
  serviceMode:"KVP",
  url:"http://t6.tianditu.com/img_w/wmts",
  version:"1.0.0"
});
        
var map = new Map({
  layers:[tdtWMTSLayer]
});
      
var view = new MapView({
  container:"viewDiv",
  map:map,
  spatialReference: { wkid: 102100 }
});
      ‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

For the layer that worked (http://t0.tianditu.com/img_c/wmts), the spatial reference is wkid 4490, so it's probably best to explicitly set the view's spatial reference to match that.

These things should be handled automatically and should throw helpful errors, but for now I think setting the SR is the way to go.

0 Kudos
feipu
by
New Contributor

Thank you so much, I will try as you suggestion.

0 Kudos