从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
相关产品推荐
相关产品推荐

