-
Notifications
You must be signed in to change notification settings - Fork 0
/
demo1.html
82 lines (71 loc) · 2.71 KB
/
demo1.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
<!DOCTYPE html><html><head><meta charset="utf-8"><meta name="viewport" content="width=device-width">
<script type="module">
import { Pbf } from "https://taisukef.github.io/pbf/Pbf.js";
import { fetchBin } from "https://code4sabae.github.io/js/fetchBin.js";
import { VectorTile } from "https://taisukef.github.io/vector-tile-js/VectorTile.js";
import * as THREE from "https://unpkg.com/three@0.128.0/build/three.module.js";
import { OrbitControls } from 'https://cdn.jsdelivr.net/npm/three@0.121.1/examples/jsm/controls/OrbitControls.js';
const addPbfToScene = async (scene, url, color) => {
const data = await fetchBin(url);
const tile = new VectorTile(new Pbf(data));
for (const name in tile.layers) {
const layer = tile.layers[name];
for (let j = 0; j < layer.length; j++) {
const feature = layer.feature(j);
const geo = feature.loadGeometry();
// make
for (const g of geo) {
const vertices = [];
for (const p of g) {
vertices.push(new THREE.Vector3(p.x / 5, 0, p.y / 5));
}
const geometry = new THREE.BufferGeometry().setFromPoints(vertices);
const material = new THREE.PointsMaterial({
size: 2,
color,
});
const mesh = new THREE.Line(geometry, material);
//const mesh = new THREE.Points(geometry, material);
scene.add(mesh);
}
}
}
};
onload = async () => {
document.body.style.margin = "0";
document.body.style.overflow = "hidden";
const canvas = document.createElement("canvas");
document.body.appendChild(canvas);
const renderer = new THREE.WebGLRenderer({ canvas });
const scene = new THREE.Scene();
const camera = new THREE.PerspectiveCamera(45);
camera.far = 10000;
addPbfToScene(scene, "https://taisukef.github.io/sh2/zxy/7/112/50.pbf", 0xffffff);
addPbfToScene(scene, "https://taisukef.github.io/sh2/zxy/9/450/202.pbf", 0x8888ff);
addPbfToScene(scene, "https://taisukef.github.io/sh2/zxy/13/7190/3216.pbf", 0xff8800);
addPbfToScene(scene, "https://taisukef.github.io/sh2/zxy/13/7190/3217.pbf", 0x88ff88);
// const controls = new OrbitControls(camera, renderer.domElement);
let th = 0;
const tick = () => {
th += .02;
camera.position.x = 1000 * Math.sin(th);
camera.position.z = 1000 * Math.cos(th);
camera.position.y = 1000;
camera.lookAt(new THREE.Vector3(500, 0, 500));
renderer.render(scene, camera);
requestAnimationFrame(tick);
};
tick();
onresize = () => {
const width = innerWidth;
const height = innerHeight;
renderer.setPixelRatio(devicePixelRatio);
renderer.setSize(width, height);
camera.aspect = width / height;
camera.updateProjectionMatrix();
};
onresize();
};
</script>
</head>
</html>