Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[question] Updating map data? #121

Closed
tipsy opened this issue Jul 30, 2024 · 1 comment
Closed

[question] Updating map data? #121

tipsy opened this issue Jul 30, 2024 · 1 comment

Comments

@tipsy
Copy link

tipsy commented Jul 30, 2024

Is it possible to update the map data and redraw the map after the map has been created?
Preferably without resetting zoom/pan.

@tipsy
Copy link
Author

tipsy commented Jul 30, 2024

Okay, I figured it out. To update the map dynamically, you need to do

// define data
const myData = {
    data: {
      gdp: {
        name: 'GDP per capita',
        format: '{0} USD',
        thousandSeparator: ',',
        thresholdMax: 50000,
        thresholdMin: 1000
      },
      change: {
        name: 'Change to year before',
        format: '{0} %'
      }
    },
    applyData: 'gdp',
    values: {
      AF: { gdp: 587, change: 4.73 },
      AL: { gdp: 4583, change: 11.09 },
      DZ: { gdp: 4293, change: 10.01 }
      // ...
    }
}

// initialize map
const map = new Map({
  /* other config here */
 data: myData,
});

// update data
const updatedData = getUpdatedData();
map.options.data = updatedData; // update tooltips
map.applyData(updatedData); // update map

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant