如何避免JavaScript中的标签重叠?

时间:2016-09-20 09:19:17

标签: javascript css math 3d three.js

我将图像纹理化为3D的球体(如下所示),并且我还添加了重叠的球面几何(标签)。如何使用three.js库分隔标签? enter image description here 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();  //getBoundingClientRect() method returns the 
                                              //size of element (here it is box) and its position relative to viewport
//update the box overlays position
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.box).css(left) = 

            this.occludeLabel(this.box, this.marker);
            //var updatedpos = {updateposx, updateposy};

            //newlabelpos.push(updatedpos);             
        }                       
}

1 个答案:

答案 0 :(得分:1)

如果您说&#34;避免标签重叠&#34;在3D中,你想要结帐&#34; Clipping&#34;对于视口。 例如:请参阅此article