Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. You can use the CSS from another Pen by using it's URL and the proper URL extention.

+ add another resource

JavaScript

Babel includes JSX processing.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                <script src="https://threejs.org/build/three.js"></script>
<script src="https://threejs.org/examples/js/controls/OrbitControls.js"></script>
<script src="https://s3-eu-west-2.amazonaws.com/bckld/lab/loading.js"></script>
              
            
!

CSS

              
                body {
  background: #000;
  margin: 0;
  overflow: hidden;
}
.hudLabel {
  position: absolute;
  top: 0;
  left: 0;
  color: #000;
  font-family: 'Trebuchet MS', sans-serif;
  font-size: 15px;
  font-weight: normal;
  line-height: 24px;
  text-align: left;
  padding: 3px;
  -webkit-box-shadow: 0px 4px 8px -3px rgba(0, 0, 0, 0.75);
  -moz-box-shadow: 0px 4px 8px -3px rgba(0, 0, 0, 0.75);
  box-shadow: 0px 4px 8px -5px rgba(0, 0, 0, 0.75);
  background: rgba( 255, 255, 255, 0.8);
  display: none;
}
              
            
!

JS

              
                function _convertLatLonToVec3(lat, lon) {
  lat = lat * Math.PI / 180.0;
  lon = -lon * Math.PI / 180.0;
  return new THREE.Vector3(
    Math.cos(lat) * Math.cos(lon),
    Math.sin(lat),
    Math.cos(lat) * Math.sin(lon));
}

function InfoBox(city, radius, domElement) {
  this._screenVector = new THREE.Vector3(0, 0, 0);

  this.position = _convertLatLonToVec3(city.lat, city.lng).multiplyScalar(radius);

  // create html overlay box
  this.box = document.createElement('div');
  this.box.innerHTML = city.name;
  this.box.className = "hudLabel";

  this.domElement = domElement;
  this.domElement.appendChild(this.box);

}

InfoBox.prototype.update = function() {
  this._screenVector.copy(this.position);
  this._screenVector.project(camera);

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

  var boundingRect = this.box.getBoundingClientRect();

  // update the box overlays position
  this.box.style.left = (posx - boundingRect.width) + 'px';
  this.box.style.top = posy + 'px';
};

//--------------------------------
function Marker() {
  THREE.Object3D.call(this);

  var radius = 0.005;
  var sphereRadius = 0.02;
  var height = 0.05;

  var material = new THREE.MeshPhongMaterial({
    color: 0xDC143C
  });

  var cone = new THREE.Mesh(new THREE.ConeBufferGeometry(radius, height, 8, 1, true), material);
  cone.position.y = height * 0.5;
  cone.rotation.x = Math.PI;

  var sphere = new THREE.Mesh(new THREE.SphereBufferGeometry(sphereRadius, 16, 8), material);
  sphere.position.y = height * 0.95 + sphereRadius;


  this.add(cone, sphere);
}

Marker.prototype = Object.create(THREE.Object3D.prototype);

// ------ Earth object -------------------------------------------------

function Earth(radius, texture) {
  THREE.Object3D.call(this);

  this.userData.radius = radius;

  var earth = new THREE.Mesh(
    new THREE.SphereBufferGeometry(radius, 64.0, 48.0),
    new THREE.MeshPhongMaterial({
      map: texture
    })
  );

  this.add(earth);
}
var markerarry= [];
Earth.prototype = Object.create(THREE.Object3D.prototype);

Earth.prototype.createMarker = function(lat, lon) {
  var marker = new Marker();

  var latRad = lat * (Math.PI / 180);
  var lonRad = -lon * (Math.PI / 180);
  var r = this.userData.radius;

  marker.position.set(Math.cos(latRad) * Math.cos(lonRad) * r, Math.sin(latRad) * r, Math.cos(latRad) * Math.sin(lonRad) * r);
  marker.rotation.set(0.0, -lonRad, latRad - Math.PI * 0.5);

  this.add(marker);
};

// ------ Three.js code ------------------------------------------------

var scene, camera, renderer, label;
var controls;

init();

function init() {
    scene = new THREE.Scene();

    camera = new THREE.PerspectiveCamera(62, 4 / 3, 0.1, 100);
    camera.position.set(0.0, 0.2, 3.0);

    renderer = new THREE.WebGLRenderer({
        antialias: true
    });

    controls = new THREE.OrbitControls(camera, renderer.domElement);
    controls.autoRotate = true;
    controls.autoRotateSpeed = -1.0;
    controls.enablePan = false;

    var ambient = new THREE.AmbientLight(0xffffff, 1);
    scene.add(ambient);

    var manager = createLoader(renderer.domElement, animate);
    var texLoader = new THREE.TextureLoader(manager).setCrossOrigin(false);
  
    var texture = texLoader.load('https://s3-eu-west-2.amazonaws.com/bckld/lab/textures/earth_latlon.jpg');
      texture.anisotropy = renderer.capabilities.getMaxAnisotropy();

  var earth = new Earth(1.0, texture);
    scene.add(earth);

    var radius1 = 1;
	
	/*================ +200 Self Development Articles =============*/
	var city = {
        "name": "+200 Self Development Articles",
        "lat": 22,
        "lng": -20
    };
    var label = new InfoBox(city, radius1, document.body);
    var material1 = new THREE.MeshBasicMaterial({
        color: 0xDC143C
    });
    var marker1 = new THREE.Mesh(new THREE.BoxGeometry(0.1, 0.19, 0.08), material1);
    scene.add(marker1);
  
    markerarry.push(marker1)
    /*=======================================================*/
    function clearMarkers(map, markers) {
        for (var i = 0; i < markers.length; i++) {
            markers[i].setMap(null);
        }
    }

    window.addEventListener("touchend", onTouchEnd);

    function onTouchEnd(event) {
        triggerlink(event, true);
    }

    function triggerlink(event, istouched) {
        const rect = renderer.domElement.getBoundingClientRect();
        var left = 0;
        var top = 0;
        if (istouched) {
            left = event.changedTouches[0].clientX - rect.left;
            top = event.changedTouches[0].clientY - rect.top;
        } else {
            left = event.clientX - rect.left;
            top = event.clientY - rect.top;
        }

        const x = (left / rect.width) * 2 - 1;
        const y = -(top / rect.height) * 2 + 1;

        const raycaster = new THREE.Raycaster();
        raycaster.ray.origin.setFromMatrixPosition(camera.matrixWorld);
        raycaster.ray.direction.set(x, y, 0.5).unproject(camera).sub(raycaster.ray.origin).normalize();
        const intersects = raycaster.intersectObjects(markerarry, true);

        if (intersects.length !== 0) {
            window.location.href = intersects[0].object.userData.URL;
        }
        console.log(intersects);

    }
    window.onmousedown = function(event) {
        triggerlink(event, false);
    }

    window.addEventListener('resize', onResize);
    onResize();
    document.body.appendChild(renderer.domElement);
}

function onResize() {
    camera.aspect = window.innerWidth / window.innerHeight;
    camera.updateProjectionMatrix();
    renderer.setSize(window.innerWidth, window.innerHeight);
}

function animate() {
    requestAnimationFrame(animate);
    controls.update();
    renderer.render(scene, camera);
}
              
            
!
999px

Console