Skip to content

Commit

Permalink
#15 Fix truncated geometry when switching 3D <--> 2D azimuthal
Browse files Browse the repository at this point in the history
 #9 Fix elevation
  • Loading branch information
J-Christophe committed Nov 24, 2017
1 parent 4633724 commit 15e0d61
Show file tree
Hide file tree
Showing 25 changed files with 564 additions and 335 deletions.
7 changes: 7 additions & 0 deletions examples/data/ApartOfSpain.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "FeatureCollection",
"features": [
{ "type": "Feature", "properties": { "LAYER": "Unknown Area Type", "NAME": "Spain", "GMI_CNTRY": "ESP", "REGION": "Europe" }, "geometry": { "type": "Polygon", "coordinates": [ [ [ 3.063611, 39.263599 ], [ 2.902222, 39.359711 ], [ 2.793056, 39.362492 ], [ 2.729167, 39.467770 ], [ 2.722500, 39.529991 ], [ 2.618889, 39.550270 ], [ 2.523611, 39.453041 ], [ 2.358055, 39.557491 ], [ 2.373055, 39.610821 ], [ 2.660833, 39.762760 ], [ 2.815833, 39.861660 ], [ 3.130833, 39.917488 ], [ 3.091944, 39.901371 ], [ 3.111944, 39.866379 ], [ 3.205277, 39.867489 ], [ 3.154444, 39.834709 ], [ 3.123888, 39.822491 ], [ 3.147222, 39.779430 ], [ 3.247777, 39.734711 ], [ 3.452777, 39.749989 ], [ 3.463611, 39.661381 ], [ 3.291944, 39.472488 ], [ 3.241944, 39.364429 ], [ 3.063611, 39.263599 ] ] ] } }

]
}
20 changes: 20 additions & 0 deletions src/Crs/AbstractCrs.js
Original file line number Diff line number Diff line change
Expand Up @@ -494,6 +494,24 @@ define(
return this.geoBound;
};

/**
* @function getName
* @memberOf AbstractCrs#
* @abstract
*/
AbstractCrs.prototype.getName = function () {
throw new SyntaxError("Not implemented");
};

/**
* @function isProjected
* @memberOf AbstractCrs#
* @return {boolean} True when the Crs is projected in 2D otherwise false.
*/
AbstractCrs.prototype.isProjected = function () {
return false;
};

/**
* @function destroy
* @memberOf AbstractCrs#
Expand All @@ -503,8 +521,10 @@ define(
this.geoide = null;
this.type = null;
this.geoBound = null;
this.projected = null;
};


/**************************************************************************************************************/
return AbstractCrs;
});
8 changes: 8 additions & 0 deletions src/Crs/EquatorialCrs.js
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,14 @@ define(['./AbstractCrs', '../Renderer/GeoBound', '../Utils/Utils', '../Utils/Con
}
};

/**
* @function getName
* @memberOf EquatorialCrs#
*/
EquatorialCrs.prototype.getName = function () {
return Constants.CRS.Equatorial;
};


/**************************************************************************************************************/

Expand Down
8 changes: 8 additions & 0 deletions src/Crs/GalacticCrs.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,14 @@ define(['./AbstractCrs', '../Renderer/GeoBound', '../Utils/Utils', '../Utils/Con
}
};

/**
* @function getName
* @memberOf GalacticCrs#
*/
GalacticCrs.prototype.getName = function () {
return Constants.CRS.Galactic;
};

return GalacticCrs;

});
8 changes: 8 additions & 0 deletions src/Crs/HorizontalLocalCrs.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,14 @@ define(['./AbstractCrs', '../Renderer/GeoBound', '../Utils/Utils', '../Utils/Con
//Do Nothing
};

/**
* @function getName
* @memberOf HorizontalLocalCrs#
*/
HorizontalLocalCrs.prototype.getName = function () {
return Constants.CRS.HorizontalLocal;
};

return HorizontalLocalCrs;

});
14 changes: 14 additions & 0 deletions src/Crs/InterfaceCrs.js
Original file line number Diff line number Diff line change
Expand Up @@ -283,4 +283,18 @@ Crs.prototype._setupPosAfterTrans = function (posWorld) {
* @return {GeoBound} the geo bound
*/
Crs.prototype.getGeoBound = function () {
};

/**
* Returns the CRS name
* @return {CRS} the CRS name
*/
Crs.prototype.getName = function () {
};

/**
* Returns True when the CRS is projected otherwise False
* @return {boolean} the CRS name
*/
Crs.prototype.isProjected = function () {
};
8 changes: 8 additions & 0 deletions src/Crs/Mars2000Crs.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,14 @@ define(['./AbstractCrs', '../Renderer/GeoBound', '../Utils/Utils', '../Utils/Con
//Do Nothing
};

/**
* @function getName
* @memberOf Mars2000Crs#
*/
Mars2000Crs.prototype.getName = function () {
return Constants.CRS.Mars_2000;
};

return Mars2000Crs;

});
8 changes: 8 additions & 0 deletions src/Crs/Moon2000Crs.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,14 @@ define(['./AbstractCrs', '../Renderer/GeoBound', '../Utils/Utils', '../Utils/Con
//Do Nothing
};

/**
* @function getName
* @memberOf Moon2000Crs#
*/
Moon2000Crs.prototype.getName = function () {
return Constants.CRS.Moon_2000;
};

return Moon2000Crs;

});
28 changes: 28 additions & 0 deletions src/Crs/ProjectedCrs.js
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,34 @@ define(['./AbstractCrs', '../Utils/Utils', '../Projection/ProjectionFactory','..
return dest;
};

/**
* Returns the projection.
* @function getProjection
* @memberOf ProjectedCrs
* @returns {AbstractProjection} the used projection
*/
ProjectedCrs.prototype.getProjection = function() {
return this.projection;
};

/**
* @function getName
* @memberOf ProjectedCrs#
*/
ProjectedCrs.prototype.getName = function () {
return this.cs.getName();
};

/**
* @function isProjected
* @memberOf ProjectedCrs#
* @return {boolean} True.
*/
ProjectedCrs.prototype.isProjected = function () {
return true;
};


return ProjectedCrs;

});
8 changes: 8 additions & 0 deletions src/Crs/WGS84Crs.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,14 @@ define(['./AbstractCrs', '../Renderer/GeoBound', '../Utils/Utils', '../Utils/Con
//Do Nothing
};

/**
* @function getName
* @memberOf WGS84Crs#
*/
WGS84Crs.prototype.getName = function () {
return Constants.CRS.WGS84;
};

return WGS84Crs;

});
85 changes: 81 additions & 4 deletions src/Globe/AbstractGlobe.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@
******************************************************************************/
define(['../Utils/Event', '../Utils/Utils',
'../Tiling/TileManager', '../Renderer/VectorRendererManager', '../Renderer/Ray', '../Renderer/GeoBound',
'../Crs/CoordinateSystemFactory', '../Renderer/RenderContext','../Renderer/glMatrix'],
'../Crs/CoordinateSystemFactory', '../Renderer/RenderContext', '../Utils/Constants', '../Renderer/glMatrix'],
function (Event, Utils,
TileManager, VectorRendererManager, Ray, GeoBound,
CoordinateSystemFactory, RenderContext) {
CoordinateSystemFactory, RenderContext, Constants) {


/**
Expand Down Expand Up @@ -375,10 +375,87 @@ define(['../Utils/Event', '../Utils/Utils',
* @memberOf AbstractGlobe#
*/
AbstractGlobe.prototype.setCoordinateSystem = function (coordinateSystem) {
var oldCrs = this.coordinateSystem;
this.coordinateSystem = coordinateSystem;
this.tileManager.tileConfig.coordinateSystem = coordinateSystem;
this.dispose();
this.tileManager.level0Tiles = this.tileManager.tiling.generateLevelZeroTiles(this.tileManager.tileConfig, this.tileManager.tilePool);
this.tileManager.tileConfig.coordinateSystem = coordinateSystem;
this._updateGeoTiling(oldCrs, coordinateSystem);
};

/**
* Updates the GeoTiling when the CRS changes.
* The GeoTiling for Azimuthal projection is quite different of the others. We need to check when a GeoTiling
* must be updated. Once a new GeoTiling is done then we need to update the geometry related to the old GeoTiling
* @function _updateGeoTiling
* @memberOf AbstractGlobe#
* @private
*/
AbstractGlobe.prototype._updateGeoTiling = function(oldCrs, crs) {
var mustBeUpdated;
if (crs.isProjected() && crs.getProjection().getName() === Constants.PROJECTION.Azimuth) {
if(oldCrs.isProjected() && oldCrs.getProjection().getName() === Constants.PROJECTION.Azimuth) {
// nothing to update, same projection;
mustBeUpdated = false;
} else {
// must be updated, the GeoTiling is quite different between azimuth and another one
mustBeUpdated = true;
}
} else if (oldCrs.isProjected() && oldCrs.getProjection().getName() === Constants.PROJECTION.Azimuth) {
if(crs.isProjected() && crs.getProjection().getName() === crs.PROJECTION.Azimuth) {
// nothing to update, same projection;
mustBeUpdated = false;
} else {
// must be updated, the GeoTiling is quite different between azimuth and another one
mustBeUpdated = true;
}
} else {
// nothing to update, the geoTiling is the same.
mustBeUpdated = false;
}

if(mustBeUpdated) {
this.tileManager.level0Tiles = this.tileManager.tiling.generateLevelZeroTiles(this.tileManager.tileConfig, this.tileManager.tilePool);
this._updateTileIndexInGeometry();
}
};

/**
* Updates the geometry related to the old GeoTiling to the new GeoTiling.
* @function _updateTileIndexInGeometry
* @memberOf AbstractGlobe#
* @private
*/
AbstractGlobe.prototype._updateTileIndexInGeometry = function() {
var postRenderers = this.tileManager.postRenderers;
var postRendererIdx = postRenderers.length;
// we use while, this is the fastest loop in Javascript https://jsperf.com/fastest-array-loops-in-javascript/32
while(postRendererIdx--) {
// we iterate on renderers
var postRenderer = postRenderers[postRendererIdx];
if (postRenderer instanceof VectorRendererManager) {
// we look for VectorRendererManager because this one contains geometry
var vectorRendererManager = postRenderers[postRendererIdx];
var vectors = vectorRendererManager.renderers;
var vectorIdx = vectors.length;
while(vectorIdx--) {
// we iterate on vector
var vector = vectors[vectorIdx];
if (vector.levelZeroTiledGeometries && vector.levelZeroTiledGeometries.length > 0) {
// we retrieve the geometries
var geometries = vector.levelZeroTiledGeometries;
var geometryIdx = geometries.length;
while(geometryIdx--) {
// we iterate on each geometry to update the indexed tile related to the geometry
// the (0,0) is 0, the (1,0) is 1, ....
var geometry = geometries[geometryIdx];
var tileIndices = vector.maxTilePerGeometry > 0 ? this.tileManager.tiling.getOverlappedLevelZeroTiles(geometry) : null;
// update
geometry._tileIndices = tileIndices;
}
}
}
}
}
};

/**
Expand Down
4 changes: 2 additions & 2 deletions src/Navigation/GroundNavigation.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ define(['../Utils/Utils', '../Utils/Constants',
AbstractNavigation.prototype.constructor.call(this, Constants.NAVIGATION.GroundNavigation, ctx, options);

// Default values for fov (in degrees)
this.minFov = (this.options.minFov) || 20;
this.maxFov = (this.options.maxFov) || 100;
this.minFov = (this.options.minFov) || 1;
this.maxFov = (this.options.maxFov) || 70;

// Initialize the navigation
this.center3d = [1.0, 0.0, 0.0];
Expand Down
9 changes: 7 additions & 2 deletions src/Projection/AbstractProjection.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,13 @@ define(['../Renderer/GeoBound'],
throw new SyntaxError("project not implemented", "AbstractProjection.js");
};

AbstractProjection.prototype.getDefaultZ = function () {
return 100000;
/**
* @function getName
* @memberOf AbstractProjection#
* @abstract
*/
AbstractProjection.prototype.getName = function () {
throw new SyntaxError("getName not implemented", "AbstractProjection.js");
};

/**************************************************************************************************************/
Expand Down
12 changes: 10 additions & 2 deletions src/Projection/AitoffProjection.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@
* @module Projection
* @implements {Projection}
*/
define(['./AbstractProjection', '../Utils/Utils', '../Renderer/glMatrix'],
function (AbstractProjection, Utils) {
define(['./AbstractProjection', '../Utils/Utils', '../Utils/Constants', '../Renderer/glMatrix'],
function (AbstractProjection, Utils, Constants) {
/**
* @name AitoffProjection
* @class
Expand Down Expand Up @@ -181,6 +181,14 @@ define(['./AbstractProjection', '../Utils/Utils', '../Renderer/glMatrix'],
return dest;
};

/**
* @function getName
* @memberOf AitoffProjection#
*/
AitoffProjection.prototype.getName = function() {
return Constants.PROJECTION.Aitoff;
};

/**************************************************************************************************************/

return AitoffProjection;
Expand Down
12 changes: 10 additions & 2 deletions src/Projection/AugustProjection.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
* along with GlobWeb. If not, see <http://www.gnu.org/licenses/>.
***************************************/

define(['./AbstractProjection', '../Utils/Utils', '../Renderer/glMatrix'],
function (AbstractProjection, Utils) {
define(['./AbstractProjection', '../Utils/Utils', '../Utils/Constants', '../Renderer/glMatrix'],
function (AbstractProjection, Utils, Constants) {
/**
* @name AugustProjection
* @class
Expand Down Expand Up @@ -79,6 +79,14 @@ define(['./AbstractProjection', '../Utils/Utils', '../Renderer/glMatrix'],
return dest;
};

/**
* @function getName
* @memberOf AugustProjection#
*/
AugustProjection.prototype.getName = function() {
return Constants.PROJECTION.August;
};

/**************************************************************************************************************/

return AugustProjection;
Expand Down
Loading

0 comments on commit 15e0d61

Please sign in to comment.