Cesium uses WebMapTileServiceImageryProvider

The project needs to have a function of switching the base map, and I want to add it directly in the original BaseLayerPicker of cesium. But there is a base map that is not free, it is a geological cloud that uses a third-party token. So record the solution here.

What was directly given to me was a URL link with a token value, and the format was almost like this:

https://网址:端口/xx/xxx/xxx//WMTSServer/1.0.0/xxxxx.xml?参数名=token值

Put this URL into the browser and return an xml data format. There is no way to start, and I didn't even think of using the WebMapTileServiceImageryProvider method at the beginning.

But there is a screenshot, which should be a part of the configuration file, which was taken on other projects. It has a type designation "OGCWMTS". So, I found inspiration in this article:

https://blog.csdn.net/thor027/article/details/112236685 icon-default.png?t=M4ADhttps://blog.csdn.net/thor027/article/details/112236685 The knowledge obtained is that I need to use WebMapTileServiceImageryProvider to obtain, and then it There are two coordinate systems to be aware of.

So, I went to see the official documentation of cesium to explain this method. So I found the example, and visited the link address, and also returned an xml data.

 I compared them one by one, and filled in the parameters in the document example against the corresponding positions in the xml file. Then I tried it, but still no map came out. With doubts I found this article:

https://www.freesion.com/article/8229929604/ icon-default.png?t=M4ADhttps://www.freesion.com/article/8229929604/ Then I instantly understood why the official website example gave two services with similar addresses. Because there is specified information in the xml content file. Take the xml example on the official website as an example:

<ResourceURL format="image/jpgpng" resourceType="tile" template="https://basemap.nationalmap.gov/arcgis/rest/services/USGSShadedReliefOnly/MapServer/WMTS/tile/1.0.0/USGSShadedReliefOnly/{Style}/{TileMatrixSet}/{TileMatrix}/{TileRow}/{TileCol}"/>

 Find the ResourceURL tag in the xml file, and then directly copy the content of the template to the url of the WebMapTileServiceImageryProvider configuration item. The content of the format is copied to the corresponding format.

Find the <ows:Identifier></ows:Identifier> tag in the Layer tag in the xml file, and fill in the content inside the layer.

Find <TileMatrixSet> in the layer tag in the xml file, and fill in the content in tileMatrixSetID

Then create a new array, and put the characters you find at the beginning of EPSG:, colon: and ending with a number into the array. Fill in the tileMatrixLabels inside.

Then look at the number behind EPSG, and change the corresponding method of tilingScheme according to the above article.

The maximumLevel fills in the length of the array.

Then the geological cloud map can appear.

Full code:

const dizhiyun_tileMatrix = ['EPSG:4326:0','EPSG:4326:1','EPSG:4326:2','EPSG:4326:3','EPSG:4326:4','EPSG:4326:5','EPSG:4326:6','EPSG:4326:7','EPSG:4326:8','EPSG:4326:9','EPSG:4326:10','EPSG:4326:11','EPSG:4326:12','EPSG:4326:13']
let dizhiyun = new Cesium.WebMapTileServiceImageryProvider({'https://igss.cgs.gov.cn:6160/xxxxxxxxxxxxxxxxx/WMTSServer/1.0.0/xxxxxxxxx/{Style}/{TileMatrixSet}/{TileMatrix}/{TileRow}/{TileCol}.png?tk=申请的token',

                style: "default",
                format: "PNG",
                layer: "找到的layer内容",
                tileMatrixSetID:"EPSG:    找到的完整内容",
                tileMatrixLabels: dizhiyun_tileMatrix,
                tilingScheme: new Cesium.GeographicTilingScheme({    // 我是4326类型的
                    numberOfLevelZeroTilesX: 2,
                    numberOfLevelZeroTilesY: 1
                }),
                maximumLevel:14    // 我的数组长度是14
        });

Summary method steps:

1. Whether the access URL can return data results.

2. Find the url address with braces in xml

3. Find the corresponding value and fill it in

Guess you like

Origin blog.csdn.net/GhostPaints/article/details/124804754