| | |
| | | |
| | | /** |
| | | * 通过中心点主动触发吸附判断。 |
| | | * @param options.allowAdsorb 是否允许吸附到最近点位,默认允许;查看运营区域等仅浏览场景需传 false 以保持视野不被吸附打断。 |
| | | */ |
| | | const queryPointerByCenter = async (lat: number, lng: number) => { |
| | | const queryPointerByCenter = async (lat: number, lng: number, options?: { allowAdsorb?: boolean }) => { |
| | | const allowAdsorb = options?.allowAdsorb !== false; |
| | | siteState.setBounce(true); |
| | | siteState.setShowToolTip(false); |
| | | try { |
| | |
| | | siteState.clearCachedStartSiteSelection(); |
| | | commitQueriedMarkers(newMarkers, false, false); |
| | | settleRegionResult({ lat, lon: lng, isInside: false }); |
| | | siteState.setIsAdsorbed(false); |
| | | if (allowAdsorb) { |
| | | siteState.setShowToolTip(true); // 运营区外恢复气泡提示 |
| | | } |
| | | siteState.setBounce(false); |
| | | return; |
| | | } |
| | | const nearestCandidates = sites.length > 0 ? sites : newMarkers; |
| | | const { adsorbed, marker } = siteState.tryAdsorb(lat, lng, nearestCandidates); |
| | | const { adsorbed, marker } = allowAdsorb |
| | | ? siteState.tryAdsorb(lat, lng, nearestCandidates) |
| | | : { adsorbed: false, marker: null }; // 仅浏览运营区域时不吸附最近点位 |
| | | commitQueriedMarkers(newMarkers, true, adsorbed); |
| | | const finalLat = adsorbed && marker ? marker.latitude : lat; // 最终纬度 |
| | | const finalLng = adsorbed && marker ? marker.longitude : lng; // 最终经度 |
| | | mapState.setLatitude(finalLat); |
| | | mapState.setLongitude(finalLng); |
| | | if (allowAdsorb) { |
| | | // 仅浏览运营区域时不回写地图中心,避免 Map 组件按旧 scale 重绘导致刚展开的运营区视野被收回 |
| | | mapState.setLatitude(finalLat); |
| | | mapState.setLongitude(finalLng); |
| | | } |
| | | settleRegionResult({ lat: finalLat, lon: finalLng, isInside: true }); |
| | | setTimeout(async () => { |
| | | siteState.setBounce(false); |
| | | if (!adsorbed) { |
| | | await siteState.resolveAddress(lat, lng); |
| | | } |
| | | if (!allowAdsorb) { |
| | | siteState.setShowToolTip(false); // 查看运营区域期间隐藏气泡,避免遮挡围栏,拖动地图后自动恢复 |
| | | } |
| | | }, 600); |
| | | } catch (error) { |
| | |
| | | siteState.clearCachedStartSiteSelection(); |
| | | commitQueriedMarkers(newMarkers, false, false); |
| | | settleRegionResult({ lat, lon: lng, isInside: false }); |
| | | siteState.setIsAdsorbed(false); |
| | | siteState.setShowToolTip(true); // 运营区外恢复气泡提示 |
| | | siteState.setBounce(false); |
| | | return; |
| | | } |