Tips for preventing labels from overlapping in JavaScript

After texturing an image to a sphere in 3D (as shown below), I encountered an issue where the planegeometry labels were overlapping. I am looking for a way to separate these labels using the three.js library. 2

labelBox.prototype.update = function()
{

camera.updateMatrixWorld();
this.position.project(camera);

var screenvector = new THREE.Vector3();
screenvector.copy(this.position);
oldlabelpos.push(screenvector);
//this.position.normalize();

this.posx = Math.round((this.position.x + 1)* this.domElement.offsetWidth/2 + webglviewport.left);
this.posy = Math.round((1 - this.position.y)* this.domElement.offsetHeight/2);

var boundingRect = this.box.getBoundingClientRect();
this.box.style.left = this.posx + 'px';
this.box.style.top = this.posy  + 'px';

this.occludeLabel(this.box, this.marker);
};

labelBox.prototype.LabelUpdateFn = function()
{       
    //var labels =  

document.getElementById('MovingLabel1');//.getElementsByClassName('spritelabel'); //labels = $(root).find(".spritelabel");

    for(var k=0; k<oldlabelpos.length; k++)
        {
            this.reposition = new THREE.Vector3();
            this.reposition = convertlatlonToVec3(oldlabelpos[k].x, 
            oldlabelpos[k].y).multiplyScalar(radius);
            this.reposition.normalize();

            camera.updateMatrixWorld();
            this.reposition.unproject(camera);

            this.newposx = Math.round((this.reposition.x + 1)* 
            this.domElement.offsetWidth/2 + webglviewport.left) - this.posx;
            this.newposy = Math.round((1 - this.reposition.y)* 
            this.domElement.offsetHeight/2) - this.posy;

            var boundingRect = this.box.getBoundingClientRect();

            this.box.style.left = (this.newposx + boundingRect.width) + 'px';
            this.box.style.top = this.newposy + 'px';

            this.occludeLabel(this.box, this.marker);          
        }                       
}

Answer №1

When discussing ways to prevent label overlapping in a 3-dimensional space, implementing "Clipping" for a viewport is recommended. For a detailed explanation, check out this informative blog post

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

receiving a pair of components instead of just one

Here is the code for router.js: import React from 'react'; import { Route } from 'react-router-dom'; import CommentList from './containers/commentview'; import CommentDetalList from './containers/commentdetailview'; ...

Converting a three.js scene into SVG or alternative vector format for export

Can an SVG- or other vector-formatted image be exported from a scene rendered using three.js's WebGLRenderer? What about from a scene derived from CanvasRenderer? If not, how can one set up SVGRenderer with three.js? Creating a new THREE.SVGRenderer( ...

The ApexChart Candlestick remains static and does not refresh with every change in state

I am currently working on a Chart component that retrieves chart data from two different sources. The first source provides historic candlestick data every minute, while the second one offers real-time data of the current candlestick. Both these sources up ...

My models in three.js are exhibiting peculiar artifacts caused by the lighting from point light

Examining this basic 3D house model reveals a simple Cube unwrap with a few textured tiles. Upon adding a point light in front of the house, the structure appears well-lit while the surrounding terrain remains dark. Inside the house, the lighting seems d ...

Clicking will cause my background content to blur

Is there a way to implement a menu button that, when clicked, reveals a menu with blurred content in the background? And when clicked again, the content returns to normal? Here's the current HTML structure: <div class="menu"> <div class=" ...

Transmit parameters via onclick event on FullCalendar

I have been utilizing the full calendar feature and it's been functioning properly. However, I am encountering an issue with sending parameters via onclick event. Below is the JavaScript code that I currently have: <script> $(document).ready(fu ...

Is there a method in AngularJS to submit form data when the input fields are pre-populated using a GET request?

How do I submit form data in AngularJS? I have a div that populates the input field from a GET request. Now, I want to send this data using a POST method. How can I achieve this? Below is the form div: <div class="row" ng-app="myApp" ng-controller="myC ...

Please provide an explanation for the statement "document.styleSheets[0].cssRules[0].style;"

I'm seeking an explanation for this block of code: document.styleSheets[0].cssRules[0].style; It would be helpful if you could use the following code as a reference: * { padding: 0; margin: 0; box-sizing: border-box; font-family:&apos ...

What is the process for generating a dynamic array in typescript?

Looking to create a TypeScript dynamic array with the desired format: const display = [ { id: 1, displayName: "Abc1" }, { id: 2, displayName: "Abc2" }, { id: 3, displayName: "Abc3" } ] Attempted the following code ...

Searching for a specific element in jQuery by querying a string

I have a situation where an ajax request is made to send text using the POST method to another PHP page. This PHP page then converts the text into markdown format and sends it back. Here's an example of what it looks like: "<p>Meep, meep, <e ...

Navigation menu with nested options in the list

I have designed a dropdown menu that lists provinces, with cities mentioned under each province. My goal is to show these cities in a submenu on the left-hand side when a province is clicked. <link rel="stylesheet" href="https://stackpath.bootstrapc ...

Tips on how to modify a select option in vue based on the value selected in another select

My Web Api has methods that load the first select and then dynamically load the options for the second select, with a parameter passed from the first selection. The URL structure for the second select is as follows: http://localhost:58209/api/Tecnico/Tanq ...

Loading times for the Polymer Project are sluggish

The website design is very appealing. However, it seems to be loading quite slowly even on Google's servers. Is there a way to speed up the initial load time of the Polymer site? Additionally, there are numerous HTTP requests being made; is there a wa ...

The functionality of the Bootstrap dropdown or radio input type is not functioning correctly

I'm currently utilizing electron([email protected]) along with bootstrap([email protected]). Whenever I attempt to incorporate a dropdown or other components from Bootstrap, they simply do not function. I am unsure of what mistake I might ha ...

Difficulty with timing in React.js when rendering content from an Express.js API

I am facing a timing issue while working with React.js. My component checks the validity of the user's token and type. If the user is an admin, it should display certain content; otherwise, it should show "you don't have permission". However, I ...

When using express to serve a static file with sendfile, the route specified is considered as the relative directory rather than its actual location directory

I'm facing an issue with a route in Express router.get('projects/fest', function(req, res, next){ res.sendfile('fest.html', {root: './public'}); }); When accessing localhost:3000/projects/fest, the HTML file is disp ...

Guide on effectively sorting the second level ng-repeat data in a table

I have a collection of data objects that I want to present in a tabular format with filtering capabilities. The current filter, based on the 'name' model, successfully filters the nested object 'family'. However, it does not function as ...

Executing Client-Side Function Upon Data Retrieval in a Node.js Application

Within my node.js Express application, there exists a route like this: router.get('/devices/:id/visualize', catchErrors(deviceController.visualizeDevice)); This route points to the following controller: exports.visualizeDevice = async (req, re ...

Exploring the Universe: Modify the hue of a celestial body and showcase information upon hoveringokableCall

I have been working on developing a simulation that shows the positions of 4673 of the nearest galaxies. In this simulation, each galaxy is represented as a point. My goal is to change the color of a point when the mouse hovers over it and display the na ...

Execute asynchronous calls within each iteration and proceed to the next iteration in Node.js

I am currently faced with a dilemma at work and I need advice on the most effective approach to handle it. Below is an example of my code: for(var i =0 ;i < collection.length; i++){ asynCall( collection[i],function(){....})//doing a asynchronous cal ...