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

vi_geo_layer

v1.0.23

Published

CUBE.gl core. A WebGL-powered geographic data visualization framework build upon three.js.

Downloads

9

Readme

CUBE.gl

CUBE.gl is a geospatial data visualization framework for visualizing large-scale geo-related datasets or create digital twin in a few line of code. The CUBE.gl is built upon the brilliant 3D library three.js by mrdoob, powered by Web-GL.

Notice

This version is in publish for testing and in active development / update. It is not recommended to use this library in production enviornment. Please report Bugs and issues the Github issue page.

Full Documentation

Features

  • Visualize numeric data by cylinder, arc, text etc.

  • Visualize datasets by point cloud and heatmap.

  • Visualize geographic data by buildings, roads, terrain, tile map, administrative geojson and custom polygon.

  • Load model and attach other object, eg. THREE.Light.

  • Create animation by WGS84 coordinate path (eg. vehicle) or simply circular around something (eg. satellite).

  • Attach shader to an object to create visual effects.

Install

by CDN

Simply add this line in your .HTML file.

<script src="https://unpkg.com/cube.gl@latest/dist/cubegl.js"></script>

by NPM

By importing the project from NPM module system, you need to install node.js. Open a terminal, direct to your project folder, execute following command:

npm i cube.gl

Hello World

Create first scene

  1. Create a div block with id in HTML:
<div id="container" style="position: absolute; width: 100%; height: 100%;"></div>
  1. Write following code
// Get target container
const container = document.getElementById('container')

// Init CUBE instance
const C = new CUBE.Space(container, {
	background: "333333", // Set Background Color
	center: {latitude: 34.710554, longitude: 103.699520}, // Set a geo location center
	scale: .002, // Set a map scale
	camera:{
		position: {x: 5, y: 5, z: 5} // Set camera default position
	}
})

// Add a basic box with wgs84 coordinate
const posi = new CUBE.Coordinate("GPS", {latitude: 34.710554, longitude: 103.699520}).ComputeWorldCoordinate()
const box = C.Add(new CUBE.Shapes("Box", posi.world).Box(1))
box.position.y = 1

// Animate scene every frame
Update()
function Update(){
    requestAnimationFrame(Update)
    C.Runtime()
}

The scale is set to 0.002 because we are going to load a administrative map for an whole country in the next step, set it to 5-10 if you want to visualize in city / street level.

Run your project, you will see a green cube placed in the middle of your screen as the coordinate is equal to the center coordinate.

example-1

  1. Now let's explore more. Add the following line before Update()
// Add Geojson Map Layer
const china = 'https://gistcdn.githack.com/isjeffcom/787220f51465c8365b4ccc7247a919e7/raw/1afd3f92f64d8dd01534b6831d65de395f07b43e/china.geojson'
fetch(china).then(async (res)=>{
    C.Add(new CUBE.GeoLayer("china", await res.json()).AdministrativeMap({border: true, height: .5}))
})

// Add an cylinder bar at Shanghai City Center
const shanghai = {latitude: 31.230689, longitude: 121.473723}
const bar = new CUBE.Data("shanghai").Cylinder(shanghai, 150, 40, .5, 0xff6600)
C.Add(bar)

*If the .geojson file fail to request, download it from here *

Run your project, you will see an administrative map of China display in the center, with a cylinder bar and... Great. You have finished your first project.

example-2

Use High-Level API

High-level API only contain City constructor for now. The City class enables the abilities to download data, and display any part of city (most of) in 3D around the world by CUBE.gl. You can create a Paris city center (Cathédrale Notre-Dame) in range 500 meters by

Init()
Update()

// Get Container
const container = document.getElementById('cont')

// Ready for CUBE Instance
let C

async function Init(){

    // Init CUBE Instance
    C = new CUBE.Space(container, {
        background: "333333", 
        center: {latitude: 48.851837, longitude: 2.356544}, 
        scale: 10,
        camera:{
            position: {x: 6, y: 10, z: 6}
        }
    })

    const cm = new CUBE.City(500) // range 500 meters

    const building = await cm.buildings()
    const roads = await cm.roads()

    document.getElementById("loading").style.display = "none"

    roads.position.y -= 1
    C.Add(building)
    C.Add(roads)

}

function Update(){
    requestAnimationFrame(Update)
    C.Runtime()
}

paris

Use with Threejs

The CUBE.gl is build upon three.js. You can access the built-in three.js by CUBE.Space.three or CUBE.Space.Three(). The current CUBE build is using three.js 0.119. You can also try to implement a different version.

More about three.js you can check here

Use with MVVM Framework

The CUBE.gl has no limitation to use in any MVVM framework as long as you can access DOM element to rendering.

Use with Vue.js

Here is an example how to use CUBE.gl in Vue.js with Vue-Cli.

<template>
    <div id="app">
        <div id="cont"></div>
    </div>
</template>

<script>

import * as CUBE from 'cube.gl'

export default {
    name: "app",
    data(){
        return{
            C: null,
            Center: {latitude: 41.157937, longitude: -8.629108}, // Porto
        }
    },
    mounted(){
        this.Init()
        this.Update()
    },
    methods: {
        Init(){
            let container = document.getElementById('cont')

            // Init CUBE Instance
            this.C = new CUBE.Space(container, {
                background: "333333", 
                center: this.Center, 
                scale: 10
            })

            //Add a basic box with wgs84 coordinate
            let posi = new CUBE.Coordinate("GPS", {latitude: 41.157937, longitude: -8.629108}).ComputeWorldCoordinate()
            this.C.Add(new CUBE.Shapes("Box", posi.world).Box(1))

            // Add Sphere
            this.C.Add(new CUBE.Shapes("Sphere", {x: 2, y: 0, z: 2}).Sphere(1, 0x00ffff))
            this.C.Add(new CUBE.Shapes("Cylinder", {x: -2, y: 0, z: -2}).Cylinder(1, 0xff0000))

        },

        Update(){
            requestAnimationFrame(this.Update)
            this.C.Runtime()
        }
    }
}
</script>

Full Documentation