skip to Main Content

Additional Components

World Map Calculator

This component is useful to:

  • Convert units from one coordinate system to another (for instance from plane coordinates to degrees and viceversa).
  • Calculate the distance between cities.

You may also use this component to capture the current cursor coordinates and convert them to other coordinate system.

You may enable this component in two ways:

  • From the Editor, clicking on the “Open Calculator” button at the bottom of the World Map inspector.
  • From code, using any of its API through calc accessor. The first time you use its API, it will automatically add the component to the map gameObject.

On the Inspector you will see the following custom editor:

Using the converter from code

You may access the conversion API of this componet from code through map.calc property. The conversión task involves 3 steps:

  1. Specify the source unit (eg. “calc.fromUnit = UNIT_TYPE.DecimalDegrees”).
  2. Assign the source parameters (eg. “calc.fromLatDec = -15.281”)
  3. Call calc.Convert() method.
  4. Obtain the results from the fields calc.to* (eg. “map.calc.toLatDegrees”, “map.calc.toLatMinutes”, …).

Note that the conversion will provide results for decimal degrees, degrees and plane coordinates. You don’t have to specify the destination unit (that’s only for the inspector window, in the API the conversion is done for the 3 types).

To convert from Decimal Degrees to any other unit you use:

 

map.calc.fromUnit = UNIT_TYPE.DecimalDegrees

map.calc.fromLatDec = <decimal degree for latitude>

map.calc.fromLonDec = <decimal degree for longitude>

map.calc.Convert()

 

To convert from Degrees, you do:

 

map.calc.fromUnit = UNIT_TYPE.Degrees

map.calc.fromLatDegrees = <degree for latitude>

map.calc.fromLatMinutes = <minutes for latitude>

map.calc.fromLatSeconds = <seconds for latitude>

map.calc.fromLonDegrees = <degree for longitude>

map.calc.fromLonMinutes = <minutes for longitude >

map.calc.fromLonSeconds = <seconds for longitude >

map.calc.Convert()

 

And finally to convert from X, Y (normalized) you use:

 

map.calc.fromUnit = UNIT_TYPE.PlaneCoordinates

map.calc.fromX = <X position in local sphere coordinates >

map.calc.fromY = <Y position in local sphere coordinates >

map.calc.Convert()

 

The results will be stored in (you pick what you need):

 

map.calc.toLatDec = <decimal degree for latitude>

map.calc.toLonDec = <decimal degree for longitude>

map.calc.toLatDegrees = <degree for latitude>

map.calc.toLatMinutes = <minutes for latitude>

map.calc.toLatSeconds = <seconds for latitude>

map.calc.toLonDegrees = <degree for longitude>

map.calc.toLonMinutes = <minutes for longitude >

map.calc.toLonSeconds = <seconds for longitude >

map.calc.toX = <X position in local sphere coordinates >

map.calc.toY = <Y position in local sphere coordinates >

You may also use the property map.calc.captureCursor = true, and that will continuously convert the current coordinates of the cursor (mouse) until it’s set to false or you press the ‘C’ key.

Using the distance calculator from code

The component includes the following two APIs to calculate the distances in meters between two coordinates (latitude/longitude) or two cities of the current selected catalogue.

map.calc.Distance(float latDec1, float lonDec1, float latDec2, float lonDec2)

map.calc.Distance(City city1, City city2)

World Map Ticker Component

Use this component to show impact banners over the map. You can show different banners, each one with different look and effects. Also you can add any number of texts to any banner, and they will simply queue (if scrolling is enabled).

Similarly to the World Map Calculator component, you may enable this component in two ways:

  • From the Editor, clicking on the “Open Ticker” button at the bottom of the World Map inspector.
  • From code, using any of its API through ticker accessor. The first time you use its API, it will automatically add the component to the map gameObject.

On the Inspector you will see the following custom editor:

The top half of the inspector corresponds to the Ticker Bands configurator. You may customize the look&feel of the 9 available ticker bands (this number could be incremented if needed though). Notes:

  • Ticker bands are where the ticker texts (second half of the inspector) scrolls or appears.
  • A ticker band can be of two types: scrollable or static. You make a ticker band static setting its scroll speed to zero.
  • Auto-hide will make the ticker band invisible when there’re no remaining texts on the band.
  • The fade speed controls how quickly should the band appear/disappear. Set it to zero to disable the fade effect.

It’s important to note that everything you change on the inspector can be done using the API (more below).

In the second half of the inspector you can configure and create a sample ticker text. Notes:

  • Horizontal offset allows you to control the horizontal position of the text (0 equals to zero longitude, being the range -0.5 to 0.5).
  • Setting fade duration to zero will disable fading effect.
  • Setting blink interval to zero will disable blinking and setting repetitions to zero will make the text blink forever.

The API can be accessed through map.ticker property and exposes the following methods/fields:

map.ticker.NUM_TICKERS: number of available bands (slots).

map.ticker.overlayMode: when enabled, ticker texts will be displayed on top of everything at nearclip distance of main camera.

map.ticker.tickerBands: array with the ticker bands objects. Modifying any of its properties has effect immediately.

map.ticker.GetTickerTextCount(): returns the number of ticker texts currently on the scene. When a ticker text scrolls outside the ticker band it’s removed so it helps to determine if the ticker bands are empty.

map.ticker.GetTickerTextCount(tickerBandIndex): same but for one specific ticker band.

map.ticker.GetTickerBandsActiveCount(): returns the number of active (visible) ticker bands.

map.ticker.ResetTickerBands(): will reset all ticker bands to their default values and removes any ticker text they contain.

map.ticker.ResetTickerBand(tickerBandIndex): same but for an specific ticker band.

map.ticker.AddTickerText(tickerText object): adds one ticker text object to a ticker band. The ticker text object contains all the neccesary information.

The demo.cs script used in the Demo scene contains the following code showing how to use the API:

// Sample code to show how tickers work
void TickerSample() {
    map.ticker.ResetTickerBands();

    // Configure 1st ticker band: a red band in the northern hemisphere
    TickerBand tickerBand = map.ticker.tickerBands[0];
    tickerBand.verticalOffset = 0.2f;
    tickerBand.backgroundColor = new Color(1,0,0,0.9f);
    tickerBand.scrollSpeed = 0;    // static band
    tickerBand.visible = true;
    tickerBand.autoHide = true;

    // Prepare a static, blinking, text for the red band
    TickerText tickerText = new TickerText(0, "WARNING!!");
    tickerText.textColor = Color.yellow;
    tickerText.blinkInterval = 0.2f;
    tickerText.horizontalOffset = 0.1f;
    tickerText.duration = 10.0f;

    // Draw it!
    map.ticker.AddTickerText(tickerText);

    // Configure second ticker band (below the red band)
    tickerBand = map.ticker.tickerBands[1];
    tickerBand.verticalOffset = 0.1f;
    tickerBand.verticalSize = 0.05f;
    tickerBand.backgroundColor = new Color(0,0,1,0.9f);
    tickerBand.visible = true;
    tickerBand.autoHide = true;

    // Prepare a ticker text
    tickerText = new TickerText(1, "INCOMING MISSLE!!");
    tickerText.textColor = Color.white;

    // Draw it!
    map.ticker.AddTickerText(tickerText);
}

World Map Decorator

This component is used to decorate parts of the map. Current decorator version supports:

  • Customizing the label of a country
  • Colorize a country with a custom color
  • Assign a texture to a country, with scale, offset and rotation options.

You may use this component in two ways:

  • From the Editor, clicking on the “Open Decorator” button at the bottom of the World Map inspector.
  • From code, using any of its API through decorator accessor. The first time you use its API, it will automatically add the component to the map gameObject.

The API of this component has several methods but the most important are:

map.decorator.SetCountryDecorator(int groupIndex, string countryName, CountryDecorator decorator)

This will assign a decorator to specified country. Decorators are objects that contains customization options and belong to one of the existing groups. This way you can enable/disable a group and all decorators of that group will be enabled/disabled at once (for instance, you may group several countries in the same group).

map.decorator.RemoveCountryDecorator(int groupIndex, string countryName)

This method will remove a decorator from the group and its effects will be removed.

A decorator object has the following fields:

  • countryName: the name of the country to be decorated. It will be assigned automatically when using SetCountryDecorator method.
  • customLabel: leave it as “” to preserve current country label.
  • isColorized: if the country is colorized.
  • fillColor: the colorizing color.
  • labelOverridesColor: if the color of the label is specified.
  • labelColor: the color of the label.
  • labelVisible: if the label is visible (default = true);
  • labelOffset: horizontal and vertical position offset of the label relative to the center of the country.
  • labelRotation: rotation of the label in degrees.
  • texture: the texture to assign to the country.
  • textureScale, textureOffset and textureRotation allows to tweak how the texture is mapped to the surface.

World Map Editor Component

Use this component to modify the provided maps interactively from Unity Editor (it doesn’t work in play mode). To open the Map Editor, click on the “Open Editor” button at the bottom of the World Map inspector.

On the Inspector you will see the following custom editor:

Description:

 

  • Show Layers: choose whether to visualize countries or countries + provinces.hich layer to modify.
  • Country File: choose which file to edit:
    • Low-definition geodata file (110m:1 scale)
    • High-definition geodata file (30m:1 scale)
  • City File: choose which file to edit. Please note that changes in one file don’t propagate to the other:
    • Principal city catalogue
    • Principal + medium sized cities catalogue
  • Country: the currently selected country. You can change its name or “sell” it to another country clicking on transfer.
  • Province/State: the currently selected province/state if provinces are visible (see Show Layers above). As with countries, you can change the province’s name ore ven transfer it ot another country.
  • City: the currently selected city.

Main toolbar

  • Select: allows you to select any country, province or city in the Scene view. Just click over the map!
  • Reshape: once you have either a country, province or city selected, you can apply modifications. These modifications are located under the Reshape mode (see below).
  • Create: enable the creation of cities, provinces or countries.
  • Revert: will discard changes and reload data from current files (in Resources/Geodata folder).
  • Save: will save changes to files in Resources/Geodata foler.

If you click the gear icon on the inspector title bar, you will see 2 additional options:

  • Restore Backup: the first time you save changes to disk, a backup of the original geodata files will be performed. The backed up files are located in Backup folder inside the main asset folder. You may manually replace the contents of the Resources/Geodata folder by the Backup contents manually as well. This option do that for you.
  • Create Low Definition Geodata File: this option is only available when the high-definition geodata file is active. It will automatically create a simplistic and reduced version (in terms of points) and replace the low-definition geodata file. This is useful only if you use the high-definition geodata file. If you only use the low-definition geodata file, then you may just change this map alone.

Reshaping options

When you select a country, the Reshape main option will show the following tools:

  • Point tool: will allow you to move one point at a time. Note that the corresponding point of the neighbour will also be moved along (if it exits). This way the frontier between two regions is easily modified in one step, avoiding gaps between adjacent regions.
  • Circle tool: similar to the point tool but affects all points inside a circle. The width of the circle can be changed in the inspector. Note that points nearer to the center of the circle will move faster than the farther ones unless you check the “Constant Move” option below.
  • SplitV: will split vertically the country or region. The splitted region will form a new country/province with name “New X” (X = original country name)
  • SplitH: same but horizontally.
  • Magnet: this useful works by clicking repeatedly over a group of points that belong to different regions. It will try to make them to join fixing the frontier. Note that there must be a sufficient number of free points so they can be fused. You can toggle on the option “Agressive Mode” which will move all points in the circle to the nearest points of other region and also will remove duplicates.
  • Smooth: will create new points around the border of the selected region.
  • Erase: will remove the points inside the selection circle.
  • Delete: will delete selected region or if there’re no more regiosn in the current country or province, this will remove the entity completely (it disappear from the country /province array).

Create options

In “Create mode” you can add new cities, provinces or countries to the map:

Note that a country is comprissed of one or more regions. Many countries have only one region, but those with islands or colonies have more than one. So you can add new regions to the selected country or create a new country. When you create a new country, the editor automatically creates the first / main region.

Also note that the main region of a country is the biggest one in terms of euclidean area.

Provinces have also regions, and can have more than one.

Map Editor Tips

 

  • Before start making changes, determine if you need the high-definition file or not. If you don’t need it for your project, then you can just work with the low-definition file. Note that the high-def and low-def files are different. That means that changes to one file will not affect the other. This may duplicate your job, so it’s important to decide if you want to modify both maps or only the low-def map.
  • The high-definition file has lots of points. Current operation in this mode on some big countries (like Russia or Antartica) can be quite slow on some machines (although functional).
  • You may change temporarily the scale of the map gameobject to 2000,1000,1 to make easier both the zoom and selection operations.
  • If you decide to modify the high-definition file, you should complete all your modifications first in this map. Then use the command “Create Low Definition Geodata File” from the gear command, and adjust the low-def map afterwards.
  • If you make any mistake using the Point/Circle tool, you can Undo (Control/Command + Z or Undo command from the Edit menu).
  • Alternatively you can use the Revert option and this will reload the geodata files from disk (changes in memory wiil be lost).
  • If you modified the geodata files in Resources/Geodata and want to recover original files, you can use the Restore Backup command from the gear icon, or manually replace the Resourcess/Geodata files with those in the Backup folder.
  • As a last resort you may replace currnet files with the originals in the asset .unitypackage.
  • Remember to visit us at kronnect.com for help and new updates.

World Flags and Weather Symbols

This package is available as a separate purchase and includes +270 vector and raster images of country flags and weather symbols:

For more information, please consult the Asset Store page:

https://www.assetstore.unity3d.com/#!/content/69010

Once imported into the project, the names of the flag texture files equal to the country names used in our map assets so you can add flag icons or texture countries with their flag with minimal effort.

 

The code to texture the country surface with its flag would be:

// Get reference to the API

WorldMap2D map = WorldMap2D.instance;




// Choose a country

string countryName = “China”;




// Load texture for the country

Texture2D flagTexture = Resources.Load<Texture2D> ("Flags/png/" + countryName);




// Apply texture to the country main region (ignore islands)

int countryIndex = map.GetCountryIndex(countryName);

map.ToggleCountryMainRegionSurface(countryIndex, true, flagTexture);
Back To Top