Gathering detailed insights and metrics for geo-three
Gathering detailed insights and metrics for geo-three
Gathering detailed insights and metrics for geo-three
Gathering detailed insights and metrics for geo-three
Tile based geographic world map visualization library for threejs
npm install geo-three
60.5
Supply Chain
96.4
Quality
79.5
Maintenance
100
Vulnerability
99.3
License
Module System
Min. Node Version
Typescript Support
Node Version
NPM Version
726 Stars
362 Commits
119 Forks
16 Watching
3 Branches
12 Contributors
Updated on 28 Nov 2024
TypeScript (94.96%)
JavaScript (4.93%)
HTML (0.12%)
Cumulative downloads
Total Downloads
Last day
-23.5%
440
Compared to previous day
Last week
12.8%
2,729
Compared to previous week
Last month
18.9%
10,228
Compared to previous month
Last year
9.4%
331,535
Compared to previous year
1
three.js
. Allows for full world scale visualization of geographic data using tile based chunks.MapProvider
interface.1// Create a map tiles provider object 2var provider = new OpenStreetMapsProvider(); 3 4// Create the map view and add it to your THREE scene 5var map = new MapView(MapView.PLANAR, provider); 6scene.add(map); 7 8// By default coordinates are to meter, can be resized to kilometer 9map.scale.set(0.001, 0.001, 0.001);
UnitsUtils
class to access the unit conversion methods for example to convert a latitude, longitude WGS84 pair value to XY coordinates you can use the code bellow:1var coords = Geo.UnitsUtils.datumsToSpherical(40.940119, -8.535589); 2controls.target.set(coords.x, 0, -coords.y);
Tiles are fetched from the service API configured, each one of the services requires specific configuration using the specific MapProvider
object.
Base tiles are always loaded at the beginning of the process, then each frame a couple of rays are casted into the tile tree. The number of rays can be configured using the MapView
subdivisionRays
attribute.
The distance of the ray to the camera is used to define if the node needs to simplified or sub-divided. These values can be configured using the thresholdUp
and thresholdDown
values.
The library has support for multiple data providers that must be configured beforehand. Most of these data providers rely on external API that differ from service to service.
Each one of them has its own provider object implementation of the MapProvider
interface.
The DebugProvider
provides information about the tiles loaded, shows the zoom level and the coordinates of the tile relative to the origin in that specific level.
LODControl
can be implemented by extending the LODControl
object and implementing the updateLOD(view, camera, renderer, scene)
method.1export class DistanceLOD extends LODControl 2{ 3 constructor() {super();} 4 5 updateLOD(view, camera, renderer, scene) 6 { 7 // Get world position of the camera. 8 var pov = new Vector3(); 9 camera.getWorldPosition(pov); 10 11 view.traverse(function(node) 12 { 13 // Check if child in a MapNode 14 if(node instanceof MapNode) 15 { 16 var position = new Vector3(); 17 node.getWorldPosition(position); 18 19 // Distance between camera and tile 20 var distance = pov.distanceTo(position); 21 22 // Normalize distance based on tile level 23 distance /= Math.pow(2, 20 - node.level); 24 25 // If closer than X subdivide 26 if (distance < 50) 27 { 28 node.subdivide(); 29 } 30 // If far away, simplify parent 31 else if (distance > 200 node.parentNode) 32 { 33 node.parentNode.simplify(); 34 } 35 } 36 }); 37 } 38}
MapNode
objects are used to define how the tiles should be represented in the space. MapNode
are organized hierarchically, every node implements the MapNode class that is based on the THREE.Mesh class (every map node has a visual representation as a mesh).MapProvider
class and implement the fetchTile(zoom, x, y)
method that returns a Promise
with access to the tile data.1export class OpenStreetMapsProvider extends MapProvider 2{ 3 constructor(address) {super();} 4 5 fetchTile(zoom, x, y) 6 { 7 return new Promise((resolve, reject) => 8 { 9 var image = document.createElement("img"); 10 image.onload = function(){resolve(image);}; 11 image.onerror = function(){reject();}; 12 image.crossOrigin = "Anonymous"; 13 image.src = "https://a.tile.openstreetmap.org/" + zoom + "/" + x + "/" + y + ".png"; 14 }); 15 } 16}
1import {Color} from "three"; 2 3export class BlueToRedProvider extends MapProvider 4{ 5 fetchTile(zoom, x, y) 6 { 7 const canvas = new OffscreenCanvas(16, 16); 8 const context = canvas.getContext('2d'); 9 10 const blue = new Color(0x0000FF); 11 const red = new Color(0xFF0000); 12 const color = blue.lerpHSL(red, (zoom - this.minZoom) / (this.maxZoom - this.minZoom)); 13 14 context.fillStyle = color.getStyle(); 15 context.fillRect(0, 0, 16, 16); 16 return Promise.resolve(canvas); 17 } 18}
MapNode
we can create a new class that extends the base implementation.MapView
object that is responsible for managing its life cycle.Mesh
object and have attached a Geometry and Material used to render them into the scene.1import {SphereGeometry, MeshBasicMaterial, Vector3} from "three"; 2 3// The MapNode inherits from three Mesh object and requires a geometry and material 4export class CustomMapNode extends MapNode 5{ 6 constructor(parentNode = null, mapView = null, location = MapNode.ROOT, level = 0, x = 0, y = 0) 7 { 8 super(CustomMapNode.GEOMETRY, CustomMapNode.MATERIAL, parentNode, mapView, location, level, x, y); 9 } 10 11 static GEOMETRY = new SphereGeometry(0.5, 32, 32); 12 13 static MATERIAL = new MeshBasicMaterial(); 14 15 // Base geometry applied to the map view. 16 static BASE_GEOMETRY = new MapNodeGeometry(1, 1, 1, 1); 17 18 // Base scale is applied to the map view 19 static BASE_SCALE = new Vector3(UnitsUtils.EARTH_PERIMETER, 1, UnitsUtils.EARTH_PERIMETER); 20 21 initialize() { 22 // Method to initialize data of the node (e.g fetch assets) 23 } 24 25 createChildNodes() 26 { 27 // Method called on subdivision to craete child nodes 28 } 29}
No vulnerabilities found.
No security vulnerabilities found.