examples - hiro-nyon/cesium-heatbox GitHub Wiki
日本語 | English
import Heatbox from 'cesium-heatbox';
const viewer = new Cesium.Viewer('cesiumContainer', { infoBox: true });
const heatbox = new Heatbox(viewer, {
voxelSize: 30,
opacity: 0.7,
// v0.1.2 新機能
wireframeOnly: true, // 枠線のみ表示で視認性向上
heightBased: false // 高さベース表現
});
// 任意のエンティティを追加(例: ランダムポイント)
for (let i = 0; i < 1000; i++) {
const lon = 139.764 + Math.random() * 0.005;
const lat = 35.679 + Math.random() * 0.004;
const alt = Math.random() * 150;
viewer.entities.add({ position: Cesium.Cartesian3.fromDegrees(lon, lat, alt), point: { pixelSize: 5 } });
}
await heatbox.createFromEntities(viewer.entities.values);// 表示/非表示
heatbox.setVisible(false);
heatbox.setVisible(true);
// オプション更新(再描画)
heatbox.updateOptions({ voxelSize: 40, showEmptyVoxels: true });const s = heatbox.getStatistics();
console.log({
voxels: s.totalVoxels,
nonEmpty: s.nonEmptyVoxels,
entities: s.totalEntities,
max: s.maxCount,
});// point エンティティのみ対象にする
const points = Heatbox.filterEntities(viewer.entities.values, e => !!e.point);
await heatbox.createFromEntities(points);const heatbox = new Heatbox(viewer, {
voxelSize: 25,
wireframeOnly: true, // ボックス本体を透明に
showOutline: true, // 枠線を表示
outlineWidth: 2 // 枠線の太さ
});
// 重なったボクセルでも内部構造が見やすくなります
await heatbox.createFromEntities(entities);const heatbox = new Heatbox(viewer, {
voxelSize: 30,
heightBased: true, // 密度に応じて高さを調整
wireframeOnly: false, // 通常の塗りつぶし表示
opacity: 0.8
});
// 密度が高い場所ほど高いボクセルが表示されます
await heatbox.createFromEntities(entities);const heatbox = new Heatbox(viewer, {
voxelSize: 20,
wireframeOnly: true, // 枠線のみ
heightBased: true, // 高さベース
outlineWidth: 3, // 太い枠線
showEmptyVoxels: false // 空ボクセル非表示
});
// 最も視認性が良い設定
await heatbox.createFromEntities(entities);const heatbox = new Heatbox(viewer, {
showOutline: true,
outlineWidth: 3, // 全て同じ太さ
outlineOpacity: 0.7 // 重なりのノイズを抑える
});const heatbox = new Heatbox(viewer, {
outlineWidth: 2, // 非TopNの既定値
highlightTopN: 10,
highlightStyle: { outlineWidth: 6 } // TopNのみ太く
});const heatbox = new Heatbox(viewer, {
outlineWidth: 2, // 既定(resolver未適用時)
outlineWidthResolver: ({ normalizedDensity, isTopN }) => {
if (isTopN) return 4; // TopNは太く
return normalizedDensity > 0.7 ? 1 // 高密度は細く
: normalizedDensity > 0.3 ? 2 // 中密度は標準
: 3; // 低密度は太く
},
voxelGap: 1.0, // 重なり軽減(寸法縮小)
outlineOpacity: 0.6 // 重なりノイズ低減
});const heatbox = new Heatbox(viewer, {
// エミュレーション専用モード: 標準枠線/インセットを使わずエッジで太線を表現
outlineRenderMode: 'emulation-only',
showOutline: false,
opacity: 0.0,
// 密度が高いほど “太く/濃く”
outlineWidthResolver: ({ normalizedDensity }) => {
const d = Math.max(0, Math.min(1, normalizedDensity || 0));
const nd = Math.pow(d, 0.5);
const minW = 1.5, maxW = 10;
return minW + nd * (maxW - minW);
},
outlineOpacityResolver: ({ normalizedDensity }) => {
const d = Math.max(0, Math.min(1, normalizedDensity || 0));
const nd = Math.pow(d, 0.5);
return Math.max(0.15, Math.min(1.0, 0.15 + nd * 0.85));
}
});優先順位:
-
-
outlineWidthResolverが定義されていれば最優先
-
-
- なければ
highlightTopNの TopN にhighlightStyle.outlineWidth、以外はoutlineWidth
- なければ
-
- いずれも未設定なら
outlineWidthを全ボクセルに適用
- いずれも未設定なら
const heatbox = new Heatbox(viewer, {
outlineInset: 2.0, // 枠線を内側に 2m オフセット
outlineInsetMode: 'topn', // TopN のみに適用('all' で全体)
highlightTopN: 20,
outlineOpacity: 0.8,
voxelGap: 1.0 // わずかなギャップで視認性を補助
});
await heatbox.createFromEntities(viewer.entities.values);注意:
- インセットは片側最大 20%(両側合計 40%)にクランプされ、最終寸法は元の 60%以上が保証されます。
- 塗り (
opacity) が 1.0 だと内側線は見えにくくなるため、0.6〜0.9 程度を推奨。wireframeOnly: trueなら最も視認性が高いです。 - 塗り (
opacity) が 1.0 だと内側線は見えにくくなるため、0.6〜0.9 程度を推奨。wireframeOnly: trueなら最も視認性が高いです。
const heatbox = new Heatbox(viewer, {
// TopN のみ太線をポリラインで重ねる(標準モードに部分エミュを重ねる)
outlineRenderMode: 'standard',
emulationScope: 'topn',
highlightTopN: 20,
outlineWidth: 4,
// 併用: インセットがあれば中間位置に太線を描いて隣接との重なりを軽減
outlineInset: 2.0,
outlineInsetMode: 'all',
outlineOpacity: 0.8,
voxelGap: 0.5
});注:
- 太線は外縁とインセットの“中間位置”に配置され、隣接枠線と被りにくい設計です。
-
outlineInset未指定時は各軸5%の自動インセット、指定時は片側20%上限でクランプされます。
-
examples/basic/ブラウザ UI 付きの基本例(エンティティ生成→ヒートマップ作成) -
examples/outlines/outline-overlap-demo-umd.html0.1.6 の枠線重なり対策デモ(ブラウザで直接開けます) -
examples/outlines/emulation-scope-demo.htmlエミュレーションスコープと TopN ハイライトの比較デモ
実行方法:
npm install
npm run dev
ブラウザが自動起動(通常は http://localhost:8080)。
import Heatbox from 'cesium-heatbox';
const viewer = new Cesium.Viewer('cesiumContainer', { infoBox: true });
const heatbox = new Heatbox(viewer, {
voxelSize: 30,
opacity: 0.7,
// v0.1.2 new features
wireframeOnly: true, // wireframe-only display for improved visibility
heightBased: false // height-based representation
});
// Add arbitrary entities (example: random points)
for (let i = 0; i < 1000; i++) {
const lon = 139.764 + Math.random() * 0.005;
const lat = 35.679 + Math.random() * 0.004;
const alt = Math.random() * 150;
viewer.entities.add({ position: Cesium.Cartesian3.fromDegrees(lon, lat, alt), point: { pixelSize: 5 } });
}
await heatbox.createFromEntities(viewer.entities.values);// Toggle visibility
heatbox.setVisible(false);
heatbox.setVisible(true);
// Update options and re-render
heatbox.updateOptions({ voxelSize: 50, opacity: 0.9, wireframeOnly: false });
// Clear all
heatbox.clear();const stats = heatbox.getStatistics();
if (stats) {
console.log(`Total voxels: ${stats.totalVoxels}`);
console.log(`Non-empty voxels: ${stats.nonEmptyVoxels}`);
console.log(`Density range: ${stats.minCount} - ${stats.maxCount}`);
}const filteredEntities = Heatbox.filterEntities(viewer.entities.values, entity => {
const pos = entity.position?.getValue(Cesium.JulianDate.now());
return pos && Cesium.Cartographic.fromCartesian(pos).height > 100;
});
await heatbox.createFromEntities(filteredEntities);const heatbox = new Heatbox(viewer, {
voxelSize: 25,
wireframeOnly: true, // Show only outlines
outlineWidth: 2, // Outline thickness
showOutline: true
});const heatbox = new Heatbox(viewer, {
voxelSize: 20,
heightBased: true, // Height represents density
opacity: 0.6
});const heatbox = new Heatbox(viewer, {
voxelSize: 30,
wireframeOnly: true, // Wireframe-only
heightBased: true, // Height-based
outlineWidth: 3, // Thick outlines
maxRenderVoxels: 200 // Limit display count
});-
examples/basic/Basic example with browser UI (entity generation → heatmap creation)
How to run:
npm install
npm run dev
Browser auto-launches (usually http://localhost:8080).