mirror of
https://github.com/tengge1/ShadowEditor.git
synced 2026-02-01 16:08:17 +00:00
修复经纬度转换bug。
This commit is contained in:
parent
fa63d06233
commit
2deb28af32
@ -13,7 +13,7 @@ import WGS84 from '../core/WGS84';
|
||||
function TiledLayerRenderer(globe) {
|
||||
Renderer.call(this, globe);
|
||||
|
||||
this.creator = new SphereTileCreator(this.camera, this.globe.options);
|
||||
this.creator = new SphereTileCreator(this.globe);
|
||||
|
||||
var geometry = new TiledGeometry();
|
||||
|
||||
|
||||
@ -7,17 +7,18 @@ import GeoUtils from '../utils/GeoUtils';
|
||||
/**
|
||||
* 球形瓦片创建者
|
||||
* @author tengge / https://github.com/tengge1
|
||||
* @param {*} camera
|
||||
* @param {*} options
|
||||
* @param {*} globe
|
||||
*/
|
||||
function SphereTileCreator(camera, options) {
|
||||
TileCreator.call(this, camera, options);
|
||||
function SphereTileCreator(globe) {
|
||||
TileCreator.call(this, globe);
|
||||
|
||||
this.cache = new Map();
|
||||
|
||||
this._center = new THREE.Vector3();
|
||||
this._centerZoom = 0;
|
||||
this._projScreenMatrix = new THREE.Matrix4();
|
||||
this._frustum = new THREE.Frustum();
|
||||
// this._box = new THREE.Box2();
|
||||
// this._projScreenMatrix = new THREE.Matrix4();
|
||||
// this._frustum = new THREE.Frustum();
|
||||
|
||||
this.tiles = [];
|
||||
}
|
||||
@ -28,10 +29,11 @@ SphereTileCreator.prototype.constructor = SphereTileCreator;
|
||||
SphereTileCreator.prototype.get = function () {
|
||||
this.tiles.length = 0;
|
||||
|
||||
GeoUtils._xyzToLonlat(this.camera.position, this._center);
|
||||
this._centerZoom = ~~GeoUtils.altToZoom(this.camera.position.length() - WGS84.a) + 2;
|
||||
|
||||
this._projScreenMatrix.multiplyMatrices(this.camera.projectionMatrix, this.camera.matrixWorldInverse);
|
||||
this._frustum.setFromMatrix(this._projScreenMatrix);
|
||||
// this._projScreenMatrix.multiplyMatrices(this.camera.projectionMatrix, this.camera.matrixWorldInverse);
|
||||
// this._frustum.setFromMatrix(this._projScreenMatrix);
|
||||
|
||||
this.fork(0, 0, 1);
|
||||
this.fork(1, 0, 1);
|
||||
@ -108,24 +110,26 @@ SphereTileCreator.prototype.isVisible = function (tile) {
|
||||
return false;
|
||||
}
|
||||
|
||||
var intersect = false;
|
||||
var face = false;
|
||||
var intersect = this._center.x >= tile._aabb.min.x &&
|
||||
this._center.x <= tile._aabb.max.x &&
|
||||
this._center.y >= tile._aabb.min.y &&
|
||||
this._center.y <= tile._aabb.max.y;
|
||||
|
||||
for (var i = 0, l = tile._vertices.length; i < l; i++) {
|
||||
var vertice = tile._vertices[i];
|
||||
return intersect;
|
||||
|
||||
if (!intersect) { // TODO: 不在同一个坐标系
|
||||
intersect = this._frustum.containsPoint(vertice);
|
||||
}
|
||||
if (!face) { // TODO: 不在同一个坐标系
|
||||
face = this.camera.position.dot(vertice) > 0;
|
||||
}
|
||||
if (intersect && face) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return intersect && face;
|
||||
|
||||
// var face = false;
|
||||
|
||||
// for (var i = 0, l = tile._vertices.length; i < l; i++) {
|
||||
// var vertice = tile._vertices[i];
|
||||
// face = this.camera.position.dot(vertice) > 0;
|
||||
// if (face) {
|
||||
// break;
|
||||
// }
|
||||
// }
|
||||
|
||||
// return intersect && face;
|
||||
};
|
||||
|
||||
SphereTileCreator.prototype.dispose = function () {
|
||||
|
||||
@ -1,12 +1,13 @@
|
||||
/**
|
||||
* 瓦片创建者
|
||||
* @author tengge / https://github.com/tengge1
|
||||
* @param {*} camera
|
||||
* @param {*} options
|
||||
* @param {*} globe
|
||||
*/
|
||||
function TileCreator(camera, options) {
|
||||
this.camera = camera;
|
||||
this.options = options;
|
||||
function TileCreator(globe) {
|
||||
this.globe = globe;
|
||||
this.options = this.globe.options;
|
||||
this.camera = this.globe.camera;
|
||||
this.renderer = this.globe.renderer;
|
||||
}
|
||||
|
||||
TileCreator.prototype.get = function (lon, lat, alt) {
|
||||
@ -14,7 +15,10 @@ TileCreator.prototype.get = function (lon, lat, alt) {
|
||||
};
|
||||
|
||||
TileCreator.prototype.dispose = function () {
|
||||
delete this.globe;
|
||||
delete this.options;
|
||||
delete this.camera;
|
||||
delete this.renderer;
|
||||
};
|
||||
|
||||
export default TileCreator;
|
||||
@ -56,7 +56,7 @@ function lonlatToXYZ(lonlat, xyz) {
|
||||
* @param {THREE.Vector3} lonlat 经纬度(弧度)、海拔
|
||||
*/
|
||||
function _xyzToLonlat(xyz, lonlat) {
|
||||
var lon = Math.acos(xyz.x / Math.sqrt(xyz.x ** 2 + xyz.z ** 2));
|
||||
var lon = -Math.sign(xyz.z) * Math.acos(xyz.x / Math.sqrt(xyz.x ** 2 + xyz.z ** 2));
|
||||
var lat = Math.atan(xyz.y / Math.sqrt(xyz.x ** 2 + xyz.z ** 2));
|
||||
var alt = Math.sqrt(xyz.x ** 2 + xyz.y ** 2 + xyz.z ** 2) - WGS84.a;
|
||||
|
||||
@ -119,7 +119,7 @@ function _mercatorLat(lat) {
|
||||
* @see https://github.com/d3/d3-geo/blob/master/src/projection/mercator.js
|
||||
*/
|
||||
function mercatorLat(lat) {
|
||||
return _mercatorLat(lat * RADIAN_PER_DEGREE);
|
||||
return _mercatorLat(lat * RADIAN_PER_DEGREE) * DEGREE_PER_RADIAN;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user