skip to Main Content

Scripting Support (C#)

You can instantiate the prefab “WorldMap2D“ or add it to the scene from the Editor. Once the prefab is in the scene, you can access the functionality from code through the static instance property:

Using WPMF;

WorldMap2D map;

void Start () {
map = WorldMap2D.instance;
   ...
}

(Note that you can have more WorldMap2D instances in the same scene. In this case, the instance property will returns the same object. To use the API on a specific instance, you can get the WorldMap2D component of the GameObject).

Most of the public API and properties are located in WorldMap2D script inside Scripts/Core folder. Below is a list of them:

Public Events

public event OnCountryEvent OnCountryEnter;

public event OnCountryEvent OnCountryExit;

public event OnCountryClick OnCountryClick;

public event OnCountryHighlight OnCountryHighlight;

 

public event OnProvinceEvent OnProvinceEnter;

public event OnProvinceEvent OnProvinceExit;

public event OnProvinceClick OnProvinceClick;                 

public event OnProvinceHighlight OnProvinceHighlight;

 

public event OnCityEnter OnCityEnter;

public event OnCityEnter OnCityExit;

public event OnCityClick OnCityClick;

public event OnSimpleMapEvent OnDragStart;

public event OnSimpleMapEvent OnDragEnd;

Public Properties & Methods

Country related

map.countries: the array of Country objects. Note that the number and indexes of countries varies between the low and high-definition geodata files (reloaded when you change the frontiersQuality property in the inspector or in the API).

map.GetCountryIndex(name): returns the index of the country in the array.

map.GetCountryIndex(localPosition): returns the country that contains a map coordinate.

map.GetCountryNearToPoint(localPosition): returns the country that contains a map coordinate or the country whose center is nearest to the map coordinate.

map.GetCountryIndex(ray, out countryIndex, out regionIndex): find the country pointed by the ray.

map.GetCountryNames(groupByContinent): returns an array with the country names, optionally grouped by continent.

map.countryHighlighted: returns the Country object for the country under the mouse cursor (or null).

map.countryHighlightedIndex: returns the index of country under the mouse cursor (or null if none).

map.countryRegionHighlighted: returns the Region object for the highlighted country (or null). Note that many contries have more than one region. The field mainRegionIndex of the Country object specified which region is bigger (usually the main body, being the rest islands or foreign regions).

map.countryRegionHIghlightedIndex: returns the index of the region of currently highlighted country for the regions field of country object.

map.countryLastClickedIndex: returns the index of last country clicked.

map.enableCountryHighlight: set it to true to allow countries to be highlighted when mouse pass over them. 

map.fillColor: color for the highlight of countries.

map.showCountryNames: enables/disables country labeling on the map.

map.showOutline: draws a border around countries highlightes or colored.

map.outlineColor: color of the outline.

map.showFrontiers: show/hide country frontiers. Same than inspector property.

map.frontiersDetail: detail level for frontiers. Specify the frontiers catalog to be used.

map.frontiersColor: color for all frontiers.

map.frontiersThinLines: makes countries frontiers lines always thin irrespective of zoom level.

map.RenameCountry(oldName, newName): allows to change the country’s name. Use this method instead of changing the name field of the country object.

map.BlinkCountry(country, color1, color2, duration, speed): makes the country specified toggle between color1 and color2 for duration in seconds and at speed rate.

map.FlyToCountry(name): start navigation at navigationTime speed to specified country. The list of country names can be obtained through the cities property.

map.FlyToCountry(index): same but specifying the country index in the countries list.

map.GetCountryRegionZoomExtents(index): gets the required zoom level to show a custom country within screen borders.

map.ToggleCountrySurface(name, visible, color): colorize one country with color provided or hide its surface (if visible = false).

map.ToggleCountrySurface(index, visible, color): same but passing the index of the country instead of the name.

map.ToggleCountryMainRegionSurface(index, visible, color, Texture2D texture): colorize and apply an optional texture to the main region of a country.

map.ToggleCountryRegionSurface(countryIndex, regionIndex, visible, color): same but only affects one single region of the country (not province/state but geographic region).

map.HideCountrySurface(countryIndex): un-colorize / hide specified country.

map.HideCountryRegionSurface(countryIndex): un-colorize / hide specified region of a country (not province/state but geographic region).

map.HideCountrySurfaces: un-colorize / hide all colorized countries (cancels ToggleCountrySurface).

map.SetCountryRegionMaterial: manually sets the material used by a country region.

map.CountryNeighbours(countryIndex): returns the list of country neighbours.

map.CountryNeighboursOfMainRegion(countryIndex): same but taking into account only the main region of the province (just in case the province could have more than one land region).

map.CountryNeighboursOfCurrentRegion(): same but taking into account the currently highlighted province.

Province related

map.provinces: return a List<Province> of all provinces/states records.

map.provinceHighlighted: returns the province/state object in the provinces list under the mouse cursor (or null if none).

map.provinceHighlightedIndex: returns the province/state index in the provinces list under the mouse cursor (or null if none).

map.provinceRegionHighlighted: returns the highlighted region of the province/state (or null).

map.provinceRegionHighlightedIndex: returns the index of the region highlighted for the regions field of province object).

map.provinceLastClicked: returns the last province clicked by the user..

map.provinceRegionLastClicked: returns the last province’s region clicked by the user..

map.showProvinces: show/hide provinces when mouse enters a country. Same than inspector property.

map.enableProvinceHighlight: toggles province highlighting when mouse is over.

map.provincesFillColor: color for the highlight of provinces.

map.provincesColor: color for provinces/states color.

map.GetProvinceIndex(name): returns the index of the province in the array. Please note that there some provinces with same name. You may want to use GetProvinceIndex(country, name) instead.

map.GetProvinceIndex(country, name): returns the index of the province inside the province array of the country object.

map.GetProvinceIndex(localPosition): returns the province that contains a map coordinate.

map.GetProvinceNearToPoint(localPosition): returns the province that contains a map coordinate or the province whose center is nearest to the map coordinate.

map.GetProvinceNames(groupByCountry): returns an array with the province names, optionally grouped by country.

map.RenameProvince(oldName, newName): allows to change the province’s name. Use this method instead of changing the name field of the province object.

map.DrawProvinces(countryIndex, includeNeighbours, forceRefresh): draws borders of the provinces for the given country. Optionally can add the neighbouts province’s borders. This method is used internally – to show provinces and names for specific countries please check the code of “Show State Names” in demo scene 1.

map.HideProvinces(): hides the provinces borders.

map.BlinkProvince(province, color1, color2, duration, speed): makes the province specified toggle between color1 and color2 for duration in seconds and at speed rate.

map.FlyToProvince(name/index, duration, zoomLevel): start navigation to specified province, optionally passing a duration in seconds (navigationTime by default) and the desired final zoomLevel. The list of provinces names can be obtained through the provinces property.

map.ToggleProvinceSurface(name, visible, color): colorize one province with color provided or hide its surface (if visible = false).

map.ToggleProvinceSurface(index, visible, color): same but passing the index of the country instead of the name.

map.HideProvinceSurface(countryIndex): un-colorize / hide specified province.

map.SetProvinceRegionMaterial(provinceIndex): manually sets the material used by a province region.

map.HideProvinceSurfaces: un-colorize / hide all colorized provinces (cancels ToggleProvinceSurface).

map.ProvinceNeighbours(provinceIndex): returns the list of province neighbours.

map.ProvinceNeighboursOfMainRegion(provinceIndex): same but taking into account only the main region of the province (just in case the province could have more than one land region).

map.ProvinceNeighboursOfCurrentRegion(): same but taking into account the currently highlighted province.

Cities related

map.cities: return a List<City> of all cities records.

map.GetCityNames: return an array with the names of the cities.

map.cityHighlighted: returns the city under the mouse cursor (or null if none).

map.cityHighlightedIndex: returns the city index under the mouse cursor (or -1 if none).

map.lastCityClicked: returns the city clicked by the user.

map.showCities: show/hide all cities. Same than inspector property.

map.minPopulation: the mínimum population amount for a city to appear on the map (in thousands). Set to zero to show all cities in the current catalog. Range: 0 .. 17000.

map.cityClassAlwaysShow: combiantion of bitwise flags to specify classes of cities that will be drawn irrespective of other filters like minimum population. See CITY_CLASS_FILTER* constants.

map.citiesColor: color for the normal cities icons.

map.citiesRegionCapitalColor: color for the region capital cities icons.

map.citiesCountryCapitalColor: color for the country capital cities icons.

map.FlyToCity(name): start navigation at navigationTime speed to specified city. The list of city names can be obtained through the cities property.

map.FlyToCity(index): same but specifying the city index in the cities list.

map.cityHitTestRadius: specifies the radius multiplier for mouse selection of cities. Default value is 200.

Earth related

map.showEarth: show/hide the planet Earth. Same than inspector property.

map.earthStyle: the currently texture used in the Earth.

map.earthColor: the currently color used in the Earth when style = SolidColor.

map.showLatitudeLines: draw latitude lines.

map.latitudeStepping: separation in degrees between each latitude line.

map.showLongitudeLines: draw longitude lines.

map.longitudeStepping: number of longitude lines.

map.gridLinesColor: color of latitude and longitude lines.

User interaction

map.mouseIsOver: returns true if mouse has entered the Earth’s sphere collider.

map.navigationTime: time in seconds to fly to the destination (see FlyTo methods).

map.allowUserDrag/map.allowUserZoom: enables/disables user interaction with the map.

map.invertZoomDirection: controls the zoom in/out direction when using mouse wheel.

map.zoomMinDistance / map.zoomMaxDistance: limits the amount of zoom user can perform.

map.allowUserKeys/map.dragFlipDirection: enables/disables user drag with WASD keys and direction.

map.allowScrollOnScreenEdges: enables/disables autodisplacement of the map when mouse is positioned on the edges of the screen.

map.dragConstantSpeed: disables drag acceleration/damping.

map.zoomConstantSpeed: disables zoom acceleration/damping.

map.mouseWheelSensibility: multiplying factor for the zoom in/out functionality.

map.mouseDragSensibility: multiplying factor for the drag functionality.

map.showCursor: enables the cursor over the map.

map.cursorFollowMouse: makes the cursor follow the map.

map.cursorLocation: current location of cursor in local coordinates (by default the sphere is size (1,1,1) so x/y/z can be in (-0.5,0.5) interval. Can be set and the cursor will move to that coordinate.

map.fitWindowWidth: makes the map occupy the width of the screen.

map.fitWindowHeight: makes the map occupy also the height of the screen.

map.CenterMap(): positions the map in front of the main camera.

map.FlyToLocation (x, y, z): same but specifying the location in local Unity spherical coordinates.

Labels related

map.showCountryNames: toggles countriy labels on/off.

map.countryLabelsSize: this is the relative size for labels. Controls how much the label can grow to fit the country area.

map.countryLabelsAbsoluteMinimumSize: minimum absolute size for all labels.

map.labelsQuality: specify the quality of the label rendering (Low, Medium, High).

map.showLabelsShadow: toggles label shadowing on/off.

map.countryLabelsColor: color for the country labels. Supports alpha.

map.countryLabelsShadowColor: color for the shadow of country labels. Also supports alpha.

map.countryLabelsFont: Font for the country labels.

Mount Points related

map.mountPoints: return a List<MountPoint> of all mount points records.

map.GetMountPointNearPoint: returns the nearest mount point to a location on the sphere.

map.GetMountPoints: returns a list of mount points, optionally filtered by country and province.

Other

map.SetZoomLevel(level): apply one-time zoom level from 0 (closest) to 1 (farther).

map.ToggleContinentSurface(name, visible, color): colorize countries belonging to specified continent with color provided or hide its surface (if visible = false).

map.HideContinentSurface(name): uncolorize/hide countries belonging to the specified continent.

map.AddMarker(marker, planeLocation, markerScale): adds a custom marker (provided by you) to the map at plane location with specified scale (markerScale).

map.AddLine(start, end, color, elevation, drawingDuration, lineWidth, fadeAfter): adds an animated line to the map from start to end position and with color, elevation and other options.

map.calc: accesor to the Calculator component.

map.ticker: accesor to the Tickers component.

map.decorator: accesor to the Decorator component.

Back To Top