cesium加载wmts服务级差错位问题

记录一次cesium加载wmts服务级差错位问题。

注:本文测试用的cesium版本为1.86,高级版本在使用WebMapTileServiceImageryProvider加载服务的时候可能不太一样,需要根据实际情况判断。

问题:使用cesium的WebMapTileServiceImageryProvider加载wmts切片服务出现切片请求行列错误,在分析切片请求时:

分析:列切片请求相差一级,行切片请求存在偏移。

获取服务元数据:

复制代码
<Capabilities xmlns="http://www.opengis.net/wmts/1.0" xmlns:ows="http://www.opengis.net/ows/1.1" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:gml="http://www.opengis.net/gml" xsi:schemaLocation="http://www.opengis.net/wmts/1.0 http://schemas.opengis.net/wmts/1.0/wmtsGetCapabilities_response.xsd" version="1.0.0">
<!-- Service Identification -->
<ows:ServiceIdentification>
<ows:Title>gaoqingyingxiang(2018)</ows:Title>
<ows:ServiceType>OGC WMTS</ows:ServiceType>
<ows:ServiceTypeVersion>1.0.0</ows:ServiceTypeVersion>
</ows:ServiceIdentification>
<!-- Operations Metadata -->
<ows:OperationsMetadata>
<ows:Operation name="GetCapabilities">
<ows:DCP>
<ows:HTTP>
<ows:Get xlink:href="http://172.19.74.81:8706/6040a76ba94df867759096e5/geo/jc_yx_ygyx_05_2018/wmts?">
<ows:Constraint name="GetEncoding">
<ows:AllowedValues>
<ows:Value>KVP</ows:Value>
</ows:AllowedValues>
</ows:Constraint>
</ows:Get>
<ows:Get xlink:href="http://172.19.74.81:8706/6040a76ba94df867759096e5/geo/jc_yx_ygyx_05_2018/wmts">
<ows:Constraint name="GetEncoding">
<ows:AllowedValues>
<ows:Value>RESTful</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://172.19.74.81:8706/6040a76ba94df867759096e5/geo/jc_yx_ygyx_05_2018/wmts?">
<ows:Constraint name="GetEncoding">
<ows:AllowedValues>
<ows:Value>KVP</ows:Value>
</ows:AllowedValues>
</ows:Constraint>
</ows:Get>
<ows:Get xlink:href="http://172.19.74.81:8706/6040a76ba94df867759096e5/geo/jc_yx_ygyx_05_2018/wmts/tile/">
<ows:Constraint name="GetEncoding">
<ows:AllowedValues>
<ows:Value>RESTful</ows:Value>
</ows:AllowedValues>
</ows:Constraint>
</ows:Get>
</ows:HTTP>
</ows:DCP>
</ows:Operation>
</ows:OperationsMetadata>
<Contents>
<!-- Layer -->
<Layer>
<ows:Title>layer0</ows:Title>
<ows:Identifier>layer0</ows:Identifier>
<ows:BoundingBox crs="urn:ogc:def:crs:EPSG::4490">
<ows:LowerCorner>28.166716 112.645651</ows:LowerCorner>
<ows:UpperCorner>28.560943 113.042939</ows:UpperCorner>
</ows:BoundingBox>
<ows:WGS84BoundingBox crs="urn:ogc:def:crs:OGC:2:84">
<ows:LowerCorner>112.645651 28.166715999214244</ows:LowerCorner>
<ows:UpperCorner>113.042939 28.560942999207132</ows:UpperCorner>
</ows:WGS84BoundingBox>
<Style isDefault="true">
<ows:Title>Default Style</ows:Title>
<ows:Identifier>default</ows:Identifier>
</Style>
<Format>image/jpgpng</Format>
<TileMatrixSetLink>
<TileMatrixSet>default</TileMatrixSet>
</TileMatrixSetLink>
<ResourceURL format="image/jpgpng" resourceType="tile" template="http://172.19.74.81:8706/6040a76ba94df867759096e5/geo/jc_yx_ygyx_05_2018/wmts/tile/{TileMatrix}/{TileRow}/{TileCol}"/>
</Layer>
<!-- TileMatrixSet -->
<TileMatrixSet>
<ows:Title>default</ows:Title>
<ows:Abstract>default tile matrix set</ows:Abstract>
<ows:Identifier>default</ows:Identifier>
<ows:SupportedCRS>urn:ogc:def:crs:EPSG::4490</ows:SupportedCRS>
<TileMatrix>
<ows:Identifier>0</ows:Identifier>
<ScaleDenominator>0.7031250000000002</ScaleDenominator>
<TopLeftCorner>90 -180</TopLeftCorner>
<TileWidth>256</TileWidth>
<TileHeight>256</TileHeight>
</TileMatrix>
<TileMatrix>
<ows:Identifier>1</ows:Identifier>
<ScaleDenominator>0.3515625000000001</ScaleDenominator>
<TopLeftCorner>90 -180</TopLeftCorner>
<TileWidth>256</TileWidth>
<TileHeight>256</TileHeight>
</TileMatrix>
<TileMatrix>
<ows:Identifier>2</ows:Identifier>
<ScaleDenominator>0.17578125000000006</ScaleDenominator>
<TopLeftCorner>90 -180</TopLeftCorner>
<TileWidth>256</TileWidth>
<TileHeight>256</TileHeight>
</TileMatrix>
<TileMatrix>
<ows:Identifier>3</ows:Identifier>
<ScaleDenominator>0.08789062500000003</ScaleDenominator>
<TopLeftCorner>90 -180</TopLeftCorner>
<TileWidth>256</TileWidth>
<TileHeight>256</TileHeight>
</TileMatrix>
<TileMatrix>
<ows:Identifier>4</ows:Identifier>
<ScaleDenominator>0.043945312500000014</ScaleDenominator>
<TopLeftCorner>90 -180</TopLeftCorner>
<TileWidth>256</TileWidth>
<TileHeight>256</TileHeight>
</TileMatrix>
<TileMatrix>
<ows:Identifier>5</ows:Identifier>
<ScaleDenominator>0.021972656250000007</ScaleDenominator>
<TopLeftCorner>90 -180</TopLeftCorner>
<TileWidth>256</TileWidth>
<TileHeight>256</TileHeight>
</TileMatrix>
<TileMatrix>
<ows:Identifier>6</ows:Identifier>
<ScaleDenominator>0.010986328125000003</ScaleDenominator>
<TopLeftCorner>90 -180</TopLeftCorner>
<TileWidth>256</TileWidth>
<TileHeight>256</TileHeight>
</TileMatrix>
<TileMatrix>
<ows:Identifier>7</ows:Identifier>
<ScaleDenominator>0.005493164062500002</ScaleDenominator>
<TopLeftCorner>90 -180</TopLeftCorner>
<TileWidth>256</TileWidth>
<TileHeight>256</TileHeight>
</TileMatrix>
<TileMatrix>
<ows:Identifier>8</ows:Identifier>
<ScaleDenominator>0.002746582031250001</ScaleDenominator>
<TopLeftCorner>90 -180</TopLeftCorner>
<TileWidth>256</TileWidth>
<TileHeight>256</TileHeight>
</TileMatrix>
<TileMatrix>
<ows:Identifier>9</ows:Identifier>
<ScaleDenominator>0.0013732910156250004</ScaleDenominator>
<TopLeftCorner>90 -180</TopLeftCorner>
<TileWidth>256</TileWidth>
<TileHeight>256</TileHeight>
</TileMatrix>
<TileMatrix>
<ows:Identifier>10</ows:Identifier>
<ScaleDenominator>6.866455078125002E-4</ScaleDenominator>
<TopLeftCorner>90 -180</TopLeftCorner>
<TileWidth>256</TileWidth>
<TileHeight>256</TileHeight>
</TileMatrix>
<TileMatrix>
<ows:Identifier>11</ows:Identifier>
<ScaleDenominator>3.433227539062501E-4</ScaleDenominator>
<TopLeftCorner>90 -180</TopLeftCorner>
<TileWidth>256</TileWidth>
<TileHeight>256</TileHeight>
</TileMatrix>
<TileMatrix>
<ows:Identifier>12</ows:Identifier>
<ScaleDenominator>1.7166137695312505E-4</ScaleDenominator>
<TopLeftCorner>90 -180</TopLeftCorner>
<TileWidth>256</TileWidth>
<TileHeight>256</TileHeight>
</TileMatrix>
<TileMatrix>
<ows:Identifier>13</ows:Identifier>
<ScaleDenominator>8.583068847656253E-5</ScaleDenominator>
<TopLeftCorner>90 -180</TopLeftCorner>
<TileWidth>256</TileWidth>
<TileHeight>256</TileHeight>
</TileMatrix>
<TileMatrix>
<ows:Identifier>14</ows:Identifier>
<ScaleDenominator>4.2915344238281264E-5</ScaleDenominator>
<TopLeftCorner>90 -180</TopLeftCorner>
<TileWidth>256</TileWidth>
<TileHeight>256</TileHeight>
</TileMatrix>
<TileMatrix>
<ows:Identifier>15</ows:Identifier>
<ScaleDenominator>2.1457672119140632E-5</ScaleDenominator>
<TopLeftCorner>90 -180</TopLeftCorner>
<TileWidth>256</TileWidth>
<TileHeight>256</TileHeight>
</TileMatrix>
<TileMatrix>
<ows:Identifier>16</ows:Identifier>
<ScaleDenominator>1.0728836059570316E-5</ScaleDenominator>
<TopLeftCorner>90 -180</TopLeftCorner>
<TileWidth>256</TileWidth>
<TileHeight>256</TileHeight>
</TileMatrix>
<TileMatrix>
<ows:Identifier>17</ows:Identifier>
<ScaleDenominator>5.364418029785158E-6</ScaleDenominator>
<TopLeftCorner>90 -180</TopLeftCorner>
<TileWidth>256</TileWidth>
<TileHeight>256</TileHeight>
</TileMatrix>
<TileMatrix>
<ows:Identifier>18</ows:Identifier>
<ScaleDenominator>2.682209014892579E-6</ScaleDenominator>
<TopLeftCorner>90 -180</TopLeftCorner>
<TileWidth>256</TileWidth>
<TileHeight>256</TileHeight>
</TileMatrix>
<TileMatrix>
<ows:Identifier>19</ows:Identifier>
<ScaleDenominator>1.3411045074462895E-6</ScaleDenominator>
<TopLeftCorner>90 -180</TopLeftCorner>
<TileWidth>256</TileWidth>
<TileHeight>256</TileHeight>
</TileMatrix>
</TileMatrixSet>
</Contents>
<ServiceMetadataURL xlink:href="http://172.19.74.81:8706/6040a76ba94df867759096e5/geo/jc_yx_ygyx_05_2018/wmts/capabilities.xml"/>
</Capabilities>
复制代码

 

图层加载逻辑为:

复制代码
var layerProvider=new Cesium.WebMapTileServiceImageryProvider({
    url: 'http://172.19.74.81:8706/6040a76ba94df867759096e5/geo/jc_yx_ygyx_05_2018/wmts',
    layer:'layer0',
    style: 'default',
    format: 'image/jpgpng',
    tileMatrixSetID: 'default',
    tileMatrixLabels: ["1","2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16", "17", "18","19","20"],
    tilingScheme: new Cesium.GeographicTilingScheme()
    })
});
viewer.imageryLayers.addImageryProvider(layerProvider);
复制代码

 错误原因:对cesium加载wmts服务中的切片方案不够了解导致。图层加载的时候设置切片是从1-20级,而实际服务的元数据显示的为0-19级,更改tileMatrixLabels后即可正常加载

tileMatrixLabels:["0","1","2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16", "17", "18","19"],

造成此问题的原因,主要是因为目前有很多切片方案是从1级开始,比如天地图的切片方案,1级切片为两列一行,在网上寻找例子的时候直接拷贝,并未考虑例子中的切片方案与自身使用的服务的切片方案是否一致。

实际上我们的切片方案初始级别并非固定,可以是0,也可以是1:

0:ogc标准中的在wgs84和2000中常用初始切片级别为0

1:天地图服务(地理坐标系)一般使用的初始切片级别为1

另外对tilingScheme参数不了解,默认GeographicTilingScheme的其起始切片数量列方向为2,行方向为1,需要搭配tileMatrixLabels,可以实现一些不同切片方案的组合。

扩展说明:

cesium支持两种切片方案:

          

           图1 web墨卡托切片                                                                图2经纬度直投

web墨卡托切片将全球以正方形形式,一行一列起切,是一种投影坐标系(3857)下的切片,用于大部分在线的web电子地图(高德、百度等)

经纬度直投切片将全球以矩形的形式,2列一行起切,分左右半球,是地理坐标系(4326或4490),用于部分电子地图,如天地图

注:天地图两种切片方式都有。

cesium加载wmts服务使用WebMapTileServiceImageryProvider:

参数说明

Name

Type

Attributes

Default

Description

url

Resource | string

   

The base URL for the WMTS GetTile operation (for KVP-encoded requests) or the tile-URL template (for RESTful requests). The tile-URL template should contain the following variables: {style}, {TileMatrixSet}, {TileMatrix}, {TileRow}, {TileCol}. The first two are optional if actual values are hardcoded or not required by the server. The {s} keyword may be used to specify subdomains.

format

string

<optional>

'image/jpeg'

The MIME type for images to retrieve from the server.

layer

string

   

The layer name for WMTS requests.

style

string

   

The style name for WMTS requests.

tileMatrixSetID

string

   

The identifier of the TileMatrixSet to use for WMTS requests.

tileMatrixLabels

Array

<optional>

 

A list of identifiers in the TileMatrix to use for WMTS requests, one per TileMatrix level.

clock

Clock

<optional>

 

A Clock instance that is used when determining the value for the time dimension. Required when `times` is specified.

times

TimeIntervalCollection

<optional>

 

TimeIntervalCollection with its data property being an object containing time dynamic dimension and their values.

dimensions

object

<optional>

 

A object containing static dimensions and their values.

tileWidth

number

<optional>

256

The tile width in pixels.

tileHeight

number

<optional>

256

The tile height in pixels.

tilingScheme

TilingScheme

<optional>

 WebMercatorTilingScheme

The tiling scheme corresponding to the organization of the tiles in the TileMatrixSet.

rectangle

Rectangle

<optional>

Rectangle.MAX_VALUE

The rectangle covered by the layer.

minimumLevel

number

<optional>

0

The minimum level-of-detail supported by the imagery provider.

maximumLevel

number

<optional>

 

The maximum level-of-detail supported by the imagery provider, or undefined if there is no limit.

ellipsoid

Ellipsoid

<optional>

 

The ellipsoid. If not specified, the WGS84 ellipsoid is used.

credit

Credit | string

<optional>

 

A credit for the data source, which is displayed on the canvas.

subdomains

string | Array.<string>

<optional>

'abc'

The subdomains to use for the {s} placeholder in the URL template. If this parameter is a single string, each character in the string is a subdomain. If it is an array, each element in the array is a subdomain.

 

其中tilingScheme可以用来设置不同的切方方案,配合tileMatrixLabels使用可以配置不同级差的切片,

  • web墨卡托投影:tilingScheme = new cesium.WebMercatorTilingScheme()

    【默认numberOfLevelZeroTilesX:1,numberOfLevelZeroTilesY:1

  • 经纬度直投:new Cesium.GeographicTilingScheme()

    【默认numberOfLevelZeroTilesX:2,numberOfLevelZeroTilesY:1

 以经纬度直投为例,对tilingScheme 进一步分析:

new Cesium.GeographicTilingScheme(options)

Name

Type

Description

options

object

optionalObject with the following properties:

Name

Type

Default

Description

ellipsoid

Ellipsoid

Ellipsoid.WGS84

optionalThe ellipsoid whose surface is being tiled. Defaults to the WGS84 ellipsoid.

rectangle

Rectangle

Rectangle.MAX_VALUE

optionalThe rectangle, in radians, covered by the tiling scheme.

numberOfLevelZeroTilesX

number

2

optionalThe number of tiles in the X direction at level zero of the tile tree.

numberOfLevelZeroTilesY

number

1

optionalThe number of tiles in the Y direction at level zero of the tile tree.

 

  • ellipsoid为切片椭球,默认为wgs84坐标系,一般情况下不做修改,使用经纬度直投,初始切片级别将全球一分为二(见图2),初始级别分辨率为180/256=0.703125(两列一行)

  注:由于国家2000坐标(4490)的球体与wgs84相差不大,一般不会去修改,如有需要可进一步修改椭球参数,具体查看相应API文档。

  • rectangle:切片范围,默认为全球范围,即(-180~180,-90~90)

  east: 3.141592653589793

  north: 1.5707963267948966

  south: -1.5707963267948966

  west: -3.141592653589793

  height: 3.141592653589793

  width: 6.283185307179586

  • numberOfLevelZeroTilesX:起始级别列方向切片数
  • numberOfLevelZeroTilesY:起始级别行方向切片数

 起始级别行列方向切片数可配合tileMatrixLabels使用,如天地图切片方案:

http://t0.tianditu.gov.cn/img_c/wmts?SERVICE=WMTS&VERSION=version&REQUEST=GetCapabilities&tk=xxx
复制代码
<Capabilities 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" xsi:schemaLocation="http://www.opengis.net/wmts/1.0 http://schemas.opengis.net/wmts/1.0.0/wmtsGetCapabilities_response.xsd" version="1.0.0">
<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.gov.cn</ows:ProviderSite>
<ows:ServiceContact>
<ows:IndividualName>Mr Wang</ows:IndividualName>
<ows:PositionName>Software Engineer</ows:PositionName>
<ows:ContactInfo>
<ows:Phone>
<ows:Voice>010-63881203</ows:Voice>
<ows:Facsimile>010-63881203</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>100830</ows:PostalCode>
<ows:ElectronicMailAddress>tdt@ngcc.cn</ows:ElectronicMailAddress>
</ows:Address>
<ows:OnlineResource xlink:type="simple" xlink:href="http://www.tianditu.gov.cn"/>
</ows:ContactInfo>
</ows:ServiceContact>
</ows:ServiceProvider>
<ows:OperationsMetadata>
<ows:Operation name="GetCapabilities">
<ows:DCP>
<ows:HTTP>
<ows:Get xlink:href="http://t0.tianditu.gov.cn/img_c/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.gov.cn/img_c/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>-180.0 -90.0</ows:LowerCorner>
<ows:UpperCorner>180.0 90.0</ows:UpperCorner>
</ows:WGS84BoundingBox>
<ows:BoundingBox>
<ows:LowerCorner>-180.0 -90.0</ows:LowerCorner>
<ows:UpperCorner>180.0 90.0</ows:UpperCorner>
</ows:BoundingBox>
<Style>
<ows:Identifier>default</ows:Identifier>
</Style>
<Format>tiles</Format>
<TileMatrixSetLink>
<TileMatrixSet>c</TileMatrixSet>
</TileMatrixSetLink>
</Layer>
<TileMatrixSet>
<ows:Identifier>c</ows:Identifier>
<ows:SupportedCRS>urn:ogc:def:crs:EPSG::4490</ows:SupportedCRS>
<TileMatrix>
<ows:Identifier>1</ows:Identifier>
<ScaleDenominator>2.958293554545656E8</ScaleDenominator>
<TopLeftCorner>90.0 -180.0</TopLeftCorner>
<TileWidth>256</TileWidth>
<TileHeight>256</TileHeight>
<MatrixWidth>2</MatrixWidth>
<MatrixHeight>1</MatrixHeight>
</TileMatrix>
<TileMatrix>
<ows:Identifier>2</ows:Identifier>
<ScaleDenominator>1.479146777272828E8</ScaleDenominator>
<TopLeftCorner>90.0 -180.0</TopLeftCorner>
<TileWidth>256</TileWidth>
<TileHeight>256</TileHeight>
<MatrixWidth>4</MatrixWidth>
<MatrixHeight>2</MatrixHeight>
</TileMatrix>
<TileMatrix>
<ows:Identifier>3</ows:Identifier>
<ScaleDenominator>7.39573388636414E7</ScaleDenominator>
<TopLeftCorner>90.0 -180.0</TopLeftCorner>
<TileWidth>256</TileWidth>
<TileHeight>256</TileHeight>
<MatrixWidth>8</MatrixWidth>
<MatrixHeight>4</MatrixHeight>
</TileMatrix>
<TileMatrix>
<ows:Identifier>4</ows:Identifier>
<ScaleDenominator>3.69786694318207E7</ScaleDenominator>
<TopLeftCorner>90.0 -180.0</TopLeftCorner>
<TileWidth>256</TileWidth>
<TileHeight>256</TileHeight>
<MatrixWidth>16</MatrixWidth>
<MatrixHeight>8</MatrixHeight>
</TileMatrix>
<TileMatrix>
<ows:Identifier>5</ows:Identifier>
<ScaleDenominator>1.848933471591035E7</ScaleDenominator>
<TopLeftCorner>90.0 -180.0</TopLeftCorner>
<TileWidth>256</TileWidth>
<TileHeight>256</TileHeight>
<MatrixWidth>32</MatrixWidth>
<MatrixHeight>16</MatrixHeight>
</TileMatrix>
<TileMatrix>
<ows:Identifier>6</ows:Identifier>
<ScaleDenominator>9244667.357955175</ScaleDenominator>
<TopLeftCorner>90.0 -180.0</TopLeftCorner>
<TileWidth>256</TileWidth>
<TileHeight>256</TileHeight>
<MatrixWidth>64</MatrixWidth>
<MatrixHeight>32</MatrixHeight>
</TileMatrix>
<TileMatrix>
<ows:Identifier>7</ows:Identifier>
<ScaleDenominator>4622333.678977588</ScaleDenominator>
<TopLeftCorner>90.0 -180.0</TopLeftCorner>
<TileWidth>256</TileWidth>
<TileHeight>256</TileHeight>
<MatrixWidth>128</MatrixWidth>
<MatrixHeight>64</MatrixHeight>
</TileMatrix>
<TileMatrix>
<ows:Identifier>8</ows:Identifier>
<ScaleDenominator>2311166.839488794</ScaleDenominator>
<TopLeftCorner>90.0 -180.0</TopLeftCorner>
<TileWidth>256</TileWidth>
<TileHeight>256</TileHeight>
<MatrixWidth>256</MatrixWidth>
<MatrixHeight>128</MatrixHeight>
</TileMatrix>
<TileMatrix>
<ows:Identifier>9</ows:Identifier>
<ScaleDenominator>1155583.419744397</ScaleDenominator>
<TopLeftCorner>90.0 -180.0</TopLeftCorner>
<TileWidth>256</TileWidth>
<TileHeight>256</TileHeight>
<MatrixWidth>512</MatrixWidth>
<MatrixHeight>256</MatrixHeight>
</TileMatrix>
<TileMatrix>
<ows:Identifier>10</ows:Identifier>
<ScaleDenominator>577791.7098721985</ScaleDenominator>
<TopLeftCorner>90.0 -180.0</TopLeftCorner>
<TileWidth>256</TileWidth>
<TileHeight>256</TileHeight>
<MatrixWidth>1024</MatrixWidth>
<MatrixHeight>512</MatrixHeight>
</TileMatrix>
<TileMatrix>
<ows:Identifier>11</ows:Identifier>
<ScaleDenominator>288895.85493609926</ScaleDenominator>
<TopLeftCorner>90.0 -180.0</TopLeftCorner>
<TileWidth>256</TileWidth>
<TileHeight>256</TileHeight>
<MatrixWidth>2048</MatrixWidth>
<MatrixHeight>1024</MatrixHeight>
</TileMatrix>
<TileMatrix>
<ows:Identifier>12</ows:Identifier>
<ScaleDenominator>144447.92746804963</ScaleDenominator>
<TopLeftCorner>90.0 -180.0</TopLeftCorner>
<TileWidth>256</TileWidth>
<TileHeight>256</TileHeight>
<MatrixWidth>4096</MatrixWidth>
<MatrixHeight>2048</MatrixHeight>
</TileMatrix>
<TileMatrix>
<ows:Identifier>13</ows:Identifier>
<ScaleDenominator>72223.96373402482</ScaleDenominator>
<TopLeftCorner>90.0 -180.0</TopLeftCorner>
<TileWidth>256</TileWidth>
<TileHeight>256</TileHeight>
<MatrixWidth>8192</MatrixWidth>
<MatrixHeight>4096</MatrixHeight>
</TileMatrix>
<TileMatrix>
<ows:Identifier>14</ows:Identifier>
<ScaleDenominator>36111.98186701241</ScaleDenominator>
<TopLeftCorner>90.0 -180.0</TopLeftCorner>
<TileWidth>256</TileWidth>
<TileHeight>256</TileHeight>
<MatrixWidth>16384</MatrixWidth>
<MatrixHeight>8192</MatrixHeight>
</TileMatrix>
<TileMatrix>
<ows:Identifier>15</ows:Identifier>
<ScaleDenominator>18055.990933506204</ScaleDenominator>
<TopLeftCorner>90.0 -180.0</TopLeftCorner>
<TileWidth>256</TileWidth>
<TileHeight>256</TileHeight>
<MatrixWidth>32768</MatrixWidth>
<MatrixHeight>16384</MatrixHeight>
</TileMatrix>
<TileMatrix>
<ows:Identifier>16</ows:Identifier>
<ScaleDenominator>9027.995466753102</ScaleDenominator>
<TopLeftCorner>90.0 -180.0</TopLeftCorner>
<TileWidth>256</TileWidth>
<TileHeight>256</TileHeight>
<MatrixWidth>65536</MatrixWidth>
<MatrixHeight>32768</MatrixHeight>
</TileMatrix>
<TileMatrix>
<ows:Identifier>17</ows:Identifier>
<ScaleDenominator>4513.997733376551</ScaleDenominator>
<TopLeftCorner>90.0 -180.0</TopLeftCorner>
<TileWidth>256</TileWidth>
<TileHeight>256</TileHeight>
<MatrixWidth>131072</MatrixWidth>
<MatrixHeight>65536</MatrixHeight>
</TileMatrix>
<TileMatrix>
<ows:Identifier>18</ows:Identifier>
<ScaleDenominator>2256.998866688275</ScaleDenominator>
<TopLeftCorner>90.0 -180.0</TopLeftCorner>
<TileWidth>256</TileWidth>
<TileHeight>256</TileHeight>
<MatrixWidth>262144</MatrixWidth>
<MatrixHeight>131072</MatrixHeight>
</TileMatrix>
</TileMatrixSet>
</Contents>
</Capabilities>
复制代码

天地图1级为初始切片级别:1级切为两列一行,在创建WebMapTileServiceImageryProvider时设置参数:

tileMatrixLabels:["1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16", "17", "18"]
tilingScheme: new Cesium.GeographicTilingScheme({
 numberOfLevelZeroTilesX: 2,
 numberOfLevelZeroTilesY: 1
})

 

其实等同于(2级作为起始切片,2级为四列两行,依此类推3级为八列四行...):

tileMatrixLabels:["2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16", "17", "18"]
tilingScheme: new Cesium.GeographicTilingScheme({
 numberOfLevelZeroTilesX: 4,
 numberOfLevelZeroTilesY: 2
})

 一般tileMatrixLabels在设置值时候,需要分析需要加载服务的切片方案,由于默认经纬度直投的切片方案GeographicTilingScheme起始级别切片数两列一行

numberOfLevelZeroTilesX: 2,numberOfLevelZeroTilesY: 1

所以需要找到切为两列一行的级别,作为tileMatrixLabels数组的第一个值,一般看切片方案中的分辨率或者比例尺,如分辨率为0.703(180/256),或者比例尺为295497593的级别,

如果切片方案不是从第一个级别开始,则需要计算,可通过切片级别中具体的分辨率或者比例尺确定,

一般情况下,在tilingScheme为GeographicTilingScheme默认的情况下,初始级别不是0就是1,

如果加载的图层数据切片方案的级别和分辨率或比例尺与以下方案对应,则tileMatrixLabels=["0","1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16", "17", "18","19"]

复制代码
lods: [
      {level: 0, resolution : 0.703125, scale : 295497593.05875004},
      {level: 1, resolution : 0.3515625, scale : 147748796.52937502},
      {level: 2, resolution : 0.17578125, scale : 73874398.264687508},
      {level: 3, resolution : 0.087890625, scale : 36937199.132343754},
      {level: 4, resolution : 0.0439453125, scale : 18468599.566171877},
      {level: 5, resolution : 0.02197265625, scale : 9234299.7830859385},
      {level: 6, resolution : 0.010986328125, scale : 4617149.8915429693},
      {level: 7, resolution : 0.0054931640625, scale : 2308574.9457714846},
      {level: 8, resolution : 0.00274658203125, scale : 1154287.4728857423},
      {level: 9, resolution : 0.001373291015625, scale : 577143.73644287116},
      {level: 10, resolution : 0.0006866455078125, scale : 288571.86822143558},
      {level: 11, resolution : 0.00034332275390625, scale : 144285.93411071779},
      {level: 12, resolution : 0.000171661376953125, scale : 72142.967055358895},
      {level: 13, resolution : 8.58306884765625e-005, scale : 36071.483527679447},
      {level: 14, resolution : 4.291534423828125e-005, scale : 18035.741763839724},
      {level: 15, resolution : 2.1457672119140625e-005, scale : 9017.8708819198619},
      {level: 16, resolution : 1.0728836059570313e-005, scale : 4508.9354409599309},
      {level: 17, resolution : 5.3644180297851563e-006, scale : 2254.4677204799655},
      {level: 18, resolution: 2.68220901489257815e-006, scale: 1127.23386023998275 },
      {level: 19, resolution: 1.341104507446289075e-006, scale: 563.616930119991375 }
    ]
复制代码

 

如果加载的图层数据切片方案的级别和分辨率或比例尺与以下方案对应,则tileMatrixLabels=["1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16", "17", "18","19","20"]

 

复制代码
lods: [
      {level: 1, resolution : 0.703125, scale : 295497593.05875004},
      {level: 2, resolution : 0.3515625, scale : 147748796.52937502},
      {level: 3, resolution : 0.17578125, scale : 73874398.264687508},
      {level: 4, resolution : 0.087890625, scale : 36937199.132343754},
      {level: 5, resolution : 0.0439453125, scale : 18468599.566171877},
      {level: 6, resolution : 0.02197265625, scale : 9234299.7830859385},
      {level: 7, resolution : 0.010986328125, scale : 4617149.8915429693},
      {level: 8, resolution : 0.0054931640625, scale : 2308574.9457714846},
      {level: 9, resolution : 0.00274658203125, scale : 1154287.4728857423},
      {level: 10, resolution : 0.001373291015625, scale : 577143.73644287116},
      {level: 11, resolution : 0.0006866455078125, scale : 288571.86822143558},
      {level: 12, resolution : 0.00034332275390625, scale : 144285.93411071779},
      {level: 13, resolution : 0.000171661376953125, scale : 72142.967055358895},
      {level: 14, resolution : 8.58306884765625e-005, scale : 36071.483527679447},
      {level: 15, resolution : 4.291534423828125e-005, scale : 18035.741763839724},
      {level: 16, resolution : 2.1457672119140625e-005, scale : 9017.8708819198619},
      {level: 17, resolution : 1.0728836059570313e-005, scale : 4508.9354409599309},
      {level: 18, resolution : 5.3644180297851563e-006, scale : 2254.4677204799655},
      {level: 19, resolution: 2.68220901489257815e-006, scale: 1127.23386023998275 },
      {level: 20, resolution: 1.341104507446289075e-006, scale: 563.616930119991375 }
    ]
复制代码

 

 

 

注:对于经纬度直投,比例尺值并非固定上述列的值,由于dpi或其他参数设置不同的原因,比例尺的值并不完全相同,所以对于切片方案没列出分辨率只有比例尺的情况下,一般看数值接近的级别即可。

 

注:比例尺值计算可能存在一定偏差,参考使用。

 实例:

根据上述原理,使用Cesium加载山东省天地图。

山东省天地图切片方案:

https://www.sdmap.gov.cn/tileservice/SDRasterPubMap?SERVICE=WMTS&VERSION=version&REQUEST=GetCapabilities

复制代码
<Capabilities xmlns="http://www.opengis.net/wmts/1.0" xmlns:ows="http://www.opengis.net/ows/1.1" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:gml="http://www.opengis.net/gml" xsi:schemaLocation="http://www.opengis.net/wmts/1.0 ../wmtsGetCapabilities_response.xsd" version="1.0.0">
<ows:ServiceIdentification>
<ows:Title>山东影像地图</ows:Title>
<ows:Abstract>山东影像地图</ows:Abstract>
<ows:Keywords>
<ows:Keyword>山东</ows:Keyword>
<ows:Keyword>影像地图</ows:Keyword>
</ows:Keywords>
<ows:ServiceType>OGC WMTS</ows:ServiceType>
<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 xlink:href="https://www.sdmap.gov.cn/"/>
<ows:ServiceContact>
<ows:IndividualName/>
<ows:PositionName/>
<ows:ContactInfo>
<ows:Phone>
<ows:Voice/>
<ows:Facsimile/>
</ows:Phone>
<ows:Address>
<ows:DeliveryPoint>山东省济南市经十东路临港南区2301号</ows:DeliveryPoint>
<ows:City>济南</ows:City>
<ows:AdministrativeArea>E座4楼</ows:AdministrativeArea>
<ows:PostalCode>250100</ows:PostalCode>
<ows:Country>中国</ows:Country>
<ows:ElectronicMailAddress/>
</ows:Address>
</ows:ContactInfo>
</ows:ServiceContact>
</ows:ServiceProvider>
<ows:OperationsMetadata>
<ows:Operation name="GetCapabilities">
<ows:DCP>
<ows:HTTP>
<ows:Get xlink:href="https://www.sdmap.gov.cn/tileservice/SDRasterPubMap">
<ows:Constraint name="GetEncoding">
<ows:AllowedValues>
<ows:Value>KVP</ows:Value>
</ows:AllowedValues>
</ows:Constraint>
</ows:Get>
<ows:Post xlink:href="http://www.maps.bob/maps.cgi?">
<ows:Constraint name="PostEncoding">
<ows:AllowedValues>
<ows:Value>SOAP</ows:Value>
</ows:AllowedValues>
</ows:Constraint>
</ows:Post>
</ows:HTTP>
</ows:DCP>
</ows:Operation>
<ows:Operation name="GetTile">
<ows:DCP>
<ows:HTTP>
<ows:Get xlink:href="https://www.sdmap.gov.cn/tileservice/SDRasterPubMap">
<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>山东影像地图</ows:Title>
<ows:Abstract>山东影像地图</ows:Abstract>
<ows:Identifier>SDRasterPubMap</ows:Identifier>
<ows:WGS84BoundingBox>
<ows:LowerCorner>114.229839088925 33.9389305555556</ows:LowerCorner>
<ows:UpperCorner>123.400530149205 38.9048194444444</ows:UpperCorner>
</ows:WGS84BoundingBox>
<BoundingBox>
<ows:LowerCorner>33.9389305555556 114.229839088925</ows:LowerCorner>
<ows:UpperCorner>38.9048194444444 123.400530149205</ows:UpperCorner>
<ows:crs>EPSG:4490</ows:crs>
</BoundingBox>
<ows:Metadata xlink:href="http://www.maps.bob/etopo2/ metadata.htm"/>
<Style isDefault="true">
<ows:Title>default</ows:Title>
<ows:Identifier>default</ows:Identifier>
<LegendURL format="image/jpeg" xlink:href="http://www.maps.bob/etopo2/legend.png"/>
</Style>
<InfoFormat>application/gml+xml; version=3.1</InfoFormat>
<TileMatrixSetLink>
<TileMatrixSet>raster</TileMatrixSet>
</TileMatrixSetLink>
<Format>image/jpeg</Format>
<TileMatrixSetLink xmlns="">
<TileMatrixSet>raster</TileMatrixSet>
</TileMatrixSetLink>
</Layer>
<TileMatrixSet>
<ows:Identifier>raster</ows:Identifier>
<ows:SupportedCRS>EPSG:4490</ows:SupportedCRS>
<TileMatrix>
<ows:Identifier>7</ows:Identifier>
<ScaleDenominator>4622334</ScaleDenominator>
<TopLeftCorner>-180 90</TopLeftCorner>
<TileWidth>256</TileWidth>
<TileHeight>256</TileHeight>
<MatrixWidth>6</MatrixWidth>
<MatrixHeight>4</MatrixHeight>
</TileMatrix>
<TileMatrix>
<ows:Identifier>8</ows:Identifier>
<ScaleDenominator>2311166.84</ScaleDenominator>
<TopLeftCorner>-180 90</TopLeftCorner>
<TileWidth>256</TileWidth>
<TileHeight>256</TileHeight>
<MatrixWidth>6</MatrixWidth>
<MatrixHeight>4</MatrixHeight>
</TileMatrix>
<TileMatrix>
<ows:Identifier>9</ows:Identifier>
<ScaleDenominator>1155583.42</ScaleDenominator>
<TopLeftCorner>-180 90</TopLeftCorner>
<TileWidth>256</TileWidth>
<TileHeight>256</TileHeight>
<MatrixWidth>6</MatrixWidth>
<MatrixHeight>4</MatrixHeight>
</TileMatrix>
<TileMatrix>
<ows:Identifier>10</ows:Identifier>
<ScaleDenominator>577791.71</ScaleDenominator>
<TopLeftCorner>-180 90</TopLeftCorner>
<TileWidth>256</TileWidth>
<TileHeight>256</TileHeight>
<MatrixWidth>6</MatrixWidth>
<MatrixHeight>4</MatrixHeight>
</TileMatrix>
<TileMatrix>
<ows:Identifier>11</ows:Identifier>
<ScaleDenominator>288895.85</ScaleDenominator>
<TopLeftCorner>-180 90</TopLeftCorner>
<TileWidth>256</TileWidth>
<TileHeight>256</TileHeight>
<MatrixWidth>6</MatrixWidth>
<MatrixHeight>4</MatrixHeight>
</TileMatrix>
<TileMatrix>
<ows:Identifier>12</ows:Identifier>
<ScaleDenominator>144447.93</ScaleDenominator>
<TopLeftCorner>-180 90</TopLeftCorner>
<TileWidth>256</TileWidth>
<TileHeight>256</TileHeight>
<MatrixWidth>6</MatrixWidth>
<MatrixHeight>4</MatrixHeight>
</TileMatrix>
<TileMatrix>
<ows:Identifier>13</ows:Identifier>
<ScaleDenominator>72223.96</ScaleDenominator>
<TopLeftCorner>-180 90</TopLeftCorner>
<TileWidth>256</TileWidth>
<TileHeight>256</TileHeight>
<MatrixWidth>6</MatrixWidth>
<MatrixHeight>4</MatrixHeight>
</TileMatrix>
<TileMatrix>
<ows:Identifier>14</ows:Identifier>
<ScaleDenominator>36111.98</ScaleDenominator>
<TopLeftCorner>-180 90</TopLeftCorner>
<TileWidth>256</TileWidth>
<TileHeight>256</TileHeight>
<MatrixWidth>6</MatrixWidth>
<MatrixHeight>4</MatrixHeight>
</TileMatrix>
<TileMatrix>
<ows:Identifier>15</ows:Identifier>
<ScaleDenominator>18055.99</ScaleDenominator>
<TopLeftCorner>-180 90</TopLeftCorner>
<TileWidth>256</TileWidth>
<TileHeight>256</TileHeight>
<MatrixWidth>6</MatrixWidth>
<MatrixHeight>4</MatrixHeight>
</TileMatrix>
<TileMatrix>
<ows:Identifier>16</ows:Identifier>
<ScaleDenominator>9028</ScaleDenominator>
<TopLeftCorner>-180 90</TopLeftCorner>
<TileWidth>256</TileWidth>
<TileHeight>256</TileHeight>
<MatrixWidth>6</MatrixWidth>
<MatrixHeight>4</MatrixHeight>
</TileMatrix>
<TileMatrix>
<ows:Identifier>17</ows:Identifier>
<ScaleDenominator>4514</ScaleDenominator>
<TopLeftCorner>-180 90</TopLeftCorner>
<TileWidth>256</TileWidth>
<TileHeight>256</TileHeight>
<MatrixWidth>6</MatrixWidth>
<MatrixHeight>4</MatrixHeight>
</TileMatrix>
<TileMatrix>
<ows:Identifier>18</ows:Identifier>
<ScaleDenominator>2257</ScaleDenominator>
<TopLeftCorner>-180 90</TopLeftCorner>
<TileWidth>256</TileWidth>
<TileHeight>256</TileHeight>
<MatrixWidth>6</MatrixWidth>
<MatrixHeight>4</MatrixHeight>
</TileMatrix>
</TileMatrixSet>
</Contents>
</Capabilities>
复制代码

 

 分析:山东天地图的切片方案是从第七级开始,切片方案中没有分辨率,只有比例尺,7级切片的比例尺是4622334,与4617149.8915429693相近,对应的是1级为初始级别的切片方案

{level: 7, resolution : 0.010986328125, scale : 4617149.8915429693},
所以:
tileMatrixLabels=["1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16", "17", "18","19","20"]

cesium加载示例:

 

复制代码
//测试,加载全国天地图
var tdtImageryProvider ImageryProvider = new Cesium.WebMapTileServiceImageryProvider({
    url: 'http://t0.tianditu.gov.cn/img_c/wmts?tk=41b698f3f13b611268b449b6685a45d3', //服务地址 
    layer: "img", //图层名称,
    style: 'default',
    format: 'image/png',
    tileMatrixSetID:'c',
    tileMatrixLabels: ["2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16", "17", "18"],
    tilingScheme: new Cesium.GeographicTilingScheme({
        numberOfLevelZeroTilesX: 4,
        numberOfLevelZeroTilesY: 2
        })
    });
    var tdtLayer = new Cesium.ImageryLayer(tdtImageryProvider);    
    viewer.imageryLayers.add(tdtLayer);
    
//测试,加载山东天地图
var sdImageryProvider=new Cesium.WebMapTileServiceImageryProvider({
    url: 'http: //www.sdmap.gov.cn/tileservice/SDRasterPubMap',//山东影像4490 7-18
    layer: 'BigdataBg',//图层名称
    style: 'default',
    format: 'image/jpeg',
    tileMatrixSetID: 'BigdataSdmapBlack',
    tileMatrixLabels: ["1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16", "17", "18","19","20"],
    tilingScheme: new Cesium.GeographicTilingScheme()
    })
});
viewer.imageryLayers.addImageryProvider(sdImageryProvider);
复制代码

 

 

 

注:全国天地图故意设置 tileMatrixLabels从2级开始,GeographicTilingScheme设置为四列两行,经测试,通过验证。

实际加载效果:

 

 




posted @   孤草之魂  阅读(1723)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 全程不用写代码,我用AI程序员写了一个飞机大战
· DeepSeek 开源周回顾「GitHub 热点速览」
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· 记一次.NET内存居高不下排查解决与启示
· 白话解读 Dapr 1.15:你的「微服务管家」又秀新绝活了
点击右上角即可分享
微信分享提示