Dear all:
The Cesium code often uses the following pattern:
var Cartographic = function(longitude, latitude, height) {
this.longitude = defaultValue(longitude, 0.0);
this.latitude = defaultValue(latitude, 0.0);
this.height = defaultValue(height, 0.0);
};
Cartographic.fromDegrees = function(longitude, latitude, height**, result**) {
longitude = CesiumMath.toRadians(defaultValue(longitude, 0.0));
latitude = CesiumMath.toRadians(defaultValue(latitude, 0.0));
height = defaultValue(height, 0.0);
if (typeof result === 'undefined') {
return new Cartographic(longitude, latitude, height);
}
result.longitude = longitude;
result.latitude = latitude;
result.height = height;
return result;
};
I think it is not that good because of:
-
code duplication,
-
not really OOP (result as a parameter).
A better pattern would be:
carto = new Cartographic();
carto.fromDegrees(…); // OO
It could require a lot of small changes in the code base but I can volunteer to implement if you feel it’s valuable.
Cheers,
Victor