Interacting with a WebGL globe: accessing database information and displaying pop-up windows when clicking on specific locations on the globe

I am working on creating a WebGL Globe similar to the one found at this link:

Currently, I have been using this example as a reference point:

Here are the specific project requirements that I am aiming to achieve:

The website needs to be able to manage data, allowing members to input information such as descriptions, URLs, and more for their representation on the globe. The layout should consist of a menu bar above, followed by the WebGL globe, news and events section, an image gallery of sponsors, and a footer.

The globe should display points representing the data entered by members through a data manager. Upon clicking on these points, an information panel (div popup) will appear showing the details and links of the selected member.

A search engine feature is necessary to enable searching by member or sector. When a member is selected, the globe should automatically rotate to their position.

Each member profile should include a title, description, address, links to social networks, and a photo gallery that is accessible through the globe panel when clicked on.

I have already created a PHP form for entering member information into a database. This PHP file also updates a JSON file containing the lat/lon coordinates of the dots displayed on the globe, which is then read by the JavaScript file in the example.

My main challenge lies in implementing a popup window feature. The script for opening windows in the previous example is written in JavaScript and loaded by the main webpage.

I am uncertain about how to retrieve data from the database, obtain the ID of a clicked spot, and pass this information back to the main webpage with the WebGL globe. Alternatively, I am exploring options for passing only the ID and having the globe retrieve the information from the database using JavaScript.

In addition, I need to extract data from a JSON or similar file and enable users to click on each point to view detailed information.

Furthermore, I aim to capture events such as clicking on objects that orbit the globe and show the same information panel. Additionally, I want these objects to continue rotating along the Z-axis around the globe as it is manually rotated with the mouse.

If anyone can provide assistance, even just addressing a portion of this complex question, I would greatly appreciate it. I feel stuck at this stage of development.

Thank you immensely for any help offered.

Current Status: https://i.sstatic.net/Qs4eG.jpg Desired Outcome: https://i.sstatic.net/OxreZ.jpg

Answer №1

Start by assigning data to each of the THREE objects that you want to be clickable in order to retrieve information from the database. Let's assume we create an object and add it to the clickable array

var clickable_objects = [];

var clickable_object = new THREE.Mesh( new THREE.IcosahedronGeometry( 1, 2 ), new THREE.MeshBasicMaterial()); 
    clickable_object.my_data = {'id':1};


clickable_objects.push(clickable_object);

Then, place the object within the 3D scene

scene.add(clickable_object);

You can use basic jQuery JSON with GET method to fetch data. In PHP, perform authentication, database login, query, etc., and return the result as text in JSON format using echo json_encode(array() $my_result).

function getDBdata(id) {
    $.getJSON('y_folder/my_script_with_dbquery.php?i_need_row_id='+id, //Retrieve $_GET['i_need_row_id'] from the URL used to call this script.
      function(r) {     
        // Access the "r" returned data (JSON encoded $my_result array) to display in a popup window
        $('#my_div_id').html('<p>This is my database content with '+r.some_variable_form_json_returned_by_php_script+'.</p;')
      }           
    )
}

To trigger the function and obtain the appropriate ID of the 3D object you click on, simply click on an object in the 3D scene to execute getDBdata(id);

Listen for clicks on the canvas (THREE 3D scene):

canvas.addEventListener( 'mouseup', onDocumentMouseUp, false );

function onDocumentMouseUp(event) {
event.preventDefault();
 if(event.which === 3)  { /// right mouse button
  var r = new THREE.Raycaster();
  r.setFromCamera( mouse, camera ); 
  var i = r.intersectObjects( clickable_objects, true); // Determine the intersection point
  var id = i.object.my_data.id // Ensure that the ID is assigned to the object initially (as mentioned earlier)
  if(id>0) {
    getDBdata(id) // Display the popup with actual data from the database
  }
 }
}

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

updating a div with URL redirection instead of global redirect

I am facing an issue with redirecting my website flow to the login page when a user clicks any link on the page after the session has expired (either due to timeout or manual logout from another window). In an attempt to solve this, I inserted the followi ...

Decoding a nested JSON array in C#

I'm brand new to c# and struggling with retrieving a JSON array of arrays from a 2D array. In my JSON file, I have data representing student grades like this: [ [10,5,4], [9,6,3] ] When trying to parse this JSON using JArray, I encounter an ...

Typescript is experiencing an error due to the use of attr("disabled", false) causing a disruption

Within my ts file, I'm using the code snippet below: $('input[type=hidden]').attr("disabled", false); The code functions as intended, however, an error persists: Argument of type 'false' is not assignable to parameter of typ ...

What is causing the lack of response in the select box on Mac Chrome when I try to click on it?

Similar Question: JQuery function doesn't work on Chrome on Mac, but works on Chrome on Win 7 and all other browsers I am encountering an issue with a select-option list <div class="social-option"> <select name="hex_theme_options[soc ...

Checkbox value not being accurately retrieved by Struts2 page

I have a form that captures phone information for two different phones, with each phone having its own set of details. If the user enters the same phone number for both phones, the second checkbox is automatically checked using the JavaScript code below: ...

Firebug detected an error with the regular expression flag "h" after executing the YUI Compressor

When I run YUI Compressor, an error occurs with the message: invalid regular expression flag h [Break On This Error] ction(event){$(this).removeClass('lumi...cs_glb.php</b> on line <b>221</b><br/> The issue seems to be with t ...

Having difficulty automatically populating a textarea with the chosen option from a datalist

Is there a way to automatically populate the Address field of a client in a textarea based on the input of the client's name in an input field? I have created a 'for loop' to retrieve a datalist of client names. For the address, I retrieved ...

Retrieving the final element from a TypeScript JSON array

I am trying to retrieve the value of the "id" property from the last element in an array of JSON objects. While I can easily find each element by id, I specifically need to extract the value of the last "id" in the array of JSON objects. In the example p ...

Unable to successfully display AJAX data on success

After successfully running my GradeCalc function in a MVC C# context with the grade parameter, I am facing an issue where the data is not displaying and the JavaScript alert pop up shows up blank. Can you assist me with this problem? $("#test").o ...

Error occurred while trying to call android.app.Service() without any arguments provided

In my experience with using Retrofit to fetch data from an API, I encountered a peculiar issue. The response would fail only when the service Array contained data; if it was null, the response would be successful and all other data would be present. Howeve ...

If the key is not found in the JSON data, assign a value of null and add it to the

My goal is to extract a value from a specific key in a JSON string and then insert that data into a dataframe. However, the column may or may not appear in the structure. When the key does not exist, it throws an error like 'KeyError': 'Co ...

When launching JQuery UI Tabs in a new browser tab using ajax, the HTML from the ajax response will be immediately shown

I am currently in the process of upgrading from JQuery UI 1.8.14 to JQuery UI 1.10. Previously, when using v1.8.14 code, opening a tab in a new browser tab would cause the entire page to reload, activating the default tab (tabIndex=0). However, I am faci ...

Everything was working perfectly with the Javascript code until I attempted to encapsulate it within

I found some helpful source code here for using AJAX to submit a form and store user information in a database using PHP. While the code I initially used worked, I realized that for efficiency, I needed to streamline it for multiple forms performing the sa ...

Unable to access the "target" property while transferring a value from child to parent component

Within my project, the student component is considered a child component of the main app component. Inside the template of the student component, there is an input element defined like so: <input type='text' #inputbox (keyup)='onkeyUp(i ...

Triggering the AJAX function in the main window

My HTML webpage has a hyperlink that, when clicked, opens the same page in another window with a hash value appended to the URL using window.open. For example, the URL could look like this: http://mywebsite.com#hash=value The webpage contains a JavaScript ...

Utilizing i18n's useTranslation and Redux's connect Higher Order Components to export components efficiently

My application has been utilizing Redux for quite some time, with the component exports structured like this: export default connect(mapStateToProps, mapDispatchToProps)(MyComponent); Now, I am integrating an i18n translation library and would like to use ...

Unusual increase in the Date() function hour on March 12, 2017

I encountered an issue where creating a new Date() object for March 12, 2017 with the hour set to 2am displays as 3am when using getHours(). The expected output should be 2am. Could there be an error in my code? I have highlighted the problematic section ...

Use CredentialsProvider to enable Next Auth login functionality

I am encountering an issue where I retrieve a user from the database and store it in a variable called result. However, I noticed that the result object does not contain the password key, resulting in the value of result.password being undefined. I am un ...

The property 'body' cannot be read because it is undefined

I have been attempting to incorporate passport logic into my controllers file, but I encountered an issue. When I place the logic inside the controllers, it gives me an error message saying "Cannot read property 'body' of undefined." However, whe ...

Making sure to consistently utilize the service API each time the form control is reset within Angular 4

In the component below, an external API service is called within the ngOnInit function to retrieve an array of gifs stored in this.items. The issue arises when the applyGif function is triggered by a user clicking on an image. This function resets the For ...