您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

BaiduImageryProvider.js 4.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  1. /**
  2. * @Author: Caven
  3. * @Date: 2020-01-15 20:27:27
  4. */
  5. import { Cesium } from '@dc-modules/namespace'
  6. import ImageryType from '../ImageryType'
  7. import BaiduMercatorTilingScheme from '../tiling-scheme/BaiduMercatorTilingScheme'
  8. const IMG_URL =
  9. 'http://shangetu{s}.map.bdimg.com/it/u=x={x};y={y};z={z};v=009;type=sate&fm=46'
  10. const VEC_URL =
  11. 'http://online{s}.map.bdimg.com/tile/?qt=tile&x={x}&y={y}&z={z}&styles=sl&v=020'
  12. const CUSTOM_URL =
  13. 'http://api{s}.map.bdimg.com/customimage/tile?&x={x}&y={y}&z={z}&scale=1&customid={style}'
  14. const TRAFFIC_URL =
  15. 'http://its.map.baidu.com:8002/traffic/TrafficTileService?time={time}&label={labelStyle}&v=016&level={z}&x={x}&y={y}&scaler=2'
  16. class BaiduImageryProvider {
  17. constructor(options = {}) {
  18. this._url =
  19. options.style === 'img'
  20. ? IMG_URL
  21. : options.style === 'vec'
  22. ? VEC_URL
  23. : options.style === 'traffic'
  24. ? TRAFFIC_URL
  25. : CUSTOM_URL
  26. this._labelStyle = options.labelStyle || 'web2D'
  27. this._tileWidth = 256
  28. this._tileHeight = 256
  29. this._maximumLevel = 18
  30. this._crs = options.crs || 'BD09'
  31. if (options.crs === 'WGS84') {
  32. let resolutions = []
  33. for (let i = 0; i < 19; i++) {
  34. resolutions[i] = 256 * Math.pow(2, 18 - i)
  35. }
  36. this._tilingScheme = new BaiduMercatorTilingScheme({
  37. resolutions,
  38. rectangleSouthwestInMeters: new Cesium.Cartesian2(
  39. -20037726.37,
  40. -12474104.17
  41. ),
  42. rectangleNortheastInMeters: new Cesium.Cartesian2(
  43. 20037726.37,
  44. 12474104.17
  45. )
  46. })
  47. } else {
  48. this._tilingScheme = new Cesium.WebMercatorTilingScheme({
  49. rectangleSouthwestInMeters: new Cesium.Cartesian2(-33554054, -33746824),
  50. rectangleNortheastInMeters: new Cesium.Cartesian2(33554054, 33746824)
  51. })
  52. }
  53. this._rectangle = this._tilingScheme.rectangle
  54. this._credit = undefined
  55. this._token = undefined
  56. this._style = options.style || 'normal'
  57. }
  58. get url() {
  59. return this._url
  60. }
  61. get token() {
  62. return this._token
  63. }
  64. get tileWidth() {
  65. if (!this.ready) {
  66. throw new Cesium.DeveloperError(
  67. 'tileWidth must not be called before the imagery provider is ready.'
  68. )
  69. }
  70. return this._tileWidth
  71. }
  72. get tileHeight() {
  73. if (!this.ready) {
  74. throw new Cesium.DeveloperError(
  75. 'tileHeight must not be called before the imagery provider is ready.'
  76. )
  77. }
  78. return this._tileHeight
  79. }
  80. get maximumLevel() {
  81. if (!this.ready) {
  82. throw new Cesium.DeveloperError(
  83. 'maximumLevel must not be called before the imagery provider is ready.'
  84. )
  85. }
  86. return this._maximumLevel
  87. }
  88. get minimumLevel() {
  89. if (!this.ready) {
  90. throw new Cesium.DeveloperError(
  91. 'minimumLevel must not be called before the imagery provider is ready.'
  92. )
  93. }
  94. return 0
  95. }
  96. get tilingScheme() {
  97. if (!this.ready) {
  98. throw new Cesium.DeveloperError(
  99. 'tilingScheme must not be called before the imagery provider is ready.'
  100. )
  101. }
  102. return this._tilingScheme
  103. }
  104. get rectangle() {
  105. if (!this.ready) {
  106. throw new Cesium.DeveloperError(
  107. 'rectangle must not be called before the imagery provider is ready.'
  108. )
  109. }
  110. return this._rectangle
  111. }
  112. get ready() {
  113. return !!this._url
  114. }
  115. get credit() {
  116. return this._credit
  117. }
  118. get hasAlphaChannel() {
  119. return true
  120. }
  121. getTileCredits(x, y, level) {}
  122. /**
  123. * Request Image
  124. * @param x
  125. * @param y
  126. * @param level
  127. * @returns {Promise<HTMLImageElement | HTMLCanvasElement>}
  128. */
  129. requestImage(x, y, level) {
  130. if (!this.ready) {
  131. throw new Cesium.DeveloperError(
  132. 'requestImage must not be called before the imagery provider is ready.'
  133. )
  134. }
  135. let xTiles = this._tilingScheme.getNumberOfXTilesAtLevel(level)
  136. let yTiles = this._tilingScheme.getNumberOfYTilesAtLevel(level)
  137. let url = this._url
  138. .replace('{z}', level)
  139. .replace('{s}', String(1))
  140. .replace('{style}', this._style)
  141. .replace('{labelStyle}', this._labelStyle)
  142. .replace('{time}', String(new Date().getTime()))
  143. if (this._crs === 'WGS84') {
  144. url = url.replace('{x}', String(x)).replace('{y}', String(-y))
  145. } else {
  146. url = url
  147. .replace('{x}', String(x - xTiles / 2))
  148. .replace('{y}', String(yTiles / 2 - y - 1))
  149. }
  150. return Cesium.ImageryProvider.loadImage(this, url)
  151. }
  152. }
  153. ImageryType.BAIDU = 'baidu'
  154. export default BaiduImageryProvider