npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

globe-threejs

v1.0.3

Published

A 3D globe visualization using Three.js with dynamic lighting and timezone calculations.

Downloads

1

Readme

Globe Module

The Globe module is a dynamic 3D Earth visualization tool that utilizes Three.js for rendering and Turf.js for geospatial operations. It's designed to be both visually engaging and informative, capable of displaying day and night textures, and providing real-time timezone data by interacting with the globe. This module features a realistic tilt to mirror Earth's axial tilt of 23.5 degrees, accurately simulates the planet's rotation speed, and dynamically adjusts the lighting to reflect the true positions of the sun relative to Earth throughout the day and year.

Optional Image Alt Text

Features

  • Dynamic Day/Night Cycle: Renders Earth with day and night textures that update in real-time according to the sun's position relative to the Earth.
  • Timezone Interaction: Clicking on the globe will display local time information, adjusted for daylight saving times based on the clicked location. This interaction retrieves and displays geodata, timezone details, as well as the current date and time for the specific location.
  • 3D Visualization: Utilizes Three.js to render a 3D globe with an atmosphere effect for enhanced visual appeal.
  • Real-Time Updates: The globe rotation and lighting adjust in real-time, providing an accurate representation of the Earth's rotation and sunlight distribution.
  • Customizable Options: Allows customization of textures, initial start time, and other globe properties.

Dependencies

You need to include the following dependencies in your project via npm or direct script tags in your HTML:

npm install three turf

Or include these scripts in your HTML:

<script src="https://cdn.skypack.dev/[email protected]"></script>
<script src="https://cdn.skypack.dev/@turf/[email protected]"></script>

Installation

npm install globe-threejs

Then, you can import the Globe class in your JavaScript project:

import { Globe } from 'https://cdn.skypack.dev/globe-threejs';

Usage

To use the Globe in your project, you need to create a new instance of the Globe and add it to a Three.js scene:

const globe = new Globe({
    dayTexture: 'path_to_day_texture.jpg',
    nightTexture: 'path_to_night_texture.jpg',
    onLocationClick: function(info) {
        console.log('Clicked location info:', info);
    }
});

// Initialize a Three.js scene
const scene = new THREE.Scene();
const camera = new THREE.PerspectiveCamera(75, window.innerWidth / window.innerHeight, 0.1, 1000);
const renderer = new THREE.WebGLRenderer();
renderer.setSize(window.innerWidth, window.innerHeight);
document.body.appendChild(renderer.domElement);

// Add the globe to the scene
globe.addToScene(scene);

// Camera and rendering setup
camera.position.z = 15;
function animate() {
    requestAnimationFrame(animate);
    renderer.render(scene, camera);
}
animate();

API Reference

Options

When creating a new instance of the Globe, you can pass in an options object to customize its behavior. Below are the available options:

  • dayTexture: Path to the image file used as the Earth's daytime texture. Default is '../assets/8081_earthmap10k.jpg'.
  • nightTexture: Path to the image file used as the Earth's nighttime texture. Default is '../assets/8081_earthlights10k.jpg'.
  • startTime: The initial date and time used to set the globe's lighting and rotation. Default is new Date(), which sets it to the current date and time.
  • earthRadius: The radius of the globe in Three.js units. Default is 5.
  • onLocationClick: A callback function that gets executed when a location on the globe is clicked. This function receives an object containing latitude, longitude, timezone, and other relevant data for the clicked location. Default is null.
  • timezoneGeoJSON: Path to the GeoJSON file that contains timezone information. Default is '../assets/all-timezones_.geojson'.

Methods

The Globe class provides several methods to interact with and control the globe:

  • init(): Initializes the globe by loading the necessary resources and setting up the Three.js scene. This method is automatically called upon instance creation.

  • addToScene(scene): Adds the globe to an existing Three.js scene. scene: The Three.js scene object to which the globe will be added.

  • setDateTime(date): Sets the globe's current date and time, affecting lighting and other time-dependent features. date:A JavaScript Date object representing the new date and time for the globe.

  • update(): Updates the globe's rotation and lighting based on real-time changes. This method is typically called within an animation loop.

  • handleMouseClick(event, camera, domElement): Handles mouse click events on the globe, performing raycasting to determine the clicked location and executing the onLocationClick callback if specified. event: The mouse event object. camera: The Three.js camera object used in the scene. domElement: The DOM element that the Three.js renderer is attached to.

Events

onLocationClick: Triggered when a location on the globe is clicked. Receives an object containing the following properties:

  • lat: Latitude of the clicked location.
  • lon: Longitude of the clicked location.
  • timezone: Timezone information of the clicked location.
  • localTime: Local time at the clicked location.
  • localDate: Local date at the clicked location.