openlayer 5 获取中心点

根据openlayer5中方法map.getView().getCenter()同样可以获取中心点坐标。

------------------------------------------------------------------------------------------------------------------

 

之前在控制台把map对象打印出来后,有一个很像中心点坐标map.focus_。我可以确定的告诉大家,这个不是中心点坐标,检查出来的结果是地图中心最右的点位。

在创建地图时,会将中心点左边写在view中,那么获取中心点坐标也是在view中

在官网中View中有一个事件--calculateExtent(opt_size)官网中是这么介绍的

Calculate the extent for the current view state and the passed size. The size is the pixel dimensions of the box into which the calculated extent should fit. In most cases you want to get the extent of the entire map, that is map.getSize().

NameTypeDescription
size    module:ol/size~Size

Box pixel size. If not provided, the size of the first map that uses this view will be used.(框像素大小。如果未提供,将使用使用此视图的第一个地图的大小。)

翻译过来就是:

计算当前视图状态和传递大小的范围。大小是计算范围应适合的框的像素尺寸。在大多数情况下,您希望获得整个地图的范围,即map.getSize()

把这个方法结果打印出来之后发现是一个四位数组:代表的是“框像素大小。如果未提供,将使用使用此视图的第一个地图的大小。”

在openlayer中还能extent查询到方法“getCenter”,那么把两个结果放在一起会有什么化学反应呢?

mapExtent = map.getView().calculateExtent(map.getSize())
map_center = ol.extent.getCenter(mapExtent)

中心点坐标就获取到了

--------------------------------------------------------------------------------------------------------------------------------------------

 

转载于:https://www.cnblogs.com/lucio110/p/11227414.html

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值