three-geo-play 1.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +148 -0
- package/dist/index.cjs +9445 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.ts +457 -0
- package/dist/index.js +9428 -0
- package/dist/index.js.map +1 -0
- package/package.json +39 -0
package/README.md
ADDED
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
|
|
2
|
+
<img width="504" height="392" alt="491275803-585ea8ae-239b-43db-aa20-e2b5ca5a784d (1)" src="https://github.com/user-attachments/assets/2382f57e-71be-405b-97f7-574345885323" />
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
# 🌍 ThreeGeoPlay
|
|
8
|
+
|
|
9
|
+
**Real-world map tiles rendered in 3D — powered by Three.js and OpenStreetMap vector data.**
|
|
10
|
+
|
|
11
|
+
ThreeGeoPlay is a JavaScript library that fetches [Vector Tiles (MVT/PBF)](https://docs.mapbox.com/vector-tiles/specification/) and renders them as 3D geometry directly into your Three.js scene. Roads, buildings, water, land use — all as real meshes you can walk through, fly over, or build games on top of.
|
|
12
|
+
|
|
13
|
+
---
|
|
14
|
+
|
|
15
|
+
## ✨ Features
|
|
16
|
+
|
|
17
|
+
- 🗺️ **Vector tile rendering** — roads, buildings, waterways, land use, and more
|
|
18
|
+
- 🏙️ **3D building extrusion** — real heights from OSM data
|
|
19
|
+
- 🎨 **Fully styleable** — swap materials, colors, and visibility per layer
|
|
20
|
+
- 📡 **Auto tile loading** — smart queue with concurrency, abort, and retry
|
|
21
|
+
- 🎮 **Follow mode** — attach to any `THREE.Object3D` (camera, player…) and the map follows
|
|
22
|
+
- 🔲 **Circular or square** render regions
|
|
23
|
+
- ⚡ **Zero dependencies** beyond Three.js
|
|
24
|
+
|
|
25
|
+
---
|
|
26
|
+
|
|
27
|
+
## 📦 Installation
|
|
28
|
+
|
|
29
|
+
```bash
|
|
30
|
+
npm install three-geo-play
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
---
|
|
34
|
+
|
|
35
|
+
## 🚀 Quick Start
|
|
36
|
+
|
|
37
|
+
```js
|
|
38
|
+
import * as THREE from 'three';
|
|
39
|
+
import { ThreeGeoPlay } from 'three-geo-play';
|
|
40
|
+
|
|
41
|
+
const scene = new THREE.Scene();
|
|
42
|
+
const camera = new THREE.PerspectiveCamera(60, innerWidth / innerHeight, 0.1, 10000);
|
|
43
|
+
const renderer = new THREE.WebGLRenderer({ antialias: true });
|
|
44
|
+
renderer.setSize(innerWidth, innerHeight);
|
|
45
|
+
document.body.appendChild(renderer.domElement);
|
|
46
|
+
|
|
47
|
+
const geo = new ThreeGeoPlay(scene, camera, renderer);
|
|
48
|
+
|
|
49
|
+
// Set your starting coordinates and tile source
|
|
50
|
+
const config = geo.getMapConfig();
|
|
51
|
+
config.originLatLon = { lat: 41.9028, lon: 12.4964 }; // Rome
|
|
52
|
+
config.pbfTileProviderZXYurl = 'https://your-tile-server/{z}/{x}/{y}.pbf';
|
|
53
|
+
config.zoomLevel = 16;
|
|
54
|
+
config.tileWorldSize = 50;
|
|
55
|
+
config.renderDistance = 6;
|
|
56
|
+
|
|
57
|
+
geo.start();
|
|
58
|
+
|
|
59
|
+
function animate() {
|
|
60
|
+
requestAnimationFrame(animate);
|
|
61
|
+
geo.onFrameUpdate(); // ← call every frame
|
|
62
|
+
renderer.render(scene, camera);
|
|
63
|
+
}
|
|
64
|
+
animate();
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
---
|
|
68
|
+
|
|
69
|
+
## 🎨 Styling
|
|
70
|
+
|
|
71
|
+
Access the style through ThreeGeoPlay `MapConfig` and modify materials directly on each layer type:
|
|
72
|
+
|
|
73
|
+
```js
|
|
74
|
+
import * as THREE from 'three';
|
|
75
|
+
|
|
76
|
+
// geo is an instance of ThreeGeoPlay
|
|
77
|
+
const style = geo.getMapConfig().mapStyle;
|
|
78
|
+
|
|
79
|
+
// Style roads
|
|
80
|
+
style.transportationLayer.primary.material = new THREE.MeshBasicMaterial({ color: 0xffffff });
|
|
81
|
+
style.transportationLayer.primary.outlineMaterial = new THREE.MeshBasicMaterial({ color: 0xcccccc });
|
|
82
|
+
style.transportationLayer.motorway.isVisible = true;
|
|
83
|
+
style.transportationLayer.pedestrian.isVisible = true;
|
|
84
|
+
|
|
85
|
+
// Style land use
|
|
86
|
+
style.landUseLayer.residential.material = new THREE.MeshBasicMaterial({ color: 0xe8f4e8 });
|
|
87
|
+
style.landUseLayer.industrial.isVisible = false;
|
|
88
|
+
|
|
89
|
+
// Style buildings — material must be transparent to enable 3D extrusion
|
|
90
|
+
style.buildingLayer.building.material = new THREE.MeshBasicMaterial({ color: 0xaaaaaa, transparent: true, opacity: 0.9 });
|
|
91
|
+
style.buildingLayer.building.isVisible = true; // false to hide all buildings
|
|
92
|
+
style.buildingLayer.building.height = 1; // extrusion scale factor
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
Each layer exposes its types directly — set `material`, `outlineMaterial`, `isVisible`, `lineWidth`, and `YOrder` per type.
|
|
96
|
+
|
|
97
|
+
---
|
|
98
|
+
|
|
99
|
+
## 🎮 Follow Mode
|
|
100
|
+
|
|
101
|
+
Attach the map to any moving object — perfect for games:
|
|
102
|
+
|
|
103
|
+
```js
|
|
104
|
+
geo.setFollowTarget(myPlayerMesh); // automatically switches to FOLLOW_TARGET mode
|
|
105
|
+
|
|
106
|
+
// Inside your animation loop:
|
|
107
|
+
geo.onFrameUpdate(); // the map re-centers as the player moves
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
---
|
|
111
|
+
|
|
112
|
+
## ⚙️ MapConfig Options
|
|
113
|
+
|
|
114
|
+
| Property | Description | Default |
|
|
115
|
+
|---|---|---|
|
|
116
|
+
| `originLatLon` | Starting `{ lat, lon }` | required |
|
|
117
|
+
| `pbfTileProviderZXYurl` | Tile URL with `{z}`, `{x}`, `{y}` | required |
|
|
118
|
+
| `zoomLevel` | OSM zoom level (12–16 recommended) | `14` |
|
|
119
|
+
| `tileWorldSize` | World units per tile | `100` |
|
|
120
|
+
| `renderDistance` | Tiles loaded around center | `3` |
|
|
121
|
+
| `tileLayout` | `TileLayout.SQUARE` or `CIRCULAR` | `SQUARE` |
|
|
122
|
+
| `showTileBorders` | Debug tile boundaries | `false` |
|
|
123
|
+
|
|
124
|
+
---
|
|
125
|
+
|
|
126
|
+
## 🗂️ Supported Layers
|
|
127
|
+
|
|
128
|
+
| Layer | Types |
|
|
129
|
+
|---|---|
|
|
130
|
+
| `transportation` | motorway, primary, secondary, tertiary, path, rail, ferry… |
|
|
131
|
+
| `building` | extruded 3D with real render heights |
|
|
132
|
+
| `waterway` | river, stream, canal, ditch… |
|
|
133
|
+
| `landuse` | residential, park, industrial, school, hospital… |
|
|
134
|
+
| `background` | ground plane |
|
|
135
|
+
|
|
136
|
+
---
|
|
137
|
+
|
|
138
|
+
## 🛰️ Tile Providers
|
|
139
|
+
|
|
140
|
+
Currently tested and supported with **[OpenMapTiles](https://openmaptiles.org/)** compatible endpoints.
|
|
141
|
+
|
|
142
|
+
> **Coming soon:** Mapbox Vector Tiles support.
|
|
143
|
+
|
|
144
|
+
---
|
|
145
|
+
|
|
146
|
+
## 📄 License
|
|
147
|
+
|
|
148
|
+
MIT
|