FunnyShoes
Posts: 6
Joined: Thu May 26, 2022 1:25 pm

mapZoom not working as expected

I'm trying to zoom into a specific coordinate (Lat, Lon), however the map seems to zoom into some bogus point no matter what lat and lon I provide.

I'm importing the map like this

Code: Select all

import usAndCanada from '@highcharts/map-collection/custom/usa-and-canada.topo.json'
I'm trying to zoom into new york like this:

Code: Select all

    const pos = chartRef.current.chart.fromLatLonToPoint({ lat:  40, lon: -74 })
    chartRef.current.chart.mapZoom(0.5, pos.x, pos.y)
The chart zooms in but to some random spot in Canada, even when I change the lat and lon.

Any help would be appreciated.
jakub.s
Posts: 1228
Joined: Fri Dec 16, 2022 11:45 am

Re: mapZoom not working as expected

Hi,

Thanks for the question!

The solution depends on what version of Highcharts you're using. chart.mapZoom is deprecated since v9.3. You can read more about this in the API: https://api.highcharts.com/class-refere ... rt#mapZoom

The current alternative is to use chart.mapView.zoomBy.

Demo: https://jsfiddle.net/BlackLabel/h247zrpq/
API: https://api.highcharts.com/class-refere ... iew#zoomBy

Let me know if that solves your problem.

Best regards,
Jakub
Jakub
Highcharts Developer

Return to “Highcharts Maps”