Cities, Places & Anchors
intermediate conceptsWorld Map Globe Ultra Edition · Core Concepts
This page describes the cities of the geodata, the pointer events of the Planetary Interaction component, the search of postal addresses, and the Planetary Anchor component, which keeps your own objects at a place of the planet.
Cities
The cities come from the geodata of the globe, with the countries and the provinces. They load when Show Political Map is on, and cities is null while they load. The globe does not draw the cities: to show a city, place your own object on it with a Planetary Anchor, as the pins of the demo do.
Each city (PoliticalMap.City, in the WPM.Planetary namespace) has name, countryIndex, province (the name of its province), population, latitude, longitude and cityClass: CITY_CLASS.CITY, CITY_CLASS.REGION_CAPITAL or CITY_CLASS.COUNTRY_CAPITAL.
City Methods
| Method | Description |
|---|---|
PoliticalMap.City[] cities | All the cities, or null while the geodata loads. |
GetCity(int cityIndex), GetCity(string countryName, string cityName), GetCity(int countryIndex, string cityName) | A city, or null. |
int GetCityIndex(string cityName) | Index of the most populated city with a name, or -1. |
int GetCityIndex(string countryName, string cityName) | Index of a city by the name of its country and its own name, or -1. |
int GetCityIndex(string countryName, string provinceName, string cityName), GetCityIndex(int countryIndex, string provinceName, string cityName) | Index of a city by its country, its province and its own name, or -1. |
int GetCityIndexInCountry(int countryIndex, string cityName), GetCityIndexInCountry(string countryName, string cityName) | Index of a city by its name inside a country, or -1. |
int GetCityIndexInProvince(int provinceIndex, string cityName) | Index of a city by its name inside a province, or -1. |
int GetCityIndex(PoliticalMap.City city) | Index of a city object, or -1. |
int GetCityIndex(double latitude, double longitude) | Index of the nearest city to a place, or -1 while the geodata loads. |
int GetCityIndex(Vector2 latlon, int cityIndexToExclude = -1) | Index of the nearest city to a place, given as latitude (X) and longitude (Y). One city can be left out, to find the nearest city to another city. |
bool GetCityIndex(Ray ray, out int cityIndex, int countryIndex = -1) | City under a ray of the camera of the globe: the nearest one on the screen within a few pixels of the ray, among the cities that Min Population (K) and Always Visible let in. A country limits the search to its cities. |
bool GetCityIndex(Ray ray, out int cityIndex, int countryIndex, float maxPixels) | The same, with the largest distance in pixels from the ray to the city. |
string[] GetCityNames(), GetCityNames(bool includeCityIndex), GetCityNames(int countryIndex, bool includeCityIndex) | Names of all the cities, or of the cities of a country. With includeCityIndex, each name ends with the index of the city in brackets. |
string GetCityCountryName(int cityIndex), GetCityProvinceName(int cityIndex) | Name of the country or of the province of a city. |
string GetCityFullName(int cityIndex) | Name of a city with its province and its country in brackets. |
Vector2 GetCityLatLon(int cityIndex) | Latitude (X) and longitude (Y) of a city. |
GetCountryCapital(int countryIndex), GetCountryCapital(string countryName) | Capital of a country, or null. |
int GetCountryCapitalIndex(int countryIndex), GetCountryCapitalIndex(string countryName) | Index of the capital of a country, or -1. |
FlyToCity(int cityIndex, float duration = 0), FlyToCity(string cityName), FlyToCity(string countryName, string cityName) | Flies the camera to a view of a city, at an altitude of 12,000 meters. With no duration, the duration follows the distance. With only the name of the city, it flies to the most populated city with that name. |
Pointer Events
The Planetary Interaction component finds the country, the province and the city under the mouse, or under the finger on a touch screen, and also the constellation and the star of the sky. It raises events when the pointer enters or leaves one, presses it, releases it or clicks it. Add it to any object and set its globe. The events of the countries, the provinces and the cities have the names and the arguments of World Map Globe Edition.
| Setting | Default | Description |
|---|---|---|
| Globe | Empty | Globe that the pointer explores. |
| Read Pointer | On | Reads the mouse or the touch screen every frame. Turn it off to give the pointer from your own code with UpdatePointer. |
| City Pick Pixels | 16 | Largest distance in pixels from the pointer to a city. |
| City Pick Offset | 0, 0 | Offset in pixels of the picture of a city from its place on the ground. Set it when an icon or a pin is drawn above the city. |
| Constellation Pick Pixels | 12 | Largest distance in pixels from the pointer to a line of a constellation or to a star with a name. |
| Event | Arguments |
|---|---|
OnCityEnter, OnCityExit | (int cityIndex) |
OnCityPointerDown, OnCityPointerUp, OnCityClick | (int cityIndex, int buttonIndex) |
OnCountryEnter, OnCountryExit | (int countryIndex, int regionIndex) |
OnCountryPointerDown, OnCountryPointerUp, OnCountryClick | (int countryIndex, int regionIndex, int buttonIndex) |
OnProvinceEnter, OnProvinceExit | (int provinceIndex, int regionIndex) |
OnProvincePointerDown, OnProvincePointerUp, OnProvinceClick | (int provinceIndex, int regionIndex, int buttonIndex) |
OnConstellationEnter, OnConstellationExit, OnConstellationClick | (int constellationIndex) |
OnStarEnter, OnStarExit | (int starIndex) |
The button is 0 for the main button or a touch, and 1 for the secondary button. A click is a release with the pointer still at the place where it was pressed. The region is the part of the country or of the province under the pointer, for example an island. While the pointer is over an element of the user interface, the regions, the cities and the constellations under it are not reported.
The events of the constellations need Show Constellations. A constellation answers where the pointer is over the sky near its lines, and a star when it has a name. OnConstellationClick is raised for the main button only. The component also highlights the constellation under the pointer. See Constellations. All the events need the geodata, so they are raised while Show Political Map is on and after the geodata loads.
| Member | Description |
|---|---|
int cityUnderPointer, countryUnderPointer, provinceUnderPointer | City, country and province under the pointer, or -1. |
int countryRegionUnderPointer, provinceRegionUnderPointer | Region under the pointer, or -1. |
int constellationUnderPointer, starUnderPointer | Constellation and star under the pointer, or -1. The name of the star is GetStarName of the globe. |
int cityLastClicked, countryLastClicked, provinceLastClicked | Last city, country and province that a click selected, or -1. |
void UpdatePointer(Vector2 screenPosition, bool pressed, bool secondaryPressed = false) | Gives the place of the pointer in pixels of the screen and the state of its buttons, and raises the events that follow. Use it with Read Pointer off, for another kind of pointer. |
using UnityEngine;
using WPM;
public class ClickInfo : MonoBehaviour {
public WorldMapGlobeUltra globe;
public PlanetaryInteraction interaction;
void OnEnable () {
interaction.OnCountryClick += CountryClicked;
interaction.OnCityEnter += CityEntered;
}
void OnDisable () {
interaction.OnCountryClick -= CountryClicked;
interaction.OnCityEnter -= CityEntered;
}
void CountryClicked (int countryIndex, int regionIndex, int buttonIndex) {
globe.HighlightCountry(countryIndex);
}
void CityEntered (int cityIndex) {
Debug.Log(globe.GetCityFullName(cityIndex));
}
}
interaction.OnCityEnter += ... in place of map.OnCityEnter += ....
Places by Address
The globe can find the latitude and the longitude of a postal address, or of the name of a place, with a geocoding service, and it can fly the camera there.
| Method | Description |
|---|---|
void GetLocation(string address, Action<GeocodingResult> onResult) | Asks the service for the place of an address. The answer arrives later, also when the address is not found. |
void FlyToAddress(string address, double altitude = 600, float duration = 0, Action<GeocodingResult> onResult = null) | Flies to a view of an address when the service answers. The altitude is the height of the camera above sea level in meters at the end of the flight. |
A GeocodingResult has found, latitude, longitude, name (the full name of the place, as the service gives it) and error. The service may return the street when it does not know the house number. The globe sends one request each second at most, and it keeps the places that it found while the application runs, so the same address is not asked again.
globe.FlyToAddress("Plaza Mayor, Madrid", 800, 0, result => {
if (!result.found) Debug.Log(result.error);
});
The settings are in globe.geocoding and they are set from scripts:
| Field | Description |
|---|---|
serviceUrl | Address of the service. The default is a public search service that is for light use only and that requires a credit. For a published application, use your own server or another provider that answers in the same format. |
applicationName | Name of your application, which the service receives with each request. When it is empty, the product name of the project is sent. |
Anchors
Add the Planetary Anchor component to any object, for example a vehicle, a unit, a missile or a pin, to keep it at a place of the planet with full precision, from orbit down to the ground, with no shaking. The anchor sets the position of the object, and also its rotation unless Orientation is Free. Anchors also work in Edit mode.
| Setting | Default | Description |
|---|---|---|
| Globe | Empty | Globe of the planet. When it is empty, the anchor takes the first globe of the scene. |
| Latitude, Longitude | 0, 0 | Place in degrees. |
| Altitude | 0 | Meters over the Altitude Reference. |
| Altitude Reference | Ground | Ground adds the altitude to the drawn ground, relief included, and the object follows the ground when its detail changes. Sea Level adds the altitude to the sphere of the planet. |
| Orientation | Upright | Free leaves the rotation to your scripts. Upright stands the object on the vertical of the place, and Ground stands it on the slope of the drawn ground. Both turn it to the Heading. |
| Heading | 0 | Degrees clockwise from the north, for Upright and Ground. |
| Member | Description |
|---|---|
void SetLocation(double latitude, double longitude, double altitude) | Moves the object to a place. The globe places it before the next draw of the Game view. |
double latitude, longitude, altitude, float heading | Place and heading. You can also change them directly. |
PlanetaryAltitudeReference altitudeReference, PlanetaryAnchorOrientation orientation | Altitude Reference and Orientation. |
Double3 PlanetPosition | Place of the object in meters from the center of the planet, as the globe placed it last. |
double GroundHeight | Height in meters of the drawn ground under the object, or 0 where no ground is drawn. |
bool OnDrawnGround | True when a drawn tile was under the object the last time the globe read the ground. |
The anchors have no Update of their own: the globe places all of them once per frame, just before the Game view is drawn, so a script can move them in Update or in LateUpdate. The globe reads the ground again only when an anchor moves or when the ground under it changes, so thousands of anchors that do not move cost very little. AnchorCount on the globe gives the number of anchors.
PlanetaryAnchor anchor = drone.AddComponent<PlanetaryAnchor>();
anchor.altitudeReference = PlanetaryAltitudeReference.SeaLevel;
anchor.SetLocation(45.8326, 6.8652, 5100);
anchor.heading = 90;Suggest an improvement
Help us improve this documentation page.