hotfix ui freeze (zoom in map)

This commit is contained in:
Фролов 2021-09-15 12:03:03 +05:00
parent 0914449d92
commit dd9c49c626
2 changed files with 20 additions and 23 deletions

View File

@ -4,7 +4,7 @@ import {Link} from "react-router-dom";
import LoaderPortal from '../components/LoaderPortal'
import { useState, useEffect } from "react";
import {ClusterService} from '../services/api'
import { notify } from "../components/factory"
import { invokeWebApiWrapperAsync } from "../components/factory"
const calcViewParams = (clusters) => {
if ((!clusters) || clusters.length === 0)
@ -23,31 +23,30 @@ const calcViewParams = (clusters) => {
return d > max ? d : max
}, 0)
return {center, zoom: maxDeg*25}
// zoom max = 20 (too close)
// zoom min = 1 (mega far)
// 4 - full Russia (161.6 deg)
// 13.5 - Khanty-Mansiysk
let zoom = 5 + 5/maxDeg
zoom = zoom < 5 ? 5: zoom
zoom = zoom > 15 ? 15: zoom
return {center, zoom}
}
export default function Deposit() {
const [clustersData, setClustersData] = useState([])
const [showLoader, setShowLoader] = useState(false)
useEffect(()=>{
const update = async()=>{
setShowLoader(true)
try{
const data = await ClusterService.getClusters()
setClustersData(data)
}
catch(ex) {
notify(`Не удалось загрузить список кустов`, 'error')
console.log(ex)
}
setShowLoader(false)
}
update()
}, [])
useEffect(()=>invokeWebApiWrapperAsync(async()=>{
const data = await ClusterService.getClusters()
setClustersData(data)
},
setShowLoader,
`Не удалось загрузить список кустов`),
[])
const viewParams = calcViewParams(clustersData)
const markers = clustersData.map(cluster =>
<Overlay
width={32}
@ -62,9 +61,7 @@ export default function Deposit() {
return (
<LoaderPortal show={showLoader}>
<div className={'h-100vh'}>
<Map
center={viewParams.center}
zoom={viewParams.zoom}>
<Map {...viewParams}>
{markers}
</Map>
</div>

View File

@ -8,12 +8,12 @@ export default function Main() {
return (
<Switch>
<Route path="/deposit">
<LayoutPortal noSheet>
<LayoutPortal noSheet title='Месторождение'>
<Deposit />
</LayoutPortal>
</Route>
<Route path="/cluster/:idClaster/:tab?">
<LayoutPortal>
<LayoutPortal title="Анализ скважин куста">
<Cluster />
</LayoutPortal>
</Route>