maplibre-gl-3d-tiles 0.1.0

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.
Files changed (38) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +165 -0
  3. package/dist/ThreeDTilesControl-BBPpJABN.cjs +37589 -0
  4. package/dist/ThreeDTilesControl-BBPpJABN.cjs.map +1 -0
  5. package/dist/ThreeDTilesControl-BJpqhBMB.js +37590 -0
  6. package/dist/ThreeDTilesControl-BJpqhBMB.js.map +1 -0
  7. package/dist/index.cjs +53 -0
  8. package/dist/index.cjs.map +1 -0
  9. package/dist/index.mjs +53 -0
  10. package/dist/index.mjs.map +1 -0
  11. package/dist/maplibre-gl-3d-tiles.css +304 -0
  12. package/dist/react.cjs +97 -0
  13. package/dist/react.cjs.map +1 -0
  14. package/dist/react.mjs +97 -0
  15. package/dist/react.mjs.map +1 -0
  16. package/dist/types/geolibre.d.ts +20 -0
  17. package/dist/types/geolibre.d.ts.map +1 -0
  18. package/dist/types/index.d.ts +5 -0
  19. package/dist/types/index.d.ts.map +1 -0
  20. package/dist/types/lib/core/ThreeDTilesControl.d.ts +69 -0
  21. package/dist/types/lib/core/ThreeDTilesControl.d.ts.map +1 -0
  22. package/dist/types/lib/core/ThreeDTilesControlReact.d.ts +3 -0
  23. package/dist/types/lib/core/ThreeDTilesControlReact.d.ts.map +1 -0
  24. package/dist/types/lib/core/ThreeDTilesLayer.d.ts +45 -0
  25. package/dist/types/lib/core/ThreeDTilesLayer.d.ts.map +1 -0
  26. package/dist/types/lib/core/types.d.ts +61 -0
  27. package/dist/types/lib/core/types.d.ts.map +1 -0
  28. package/dist/types/lib/hooks/index.d.ts +2 -0
  29. package/dist/types/lib/hooks/index.d.ts.map +1 -0
  30. package/dist/types/lib/hooks/useThreeDTilesState.d.ts +13 -0
  31. package/dist/types/lib/hooks/useThreeDTilesState.d.ts.map +1 -0
  32. package/dist/types/lib/utils/helpers.d.ts +86 -0
  33. package/dist/types/lib/utils/helpers.d.ts.map +1 -0
  34. package/dist/types/lib/utils/index.d.ts +2 -0
  35. package/dist/types/lib/utils/index.d.ts.map +1 -0
  36. package/dist/types/react.d.ts +4 -0
  37. package/dist/types/react.d.ts.map +1 -0
  38. package/package.json +110 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Qiusheng Wu
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,165 @@
1
+ # MapLibre GL 3D Tiles
2
+
3
+ A MapLibre GL JS control for rendering 3D Tiles with three.js and `3d-tiles-renderer`. It provides a standalone `IControl`, a React wrapper, Vite examples, a Docker example server, and a GeoLibre plugin bundle.
4
+
5
+ ## Features
6
+
7
+ - MapLibre custom 3D layer backed by three.js
8
+ - 3D Tiles rendering through `3d-tiles-renderer`
9
+ - GLTF, Draco, and KTX2 loader support
10
+ - Collapsible MapLibre control with URL, altitude offset, visibility, load, remove, and fly-to actions
11
+ - Multiple tilesets on the same map with per-tileset visibility, fly-to, and remove actions
12
+ - TypeScript API and React wrapper
13
+ - GeoLibre plugin zip build
14
+
15
+ ## Installation
16
+
17
+ ```bash
18
+ npm install maplibre-gl-3d-tiles
19
+ ```
20
+
21
+ ## Vanilla Usage
22
+
23
+ ```typescript
24
+ import maplibregl from 'maplibre-gl';
25
+ import { ThreeDTilesControl } from 'maplibre-gl-3d-tiles';
26
+ import 'maplibre-gl-3d-tiles/style.css';
27
+ import 'maplibre-gl/dist/maplibre-gl.css';
28
+
29
+ const map = new maplibregl.Map({
30
+ container: 'map',
31
+ style: 'https://tiles.openfreemap.org/styles/bright',
32
+ center: [0, 0],
33
+ zoom: 1,
34
+ pitch: 60,
35
+ maxPitch: 80,
36
+ canvasContextAttributes: { antialias: true },
37
+ });
38
+
39
+ map.on('load', () => {
40
+ const control = new ThreeDTilesControl({
41
+ collapsed: false,
42
+ tilesetUrl: 'https://pelican-public.s3.amazonaws.com/3dtiles/agi-hq/tileset.json',
43
+ altitudeOffset: -300,
44
+ });
45
+
46
+ map.addControl(control, 'top-right');
47
+ void control.loadTileset();
48
+ void control.loadTileset('https://example.com/another/tileset.json', {
49
+ altitudeOffset: 0,
50
+ });
51
+ });
52
+ ```
53
+
54
+ ## React Usage
55
+
56
+ ```tsx
57
+ import { useEffect, useRef, useState } from 'react';
58
+ import maplibregl, { Map } from 'maplibre-gl';
59
+ import {
60
+ ThreeDTilesControlReact,
61
+ useThreeDTilesState,
62
+ } from 'maplibre-gl-3d-tiles/react';
63
+ import 'maplibre-gl-3d-tiles/style.css';
64
+
65
+ function App() {
66
+ const mapContainer = useRef<HTMLDivElement>(null);
67
+ const [map, setMap] = useState<Map | null>(null);
68
+ const { state, setState } = useThreeDTilesState({ collapsed: false });
69
+
70
+ useEffect(() => {
71
+ if (!mapContainer.current) return;
72
+
73
+ const mapInstance = new maplibregl.Map({
74
+ container: mapContainer.current,
75
+ style: 'https://tiles.openfreemap.org/styles/bright',
76
+ center: [0, 0],
77
+ zoom: 1,
78
+ pitch: 60,
79
+ maxPitch: 80,
80
+ canvasContextAttributes: { antialias: true },
81
+ });
82
+
83
+ mapInstance.on('load', () => setMap(mapInstance));
84
+ return () => mapInstance.remove();
85
+ }, []);
86
+
87
+ return (
88
+ <>
89
+ <div ref={mapContainer} style={{ width: '100%', height: '100vh' }} />
90
+ {map && (
91
+ <ThreeDTilesControlReact
92
+ map={map}
93
+ collapsed={state.collapsed}
94
+ onStateChange={(nextState) => setState(nextState)}
95
+ />
96
+ )}
97
+ </>
98
+ );
99
+ }
100
+ ```
101
+
102
+ ## API
103
+
104
+ ### ThreeDTilesControl
105
+
106
+ Constructor options include:
107
+
108
+ | Option | Type | Default |
109
+ | --- | --- | --- |
110
+ | `tilesetUrl` | `string` | MapLibre example tileset |
111
+ | `altitudeOffset` | `number` | `-300` |
112
+ | `flyToOnLoad` | `boolean` | `true` |
113
+ | `visible` | `boolean` | `true` |
114
+ | `layerId` | `string` | `maplibre-gl-3d-tiles` |
115
+ | `collapsed` | `boolean` | `true` |
116
+ | `panelWidth` | `number` | `360` |
117
+ | `position` | MapLibre control position | `top-right` |
118
+
119
+ Main methods:
120
+
121
+ - `loadTileset(url?, options?)`
122
+ - `removeTileset(id?)`, removes all tilesets when no id is passed
123
+ - `setVisible(visible, id?)`
124
+ - `flyToTileset(id?)`
125
+ - `getState()`
126
+ - `setState(state)`
127
+ - `toggle()`, `expand()`, `collapse()`
128
+ - `on(event, handler)`, `off(event, handler)`
129
+
130
+ Events:
131
+
132
+ ```text
133
+ collapse, expand, statechange, loadstart, load, error, remove, visibilitychange
134
+ ```
135
+
136
+ ## Development
137
+
138
+ ```bash
139
+ npm install
140
+ npm run dev
141
+ npm test
142
+ npm run build
143
+ npm run build:examples
144
+ ```
145
+
146
+ ## GeoLibre Plugin Bundle
147
+
148
+ ```bash
149
+ npm run package:geolibre
150
+ ```
151
+
152
+ This creates:
153
+
154
+ ```text
155
+ geolibre-plugin/maplibre-gl-3d-tiles-0.1.0.zip
156
+ ```
157
+
158
+ ## Docker
159
+
160
+ ```bash
161
+ docker build -t maplibre-gl-3d-tiles .
162
+ docker run -p 8080:80 maplibre-gl-3d-tiles
163
+ ```
164
+
165
+ Open http://localhost:8080/maplibre-gl-3d-tiles/ to view the examples.