Zooming in to view a single country from a world map

edited February 2014 in Library Questions

I have a world map and I want to zoom in to view only a single country when I click on it. I am using the unfolding maps library to render the map. In one of it's examples, MarkerSelectinApp, a country is highlighted is the mouse is on top of it.

What I was planning is that, if the mouse is pressed inside a country, I can zoom and pan to the center of the country, only the data about the center of the country isnt available, and i couldnt find it anywhere on the web (assuming that there is something such as the center of a country).

Does anyone have any experience is doing something related or have another idea on how to implement this.


  • I can think of a way to do it, but you won't like it. When you mouse over a country, that country is highlighted. That means that you can determine which pixels on the screen change when a country is selected. That means that you can determine the smallest box that will encompass those changed pixels. From that, you can determine the point to zoom in at, and how much to zoom in. You can either predetermine this for each country and save that information in some structure that you load, or do it on the fly when one is picked. Your call.

  • "I am using the unfolding maps library"
    Then this question belongs to the Questions about Libraries category, where I moved it...

    To newcomers in this forum: read attentively these instructions

  • You can pan to the center of the country by using Unfolding's GeoUtils.


    Location countryCenter = GeoUtils.getCentroid(GeoUtils.getLocations(marker));

    or if you don't have a marker and draw it on your own, the same for locations:

    Location countryCenter = GeoUtils.getCentroid(countryLocations);

    and use


  • Just to be sure I understand correctly, countryLocation is the current mouseX and mouseY location? And I think the countries.geo.json data is to be used to identify the boundaries of the country?

  • Missed your response.

    In my code lines I'd assumed you use the MarkerSelectionApp as basis. There, the countries.geo.json file is used to load country boundaries. The other option is to use some other source and store it as list of locations (in my example the countryLocations).

Sign In or Register to comment.