1

I've been searching all over the internet and didn't find an answer. I am trying to make a map using Echarts for React. And I would like to update a map on zoom (georoam) to show smaller regions. For example on zoom=1 in will be provinces, on zoom=3 map will show regions and so on. The event listener georoam doesn't return correct current value of zoom. If I zoom in it returns 1.1, if i zoom out 0.9 only. So I was trying to calculate and set the zoom manually, but the map then doesnt work well, it zooms only into center and I cannot move it at all. So maybe you know some good solution for this. Below I paste the code of my function for georoam

const onGeoRoam = (params) => {
    if(params.zoom){
        if (params.zoom >= 1.1){
            setZoom(zoom+0.1)
        }else if(zoom >= 3 && params.zoom >= 1.1){
            setZoom(zoom+1)
        }else {
            setZoom(zoom-0.1)
        }

        if(zoom >= 2 && zoom < 3){
            setMap('regions')
        }else if(zoom >= 3 && zoom < 4){
            setMap('subregions')
        }else if(zoom >= 4 && zoom < 5){
            setMap('districts')
        }else if(zoom >= 5){
            setMap('municipalities')
        }else{
            setMap('provinces')
        }
    }

    setOption({
        tooltip: tooltip,
        series: [
            {
                name: "World PopEstimates",
                type: "map",
                roam: true,
                map: map,
                selectedMode: 'single',
                zoom: zoom,
                emphasis: emphasis,
                scaleLimit: {min: 1, max: 10},
                aspectScale: "1.1",
                itemStyle: itemStyle,
             },
        ],
    })
}

I will be very greatful for your help

  • To inspect the problem need to inspect the full code for reproduce this behavior. Could you provide it with the jsfiddle or similar tool? Counterquestion: why you just do not use `Math.round` method to get the rounded result without fight with the decimals? Or you need to provide accuracy more that 0.1? – Sergey Fedorov Oct 03 '20 at 23:21
  • 2
    Hi Sergey, thanks for your response. I prepared an example on codesandbox https://codesandbox.io/s/exciting-curie-5dkfq?file=/src/Map.js. – Ilona Novik Oct 04 '20 at 13:53

0 Answers0