You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

从Leaflet迁移到OpenGlobus:如何实现相机缩放到边界框?

OpenGlobus 实现相机缩放到指定边界框

在OpenGlobus中,你可以通过createBoundsByExtent创建边界对象,再配合相机的flyTo或setView方法,实现和Leaflet fitBounds一致的功能。以下是适配你现有数据的简短示例:

// 转换Leaflet风格的边界坐标为OpenGlobus的extent格式 [west, south, east, north]
const extent = [
  data.boundingbox[2], // 对应Leaflet bounds的west
  data.boundingbox[0], // 对应Leaflet bounds的south
  data.boundingbox[3], // 对应Leaflet bounds的east
  data.boundingbox[1]  // 对应Leaflet bounds的north
];

// 创建OpenGlobus边界对象
const bounds = og.bounds.createBoundsByExtent(extent);

// 带动画飞至目标边界
map.camera.flyTo({ bounds: bounds });

// 若无需动画,直接设置视图
// map.camera.setView({ bounds: bounds });

注意:createBoundsByExtent的入参格式是[west, south, east, north],和Leaflet的[[south, west], [north, east]]顺序不同,需对应好坐标位置。

内容的提问来源于stack exchange,提问作者pvlt

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.24 22:06:22