connecting d3.js and THREE.js for a synchronized earth simulation

I have been experimenting with combining WebGL earth and d3.geo.satellite projection in my project.

Successfully overlaying the two projections and syncing rotation, I am now facing difficulties in syncing zooming. Every attempt to match their size results in deformation of the WebGL projection while the d3.geo.satellite projection remains unchanged. I have played around with different combinations of projection.scale and projection.distance but haven't found a solution yet.

If you'd like to see the issue for yourself, here is the JSFiddle link (please note that it may take some time to load the resources). You can rotate by dragging (which works fine), but zooming in using the mousewheel will show the problem:

https://jsfiddle.net/nxtwrld/7x7dLj4n/2/

The crucial code lies at the bottom of the script - the scale function:

function scale(){
    var scale = d3.event.scale;
    var ratio = scale/scale0;

    // Scale projection
    projection.scale(scale);

    // Scale Three.js earth
    earth.scale.x = earth.scale.y = earth.scale.z = ratio;
}

Answer №1

I haven't had success using WebGL earth either. When I checked your jsfiddle, it wasn't working anymore. From what I gather, you're looking to integrate D3.js with Threejs for a 3d globe solution.

Have you considered trying earthjs? It utilizes D3.js v4 and Threejs revision 8x under the hood, both of which are the most up-to-date versions. It can seamlessly combine Svg, canvas, and threejs (WebGL) elements.

    const g = earthjs({padding:60})
    .register(earthjs.plugins.mousePlugin())
    .register(earthjs.plugins.threejsPlugin())
    .register(earthjs.plugins.autorotatePlugin())
    .register(earthjs.plugins.dropShadowSvg(),'dropshadow')
    .register(earthjs.plugins.worldSvg('../d/world-110m.json'))
    .register(earthjs.plugins.globeThreejs('../globe/world.jpg'))
    g._.options.showLakes = false;
    g.ready(function(){
        g.create();
    })

You can test out the code snippet above by visiting this link.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Discovering the dimensions of a video in Angular 2 using TypeScript

To determine whether the video is portrait or landscape, I am attempting to retrieve the height and width of the video using the following method: import { Component, OnInit, AfterViewInit } from '@angular/core'; @Component({ selector: ' ...

What is the process for assigning custom constructor parameters to an Angular Service during its creation in an Angular Component?

I have been tasked with converting a Typescript class into an Angular 6 service: export class TestClass { customParam1; customParam2; constructor(customParam1, custom1Param2) { this.customParam1 = customParam1; this.customPara ...

Java and JavaScript - Utilizing a Map

I'm currently using Rhino to run JavaScript code within my Java program, but I've encountered a problem with iterating over the map in JavaScript. On the Java side: private final Map<Long, ClassEmployees > employees ; ... employees.put (n ...

Is there a way to bypass the final function call when using Express Middleware?

In my Node.js project using express, I have a function inside a get route... The function currently includes a simple caching functionality that I coded myself. It queries data from an MSSQL Database and returns it using res.json(data). However, I want to ...

Adjust the form action and text input name according to the selected radio input

Seeking assistance with the following code, can someone help? $(document).ready(function() { $('#searchform').submit(function() { var action = ''; if($('.action_url').val() == 'l_catalog') { ...

Different placeholder text rendered in two text styles

Can an input box placeholder have two different styles? Here's the design I have in mind: https://i.stack.imgur.com/7OH9A.png ...

Quantifying website loading times using JavaScript code

Looking for a solution to load a webpage, analyze page load time and network call statistics using tools like Selenium. I'm interested in obtaining similar information as Chrome DevTools Network tab, including details on request status, type, size, an ...

Guide on invoking a node.js function from an express-rendered ejs page

My express server currently has a button that triggers a POST request to activate a function in my node.js server. Instead of using a traditional POST request, I am interested in implementing something like AJAX so that the page doesn't reload. Is th ...

Notifying asynchronous completion using Gulp, Babel, and configuration file config.yml

My current project involves using babel and gulp for handling tasks, as well as loading a yml config file for paths. This is the content of cofing.yml: PATHS: # Path to source folder sources: "jet/static/jet_src" # Path to dist folder dist: "jet/ ...

Calling a function after a value has been updated

Does anyone have any suggestions for how to create a Logout button that unsets sessions and then closes the current tab? I've been able to destroy the sessions, but I'm struggling with closing the tab. I've tried using setInterval and echoin ...

THREE.js: dual scenes sharing identical camera positions

I'm currently working on a project where I have two overlapping scenes. The top scene can be faded in and out using a slider, and users can rotate objects within the scene for a better view. My challenge is to keep the camera position consistent betw ...

Enhancing Dataset Quality: Incorporating Failed Results with Apify

We have implemented the Apify Web Scraper actor to execute a URL validation task that retrieves the input URL, the title of the page, and the HTTP response status code. Our testing includes 5 URLs - 4 valid ones and 1 non-existent URL. The successful resul ...

How can I show or hide all child elements of a DOM node using JavaScript?

Assume I have a situation where the HTML below is present and I aim to dynamically conceal all the descendants of the 'overlay' div <div id="overlay" class="foo"> <h2 class="title">title</h2> ...

Issue: Module './' could not be located

Encountered this error while trying to launch my application using NPM start. Strangely, it worked perfectly on another computer. I unzipped the file, ran npm install, and attempted to start the app, only to be hit with the following error: Any assistance ...

The order of key:value pairs in documents created by Mongoose does not always align with the schema

Having trouble understanding how the Mongo .create and .findAndUpdate operations work. My mongoose version is 5.4.2X and I have a model with a schema containing multiple key:value pairs in a specific order (using 1. 2. 3. etc to indicate the correct order) ...

Unusual shadow effects with three.js

I'm still new to three.js and webgl, and I'm encountering some odd-looking shadows when using a directional light. Could somebody help me out? Below is the code I have for the renderer: this.renderer.shadowMapEnabled = true; this.renderer.shad ...

What could be the reason for Firefox abruptly terminating inactive XMLHttpRequest connections?

When working with a JavaScript class, an XMLHttpRequest is used to connect to the server. The server sends data slowly, and this process functions well in Chromium. However, Firefox tends to close the connection randomly after a certain amount of time (typ ...

Utilizing Typescript Generics in Arrow Function to Combine Two Arguments

For instance, I am working with this code in a .tsx file extension const Add = <T,>(arg0: T, arg1: T): T => arg0 + arg1; const A = Add(1, 2); const B = Add('1', '2') However, I am encountering an issue, as there is an error m ...

Utilize moment.js to filter an array of objects based on 'last month' and 'last week' when clicked

In my database, each object has a dateCreated value of 2015-12-11T11:12:14.635Z I'm trying to filter this array for the past week and month. The issue is that if today is March 19th, I want to search from the 11th to the 18th for the last 7 days, st ...

Error encountered in Angular JS: $parse:syntax Syntax Error detected

var app=angular.module('myapp',[]) app.controller('myctrl',Myfunction); function Myfunction($scope,$compile){ var self=this; $scope.text=s4(); $scope.adding=function(){ var divElement = angular.element($("#exampleId")); ...