-
-
Notifications
You must be signed in to change notification settings - Fork 123
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
490 additions
and
550 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
{ | ||
"name": "@dvgis/cesium-map", | ||
"version": "3.1.0", | ||
"version": "4.0.0", | ||
"repository": "https://github.com/dvgis/cesium-map.git", | ||
"homepage": "https://www.dvgis.cn", | ||
"author": "Caven Chen <[email protected]>", | ||
|
@@ -14,7 +14,7 @@ | |
"tencent", | ||
"tdt" | ||
], | ||
"main": "dist/index.cjs", | ||
"main": "dist/index.js", | ||
"type": "module", | ||
"scripts": { | ||
"build": "rimraf dist && gulp build", | ||
|
@@ -28,11 +28,9 @@ | |
"@babel/plugin-proposal-class-properties": "^7.18.6", | ||
"@babel/plugin-transform-runtime": "^7.21.4", | ||
"@babel/preset-env": "^7.21.5", | ||
"@rollup/plugin-babel": "^6.0.3", | ||
"@rollup/plugin-commonjs": "^25.0.0", | ||
"@rollup/plugin-node-resolve": "^15.0.2", | ||
"@rollup/plugin-terser": "^0.4.1", | ||
"esbuild": "^0.20.2", | ||
"esbuild-plugin-external-global": "^1.0.1", | ||
"esbuild-plugin-globals": "^0.2.0", | ||
"eslint": "^8.40.0", | ||
"eslint-config-prettier": "^8.8.0", | ||
"eslint-plugin-import": "^2.27.5", | ||
|
@@ -41,11 +39,10 @@ | |
"eslint-plugin-promise": "^6.1.1", | ||
"gulp": "^4.0.2", | ||
"prettier": "^2.8.8", | ||
"rimraf": "^5.0.0", | ||
"rollup": "^3.21.8" | ||
"rimraf": "^5.0.0" | ||
}, | ||
"dependencies": { | ||
"@cesium/engine": "^2.4.0" | ||
"peerDependencies": { | ||
"@cesium/engine": "^9.0.0" | ||
}, | ||
"files": [ | ||
"dist", | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
/** | ||
* @Author: Caven | ||
* @Date: 2024-04-06 20:40:25 | ||
*/ | ||
import { | ||
GeographicTilingScheme, | ||
Math as CesiumMath, | ||
Cartesian2, | ||
Rectangle, | ||
defined, | ||
} from '@cesium/engine' | ||
|
||
class CustomGeographicTilingScheme extends GeographicTilingScheme { | ||
constructor(options = {}) { | ||
super(options) | ||
this._origin = options.origin || [-180, 90] | ||
this._zoomOffset = options.zoomOffset || 0 | ||
this._tileSize = options.tileSize || 256 | ||
this._resolutions = options.resolutions || [] | ||
} | ||
|
||
get zoomOffset() { | ||
return this._zoomOffset | ||
} | ||
|
||
tileXYToRectangle(x, y, level, result) { | ||
if (!this._resolutions || !this._resolutions[level + this._zoomOffset]) { | ||
return Rectangle.MAX_VALUE | ||
} | ||
|
||
const tileRes = this._resolutions[level + this._zoomOffset] * this._tileSize | ||
const west = CesiumMath.toRadians(this._origin[0] + x * tileRes) | ||
const south = CesiumMath.toRadians(this._origin[1] - (y + 1) * tileRes) | ||
const east = CesiumMath.toRadians(this._origin[0] + (x + 1) * tileRes) | ||
const north = CesiumMath.toRadians(this._origin[1] - y * tileRes) | ||
if (!defined(result)) { | ||
return new Rectangle(west, south, east, north) | ||
} | ||
result.west = west | ||
result.south = south | ||
result.east = east | ||
result.north = north | ||
return result | ||
} | ||
|
||
positionToTileXY(position, level, result) { | ||
if (!this._resolutions || !this._resolutions[level + this._zoomOffset]) { | ||
return new Cartesian2() | ||
} | ||
const tileRes = this._resolutions[level + this._zoomOffset] * this._tileSize | ||
const longitude = CesiumMath.toDegrees(position.longitude) | ||
const latitude = CesiumMath.toDegrees(position.latitude) | ||
// Calculate the tile row and column numbers in the current coordinate system | ||
const xTileCoordinate = Math.floor((longitude - this._origin[0]) / tileRes) | ||
const yTileCoordinate = Math.floor((this._origin[1] - latitude) / tileRes) | ||
if (!defined(result)) { | ||
return new Cartesian2( | ||
Math.max(0, xTileCoordinate), | ||
Math.max(0, yTileCoordinate) | ||
) | ||
} | ||
result.x = xTileCoordinate | ||
result.y = yTileCoordinate | ||
return result | ||
} | ||
} | ||
|
||
export default CustomGeographicTilingScheme |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
/** | ||
* @Author: Caven | ||
* @Date: 2024-04-06 20:40:25 | ||
*/ | ||
|
||
import { | ||
WebMercatorTilingScheme, | ||
Cartesian2, | ||
Rectangle, | ||
defined, | ||
} from '@cesium/engine' | ||
|
||
class CustomMercatorTilingScheme extends WebMercatorTilingScheme { | ||
constructor(options = {}) { | ||
super(options) | ||
this._origin = options.origin || [-20037508.3427892, 20037508.3427892] | ||
this._zoomOffset = options.zoomOffset || 0 | ||
this._tileSize = options.tileSize || 256 | ||
this._resolutions = options.resolutions || [] | ||
} | ||
|
||
get zoomOffset() { | ||
return this._zoomOffset | ||
} | ||
|
||
tileXYToNativeRectangle(x, y, level, result) { | ||
if (!this._resolutions || !this._resolutions[level + this._zoomOffset]) { | ||
return Rectangle.MAX_VALUE | ||
} | ||
|
||
if (x < 0 || y < 0) { | ||
return Rectangle.MAX_VALUE | ||
} | ||
const tileRes = this._resolutions[level + this._zoomOffset] * this._tileSize | ||
let west = this._origin[0] + x * tileRes | ||
let south = this._origin[1] - (y + 1) * tileRes | ||
let east = this._origin[0] + (x + 1) * tileRes | ||
let north = this._origin[1] - y * tileRes | ||
|
||
if (!defined(result)) { | ||
return new Rectangle(west, south, east, north) | ||
} | ||
result.west = west | ||
result.south = south | ||
result.east = east | ||
result.north = north | ||
return result | ||
} | ||
|
||
positionToTileXY(position, level, result) { | ||
const rectangle = this._rectangle | ||
if (!Rectangle.contains(rectangle, position)) { | ||
return undefined | ||
} | ||
if (!this._resolutions || !this._resolutions[level + this._zoomOffset]) { | ||
return new Cartesian2() | ||
} | ||
const tileRes = this._resolutions[level + this._zoomOffset] * this._tileSize | ||
const projection = this._projection | ||
const webMercatorPosition = projection.project(position) | ||
|
||
// Calculate the tile row and column numbers in the current coordinate system | ||
const xTileCoordinate = Math.floor( | ||
(webMercatorPosition.x - this._origin[0]) / tileRes | ||
) | ||
|
||
const yTileCoordinate = Math.floor( | ||
(this._origin[1] - webMercatorPosition.y) / tileRes | ||
) | ||
if (!defined(result)) { | ||
return new Cartesian2( | ||
Math.max(0, xTileCoordinate), | ||
Math.max(0, yTileCoordinate) | ||
) | ||
} | ||
result.x = xTileCoordinate | ||
result.y = yTileCoordinate | ||
return result | ||
} | ||
} | ||
|
||
export default CustomMercatorTilingScheme |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.