Commit f7dad6f7 authored by Clément Igonet's avatar Clément Igonet

viewer-earth3 - last updates.

parent 45bc752a
......@@ -57,6 +57,15 @@
var tileMeshes = {};
var tileMeshQueue = [];
// // UNESCO
// this.LONGITUDE_ORI = 2.3057599523656336;
// this.LATITUDE_ORI = 48.849568465379264;
// LOUVRE
this.LONGITUDE_ORI = 2.3364709900972684;
this.LATITUDE_ORI = 48.86045538042749;
var R = 6378.137;
var xtile = 0;
var ytile = 0;
......@@ -65,9 +74,6 @@
var tileGroup = [];
var defaultAlti = 150;
var textureLoader = new THREE.TextureLoader();
// var currentIds = {};
textureLoader.crossOrigin = '';
var geojsonLoader = new THREE.GeojsonLoader();
var params = getSearchParameters();
......@@ -89,10 +95,16 @@
renderer.shadowMapWidth = 1024;
renderer.shadowMapHeight = 1024;
var goRender = function() {
render();
var goUpdateSceneLazy = function() {
updateSceneLazy();
};
var controls = new THREE.EarthControls(camera, renderer.domElement, goRender);
var controls = new THREE.EarthControls(
camera,
renderer.domElement,
goUpdateSceneLazy, {
longitude: LONGITUDE_ORI,
latitude: LATITUDE_ORI
});
var lonStamp = 0;
var latStamp = 0;
......@@ -124,18 +136,21 @@
}
// ENDOF initialization //
window.addEventListener( 'resize', onWindowResize, false );
window.addEventListener('resize', onWindowResize, false);
function onWindowResize(){
function onWindowResize() {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setSize( window.innerWidth, window.innerHeight );
renderer.setSize(window.innerWidth, window.innerHeight);
render();
}
var render = function() {
renderer.render(scene, camera);
}
var updateSceneLazy = function() {
// requestAnimationFrame(render);
////////////////////////////////////////////////////////////
var oldZoom = zoom;
......@@ -176,9 +191,11 @@
renderer.render(scene, camera);
};
render();
updateSceneLazy();
function updateScene(position) {
console.log('position.lon:', position.lon);
console.log('position.lat:', position.lat);
xtile = long2tile(position.lon, zoom);
ytile = lat2tile(position.lat, zoom);
......@@ -283,30 +300,45 @@
tileSupport.position.set(xTileShift * widthUp, -yTileShift * widthSide, 0);
tileSupport.add(tileMesh)
oriGround.add(tileSupport);
if (zoom_ >= 19) {
(function(earth, myTile, zoom, xtile, ytile) {
var geojson = 'http://localhost:8081/3dtile?format=geojson&xtile=' + xtile + '&ytile=' + ytile + '&zoom=' + zoom;
// if (zoom_ >= 19 && atile == xtile_ && btile == ytile) {
if (zoom >= 17 && zoom_ >= zoom) {
// var rColor = ((53 * (atile % modulus)) % 256).toString(16);
// console.log('rColor:', rColor);
var defaultColor =
((13 * zoom) % 256) * 65536 +
((53 * (atile % modulus)) % 256) * 256 +
((97 * (btile % modulus)) % 256);
// var defaultColor = 0xeeeeee;
// console.log('Define defaultColor:', defaultColor);
(function(earth, myTile, zoom, xtile, ytile, defaultColor) {
var url = 'http://localhost:8081/3dtile?format=geojson&xtile=' + xtile + '&ytile=' + ytile + '&zoom=' + zoom;
geojsonLoader.load(
geojson,
url,
function(obj) {
myTile.add(obj);
render();
}
);
})(earth, tileSupport, zoom_, atile, btile);
},
function() {},
function() {},
defaultColor);
})(earth, tileSupport, zoom_, (atile % modulus), (btile % modulus), defaultColor);
}
}
(function(yourTileMesh, yourZoom, yourXtile, yourYtile) {
var onLoaded = function(texture) {
yourTileMesh.material = new THREE.MeshBasicMaterial({
map: texture
});
render();
};
textureFactory(yourZoom, yourXtile, yourYtile, onLoaded);
textureFactory(
yourZoom,
yourXtile,
yourYtile,
function(texture) {
yourTileMesh.material = new THREE.MeshBasicMaterial({
map: texture
});
render();
}
);
})(tileMesh, zoom_, atile % modulus, btile % modulus);
var id = 'tile' + zoom_ + '_' +(atile % modulus) + '_' + (btile % modulus);
var id = 'tile' + zoom_ + '_' + (atile % modulus) + '_' + (btile % modulus);
currentIds[id] = {};
// console.log('currentIds: ', JSON.stringify(currentIds));
}
......
......@@ -31,7 +31,7 @@ OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
// Zoom - middle mouse, or mousewheel / touch: two finger spread or squish
// Pan - right mouse, or arrow keys / touch: three finter swipe
THREE.EarthControls = function(object, domElement, render) {
THREE.EarthControls = function(object, domElement, render, coord) {
this.object = object;
this.render = render;
this.domElement = (domElement !== undefined) ? domElement : document;
......@@ -74,16 +74,25 @@ THREE.EarthControls = function(object, domElement, render) {
this.enablePan = true;
this.keyPanSpeed = 7.0; // pixels moved per arrow key push
// Le louvre
this.LONGITUDE_ORI = 2.33517;
this.LATITUDE_ORI = 48.86148;
// // Le louvre
// this.LONGITUDE_ORI = 2.33517;
// this.LATITUDE_ORI = 48.86148;
// UNESCO
// this.LONGITUDE_ORI = 2.3057599523656336;
// this.LATITUDE_ORI = 48.849568465379264;
// this.LONGITUDE_ORI = 0;
// this.LATITUDE_ORI = 0.00001;
// ESB
// // ESB
// this.LONGITUDE_ORI = -73.98468017578125;
// this.LATITUDE_ORI = 40.7477771608207;
// COLISEO
this.LONGITUDE_ORI = 12.492148216478085;
this.LATITUDE_ORI = 41.89015670900311;
// Set to true to automatically rotate around the target
// If auto-rotate is enabled, you must call controls.update() in your animation loop
this.autoRotate = false;
......@@ -236,6 +245,10 @@ THREE.EarthControls = function(object, domElement, render) {
// var panOffset = new THREE.Vector3();
var longitude = this.LONGITUDE_ORI;
var latitude = this.LATITUDE_ORI;
if (coord !== null) {
longitude = (coord.hasOwnProperty('longitude')) ? coord.longitude : longitude;
latitude = (coord.hasOwnProperty('latitude')) ? coord.latitude : latitude;
}
var R = 6378.137;
var zoomChanged = false;
......
This diff is collapsed.
......@@ -120,8 +120,6 @@ getTileMesh = function(r, zoom, ytile, power) {
return new THREE.Mesh(geoTiles[id]);
}
assignUVs = function(geometry) {
geometry.computeBoundingBox();
......@@ -149,8 +147,9 @@ assignUVs = function(geometry) {
geometry.uvsNeedUpdate = true;
}
var textureLoader = new THREE.TextureLoader();
textureLoader.crossOrigin = '';
var textures = {};
var textureQueue = [];
var textureRequests = {};
var textureAliveRequests = {};
var textureAliveRequestsCount = 0;
......@@ -165,7 +164,7 @@ function loadNextTexture() {
textureAliveRequestsCount = textureAliveRequestsCount + (textureAliveRequests.hasOwnProperty(id) ? 0 : 1);
textureAliveRequests[id] = textureRequests[id];
var url = textureAliveRequests[id].url;
delete textureRequests[id]
delete textureRequests[id];
textureRequestsCount--;
(function(url, id) {
textureAliveRequests[id].request = textureLoader.load(url,
......@@ -177,15 +176,24 @@ function loadNextTexture() {
textureAliveRequestsCount--;
}
loadNextTexture();
},
function() {},
function() {
if (textureAliveRequests.hasOwnProperty(id)) {
// textureAliveRequests[id].onLoaded(texture);
delete textureAliveRequests[id];
textureAliveRequestsCount--;
}
loadNextTexture();
}
);
})(url, id)
})(url, id);
}
}
function textureFactory(zoom, xtile, ytile, onLoaded) {
var id = 'tile' + zoom + '_' + xtile + '_' + ytile;
if ((textures.hasOwnProperty(id))) {
if (textures.hasOwnProperty(id)) {
onLoaded(textures[id]);
} else {
var serverRandom = TILE_PROVIDER01_RANDOM[
......@@ -197,9 +205,9 @@ function textureFactory(zoom, xtile, ytile, onLoaded) {
textureRequestsCount = textureRequestsCount + (textureRequests.hasOwnProperty(id) ? 0 : 1);
textureRequests[id] = {
url: url,
onLoaded: onLoaded
}
url: url,
onLoaded: onLoaded
}
loadNextTexture();
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment