Political Map
intermediate conceptsWorld Map Globe Ultra Edition · Core Concepts
The globe draws countries and provinces on the terrain. The fills, the borders and the names are part of the surface, so they follow the relief. The options are in the Political Map Settings section of the globe. See Political Map Settings for the full list.
Geodata
The countries, the provinces and the cities come from the geodata in Resources/Geodata, built from public domain geodata. The globe loads them in the background when Show Political Map is on. The Map property of the globe gives them, and the lists countries, provinces and cities are the same lists.
Map is null while the geodata loads, and also when Show Political Map is off from the start. The methods that change countries and provinces throw an exception while Map is null, so a script waits until it is not null. They also throw an exception when the index of the country or of the province is out of range, so check that a search did not return -1.
using System.Collections;
using UnityEngine;
using WPM;
public class ColorSpain : MonoBehaviour {
public WorldMapGlobeUltra globe;
IEnumerator Start () {
while (globe.Map == null) yield return null;
int country = globe.GetCountryIndex("Spain");
if (country >= 0) globe.ToggleCountrySurface(country, true, new Color(1, 0.5f, 0, 0.5f));
}
}
Each country has name, continent, capitalCityIndex, its ISO codes (IsoA2, IsoA3, IsoN3) and its FIPS code (Fips), and the lists Provinces, Cities and Neighbours with indices. Each province has name, countryIndex and Neighbours.
Borders
Show Country Borders draws the borders between countries and the coasts, and Show Province Borders draws the borders between provinces. The width of a line is in pixels and stays the same at any distance. Seen from far, the lines keep their contrast over the haze of the atmosphere.
- Min View Size (km) hides the lines near the ground: they show while the height of the screen covers this ground or more, and they fade out down to half this value.
- Max View Size (km) of the provinces hides the borders and the names of the provinces from far: they show while the height of the screen covers less ground than this value, and they fade out up to twice this value. The default is 2000 km.
Colors
Give a color to a country or to a province with these methods. The alpha of the color is its opacity over the terrain. A province with no color shows the color of its country. A change of color shows at once and it has no cost in each frame. In this version the colors are plain: fill textures are not available.
| Method | Description |
|---|---|
ToggleCountrySurface(int countryIndex, bool visible, Color color) | Colors a country, or removes its color when visible is false. |
ToggleProvinceSurface(int provinceIndex, bool visible, Color color) | Colors a province, or removes its color. |
HideCountrySurface(int countryIndex), HideProvinceSurface(int provinceIndex) | Removes the color of a country or of a province. |
HideCountrySurfaces(), HideProvinceSurfaces() | Removes the colors of all the countries or of all the provinces. |
Fill Border Gradient adds a band in the color of each colored country along its borders and coasts, also when its provinces have colors of their own. The band fades toward the inside of the country and, like a band painted on the ground, it looks narrower toward the horizon. Over the band, the border line takes a dark shade of the color of the country.
Highlight & Blink
One country and one province can be highlighted at a time. The highlight fills the region with the alpha of its color and glows to the full color along the border, over the width of the band.
| Member | Description |
|---|---|
HighlightCountry(int countryIndex) | Highlights a country with Country Highlight Color, in place of the country highlighted before. |
HighlightCountry(int countryIndex, Color color) | Highlights a country with a color. |
HighlightProvince(int provinceIndex), HighlightProvince(int provinceIndex, Color color) | The same for a province, with Province Highlight Color. |
HideCountryRegionHighlights(), HideProvinceRegionHighlights() | Removes the highlight. |
int countryHighlightedIndex, provinceHighlightedIndex | The highlighted country or province, or -1. |
BlinkCountry(int countryIndex, Color color1, Color color2, float duration, float blinkingSpeed, bool smoothBlink = false) | Makes a country blink between two colors for duration seconds. The colors change every blinkingSpeed seconds, or with smoothBlink they blend back and forth blinkingSpeed times each second. |
BlinkProvince(...) | The same for a province. |
Fade Duration sets the seconds that a highlight takes to appear and to fade away. Max Screen Size sets the largest share of the screen that a highlighted region can cover: a larger region is not filled, so the screen is never painted in one color. Blinks use the real time, so they also run while the game is paused.
Names of Countries and Provinces
Show Country Names draws the name of each country inside the country. Show Province Names draws the names of the provinces, and it needs Show Province Borders. A name shows only while its letters can be read on the screen: not too small and not too large. When the names of the provinces of a country can be read, the name of the country fades away. The letters follow the relief and take the light of the Sun, so they are dark at night.
- Relative Size is the share of the room of the region that its name takes.
- Orientation: with Automatic, a name follows the shape of its region when that gives clearly larger letters, as in a long or tilted region. With Horizontal, every name reads to the east.
- Font: any font of your project. Leave it empty to use the font of the asset. The globe makes the letters at runtime, so you do not need any text package.
With Visibility set to Scripting, only the provinces of one country take names:
globe.political.provinceLabelsVisibility = PlanetaryProvinceLabelsVisibility.Scripting;
globe.DrawProvinceLabels("France"); // keeps the Labels Color
globe.DrawProvinceLabels(countryIndex, Color.yellow);
globe.HideProvinceLabels();
Queries by Place and by Ray
| Method | Description |
|---|---|
int GetCountryIndex(string name) | Index of a country by its name, or -1. |
int GetCountryIndexByISO_A2(string), GetCountryIndexByISO_A3(string), GetCountryIndexByISO_N3(string), GetCountryIndexByFIPS10_4(string) | Index of a country by its ISO code of two letters, of three letters or of three digits, or by its FIPS 10-4 code, or -1. |
int GetCountryIndex(double latitude, double longitude) | Country at a place, or -1 over the sea. |
int GetProvinceIndex(int countryIndex, string name) | Index of a province by its name inside a country, or -1, also when the country index is -1. |
int GetProvinceIndex(double latitude, double longitude) | Province at a place, or -1 over the sea. |
bool GetGlobeIntersection(Ray ray, out double latitude, out double longitude) | Place where a ray of the camera of the globe meets the drawn surface, relief included. Another overload also gives the altitude in meters over the sphere of the planet. False when the ray misses the planet. |
bool GetCountryIndex(Ray ray, out int countryIndex), GetProvinceIndex(Ray ray, out int provinceIndex) | Country or province where a ray meets the drawn surface. False over the sea, outside the planet or while the geodata loads. |
Make the ray with the camera of the globe:
// screenPosition: the place of the pointer in pixels
Ray ray = globe.flightCamera.View.ScreenPointToRay(screenPosition);
if (globe.GetCountryIndex(ray, out int country)) Debug.Log(globe.countries[country].name);
For hover and click events, use the Planetary Interaction component. See Pointer Events. The demo includes PoliticalSelectionExample, a small component that highlights the country or the province under the pointer and makes a clicked region blink, using only this API. You can copy it and change it for your game.
Data Colors
The Political Data Colors component colors the countries or the provinces from a table, for example the population or the income of each country. Add it with Add Component > World Map Globe Ultra > Political Data Colors, assign the table and click Apply Table. In Play mode, the component applies its table when it is enabled, after the geodata loads, and it removes its colors when it is disabled.
Table Format
- The table is a text asset in CSV format, with the names of the columns in its first line. The columns can be separated by commas, semicolons or tabs. With semicolons or tabs, a decimal comma is also accepted.
- The key column names each region. A country is found by its ISO code of two letters, of three letters or of three digits, or by its name. A province is found by its name, inside the country of the row when the table has a country column.
- Names are compared with no accents and with no difference between capital and small letters.
- The value column gives a number to each region, and the palette gives it a color.
- The color column gives a color to a region, as
#RGB,#RGBA,#RRGGBBor#RRGGBBAA. A row with a color does not use the palette.
country,value
ES,47.4
FR,68.2
Germany,84.5
Italy,58.9
Settings
| Setting | Default | Description |
|---|---|---|
| Globe | Empty | Globe whose countries or provinces are colored. When it is empty, the component finds the globe of the scene. |
| Table | Empty | Table in CSV format. |
| Level | Countries | Regions that the rows of the table name: Countries or Provinces. |
| Key Column | Empty | Column with the ISO code or the name of each country, or with the name of each province. The first column when it is empty. |
| Country Column | Empty | Shown with Provinces. Column with the country of each province. The column named country when it is empty. |
| Value Column | Empty | Column with the value of each region. The column named value when it is empty, or else the first column with no other use. |
| Color Column | Empty | Column with a color for each region. The column named color when it is empty. |
| Palette | A gradient | Colors of the values, from the lowest value at the left to the highest value at the right. |
| Classes | 5 | Number of steps of the palette, from 0 to 12. With 0 each value has its own color. |
| Logarithmic | Off | The steps follow the logarithm of the values, for values that grow by factors. It needs values over 0. |
| Auto Range | On | The palette goes from the lowest value of the table to the highest one. When it is off, Minimum (0) and Maximum (1) give the values of the first and of the last color. |
| Color No Data | On | The regions with no row or with no value in the table take No Data Color (gray, alpha 0.6). |
| Opacity | 0.8 | Opacity of the colors over the terrain, from 0 to 1. |
| Title | Empty | Title of the legend. |
| Value Format | 0.## | Format of the values in the legend. |
After Apply Table, the inspector shows the number of rows that match a region and lists the rows that match none, with their line numbers. Clear Colors removes the colors. The component gives the legend to your interface; it does not draw it. The DataColorsExample of the demo draws one.
Scripting
| Member | Description |
|---|---|
bool Apply() | Colors the regions from the table of the component. False when the table cannot be read or the globe is not ready. |
bool Apply(string csvText) | Colors the regions from a table given as text. |
void Clear() | Removes the colors that the component gave. |
Color ColorOf(double value) | Color of a value with the palette and the range of the last table. |
IReadOnlyList<PoliticalLegendEntry> legend | Steps of the legend, each with a label and a color, from the lowest value to the highest one, and the regions with no data at the end. |
int matchedRows, IReadOnlyList<string> unmatchedRows | Rows that match a region, and the rows that match none. |
double rangeMinimum, rangeMaximum | Values of the first and of the last color of the palette. |
string error | Why the last table could not be read, or null. |
event Action OnChanged | Raised after a table is applied or cleared. |
Suggest an improvement
Help us improve this documentation page.