themustafaomar / jsvectormap

A lightweight JavaScript library for creating interactive maps and pretty data visualization.
https://jvm-docs.vercel.app
MIT License
398 stars 80 forks source link

Focus not working on US. #129

Closed andreizet closed 1 year ago

andreizet commented 1 year ago

Hey!

It seems that there is an issue with focusOn when setting the region or regions to US. On any other region, the focus works as it should.

https://codepen.io/andreizet/pen/YzORLNy?editors=0110

themustafaomar commented 1 year ago

Hi @andreizet

Unfortunately, the US has a special known case because the path takes the full width, it's impossible to focus on the US by region name.

image

However there's another way, you can focus using the coordinates, example:

const map = new jsVectorMap({
  ...
  focusOn: {
    coords: [37.0902, -95.7129],
    scale: 5,
    animate: true,
  },
  ...
})
andreizet commented 1 year ago

@themustafaomar it makes sense, indeed!

For everyone else having the same issue as I did, another solution is to focus on Mexico and Canada: regions: ['CA', 'MX']