gpt4 book ai didi

javascript - 如何使用 OpenLayers 区分用户和函数对 map 移动的变化

转载 作者:行者123 更新时间:2023-12-02 21:32:59 28 4
gpt4 key购买 nike

我有一个简单的功能,用户启动 GPS 和跟踪位置, map View 跟随他。我想在用户平移 map 时停用跟随功能,但保持跟踪位置功能处于激活状态,以便用户可以移动 map 并仍然查看其位置。我尝试使用 map events (moveendmovestartchange),但无论 map 如何移动,它们都会触发。我还尝试了 click 事件,但平移 map 时不会触发此事件,只有在快速发生单击时才会触发。

有没有办法检查这种差异?

OpenLayers track position example供引用

<小时/>

我发现一些与我的问题非常相似的相关问题:12 .

引用第二个问题:

map.on('moveend', function(event) {
var mapView = map.getView(),
moveInitiatedProgrammatically = mapView.get('moveInitiatedProgrammatically') || false;

mapView.unset('moveInitiatedProgrammatically');

// evaluate moveInitiatedProgrammatically's value and behave accordingly...
});

map.getView().set('moveInitiatedProgrammatically', true);
map.getView().setCenter(coord);

It's not ideal for the following reasons:

  1. Introduces additional state information in the map's view.
  2. Carelessly replacing the map view will lose that state information.
  3. Requires setting a property before changing the view state and may be too easily forgotten.

However, it adresses my issue in the meantime.

最佳答案

使用ol-ext ol/control/GeolocationBar。您可以开始新的轨道。当您移动 map 时,center 按钮可让您回到轨迹中心。
在线查看示例:https://viglino.github.io/ol-ext/examples/mobile/map.control.geolocationbar.html

关于javascript - 如何使用 OpenLayers 区分用户和函数对 map 移动的变化,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60570190/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com