【问题标题】:Mapbox : how to fit the zoom to all the markers of a map?Mapbox:如何使缩放适合地图的所有标记?
【发布时间】:2020-04-25 07:47:38
【问题描述】:

是否有一种简单的方法可以在页面刚加载时自动查看我的 Mapbox 地图的所有标记...? 这是我的地图:http://www.geometry.be/urbanmaestro/v7/ 非常感谢您的帮助!!

【问题讨论】:

标签: zooming mapbox marker markers


【解决方案1】:

您需要首先计算您的点的最小边界框,即找出地图必须放大的右上角和左下角坐标。您可以手动执行此操作,也可以使用 @turf/bbox 之类的库,其结果 (minX, minY, maxX, maxY) 可让您找到这两个点的位置。

现在,在地图初始化的任何时候,您都可以调用map.fitBounds,将两个点as documented 传递给它,顺序为[左下,右上]。

【讨论】:

  • 非常感谢您的回答。我在我的代码中做了很多测试,但我无法应用该解决方案...geometry.be/urbanmaestro/v7/test.txt如果有人知道我必须在我的代码中在哪里做,我将非常感激:-)
【解决方案2】:

只需在 Mapbox 中添加所有注释后添加此代码

let inset = UIEdgeInsets(top: 50, left: 50, bottom: 50, right: 50)

guard let annotations = mapView.annotations else {return}

self.mapView.showAnnotations(annotations, edgePadding: inset, animated: true, completionHandler: nil)

这将获取您在 Mapbox 中的所有注释,并从所有插图中显示 50 个填充。

【讨论】:

    猜你喜欢
    • 2013-05-26
    • 1970-01-01
    • 2016-11-04
    • 1970-01-01
    • 2012-12-13
    • 1970-01-01
    • 1970-01-01
    • 2018-04-13
    • 1970-01-01
    相关资源
    最近更新 更多