question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Zoom in on Country

See original GitHub issue

It would be incredibly useful to center and zoom based on the returned <Geography />s within <Geographies />. I think it could be helpful as a prop within <ZoomableGroup />.

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:3
  • Comments:16 (12 by maintainers)

github_iconTop GitHub Comments

5reactions
abemediacommented, Oct 19, 2017

The beauty of open source 🙂

4reactions
abemediacommented, Oct 18, 2017

I have managed to solve the issue of zooming in to a clicked country as follows, however how would I go about skipping the click event on the case of panning the map?

  handleGeographyClick(geography) {
    // geography looks something like this:
    // { type: "Feature",  properties: {...}, geometry: {...} }

    // zoom out if this country is already selected
    if (this.state.currentCountry === geography.properties.iso_a3) {
      return this.setState({
        center: [0,0],
        zoom: 1,
        currentCountry: null
      });
    }

    const path = geoPath().projection(this.projection());
    const center = this.projection().invert(path.centroid(geography));

    // calculate zoom level
    const bounds = path.bounds(geography);
    const dx = bounds[1][0] - bounds[0][0];
    const dy = bounds[1][1] - bounds[0][1];
    const zoom = 0.9 / Math.max(dx / this.props.width, dy / this.props.height);

    this.setState({ 
      center, 
      zoom, 
      currentCountry: geography.properties.iso_a3 
    });
  }
Read more comments on GitHub >

github_iconTop Results From Across the Web

Zooming to Countries Map - amCharts
geoMercator() })); // Create main polygon series for countries // https://www.amcharts.com/docs/v5/charts/map-chart/map-polygon-series/ var polygonSeries ...
Read more >
Specifying global dial-in countries/regions - Zoom Support
Sign in to the Zoom web portal. · In the navigation panel, click Settings. · Click the Audio Conferencing tab. · Scroll down...
Read more >
Earth View Maps
Find your new travel destination by searching for a country, city and even a street name. Zoom in or zoom out with scroller...
Read more >
One chart a day - Zoom in to per country in the world map / Rich
One chart a day - Zoom in to per country in the world map ... Objectives: Zoom in to per country in the...
Read more >
Zoom in on a country when the id is set - Highcharts official ...
Re: Zoom in on a country when the id is set ... Hello Patric, Welcome to our forum and thanks for contacting us...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found