如果您看不到边界线,请按照以下步骤调试:
- Chrome/Edge: 按
F12或Ctrl+Shift+I(Windows) /Cmd+Option+I(Mac) - Firefox: 按
F12或Ctrl+Shift+K(Windows) /Cmd+Option+K(Mac)
启动应用后,您应该在控制台中看到以下日志序列:
📂 loadShapefile called with path: /shapefiles/ne_110m_admin_0_countries.shp
📂 Base path: /shapefiles/ne_110m_admin_0_countries
📥 Fetch responses: { shp: { ok: true, status: 200 }, dbf: { ok: true, status: 200 } }
✅ Files fetched successfully
✅ Buffers loaded: { shpSize: 180924, dbfSize: 531808 }
📊 Parsed data: { shpFeatures: XXX, dbfRecords: XXX }
✅ GeoJSON created: { type: 'FeatureCollection', featuresCount: 177 }
📝 Sample feature: { type: 'MultiPolygon', properties: [...] }
🔄 [BoundaryLayer] Loading shapefile: /shapefiles/ne_110m_admin_0_countries.shp
📊 [BoundaryLayer] Processing 177 features
🔍 [BoundaryLayer] Line 1: { featureIdx: 0, polygonIdx: 0, ringIdx: 0, pointsCount: XXX, ... }
🔍 [BoundaryLayer] Line 2: ...
🔍 [BoundaryLayer] Line 3: ...
✅ [BoundaryLayer] Created XXX boundary lines from XXX rings
🎨 [BoundaryLayer] Rendering XXX lines with color #FFD700
🖊️ [BoundaryLayer] Rendering line 0/XXX
🖊️ [BoundaryLayer] Rendering line 100/XXX
...
日志:
❌ Failed to fetch SHP file: 404 Not Found
原因: Shapefile 文件不在 public 目录中
解决:
# 检查文件是否存在
ls -la public/shapefiles/
# 应该看到:
# ne_110m_admin_0_countries.shp
# ne_110m_admin_0_countries.dbf
# ne_110m_admin_0_countries.shx日志:
Access to fetch at '...' has been blocked by CORS policy
解决: 确保使用开发服务器运行 (npm run dev),而不是直接打开 HTML 文件
日志:
TypeError: shp.combine is not a function
解决:
# 重新安装 shpjs
npm uninstall shpjs
npm install shpjs可能原因:
-
颜色问题: 边界线颜色可能与背景混淆
- 尝试更改颜色:在
src/App.tsx中修改color: '#FF0000'(红色)
- 尝试更改颜色:在
-
半径问题: 边界线可能在地球内部或太远
- 检查控制台中
firstPoint的坐标值 - 坐标应该接近 1.005 左右
- 检查控制台中
-
相机位置: 相机可能看向错误的方向
- 尝试用鼠标拖动地球旋转查看不同角度
-
线条太细: WebGL 的 lineWidth 限制
- 已设置为
lineWidth: 2 - @react-three/drei 的 Line 组件应该能正确处理
- 已设置为
打开浏览器访问:
http://localhost:5173/shapefiles/ne_110m_admin_0_countries.shp
应该能下载文件(不是 404)
在浏览器控制台输入:
// 查看场景中的对象
console.log(window.scene) // 可能需要在开发者工具中查找 Three.js scene编辑 src/App.tsx:
{
id: 'countries',
name: '国界 (110m)',
shpPath: '/shapefiles/ne_110m_admin_0_countries.shp',
color: '#FF0000', // 改为亮红色
visible: true,
}编辑 src/components/BoundaryLayer.tsx:
lineWidth = 5, // 改为 5(更粗)-
npm run dev正在运行 - 浏览器开发者工具已打开
- 控制台没有红色错误信息
- 看到 "✅ [BoundaryLayer] Created XXX boundary lines" 日志
- 看到 "🎨 [BoundaryLayer] Rendering XXX lines" 日志
- 文件
public/shapefiles/ne_110m_admin_0_countries.shp存在 - 文件
public/shapefiles/ne_110m_admin_0_countries.dbf存在
如果以上步骤都无法解决问题,请提供:
- 完整的控制台日志(复制所有内容)
- 浏览器版本
- 操作系统
ls -la public/shapefiles/的输出
成功时,您应该看到:
- 一个带有高质量纹理的地球
- 金色(#FFD700)的国界边界线
- 图层控制面板在左侧
- 可以用鼠标拖动旋转地球
- 可以用滚轮缩放