Loading & Saving Data
advanced scriptingWorld Map Globe Edition · Scripting Support (C#)
WorldMapGlobe (namespace WPM). Access via WorldMapGlobe.instance.
Geodata Format
GEODATA_FORMAT geodataFormat { get; set; }The geodata format: Packed (text-based, editable) or Binary (compact, faster loading).
string geodataResourcesPath { get; set; }Path within Resources where geodata files are stored.
Countries Data
string GetCountriesAttributes(bool prettyPrint = true)Returns all country custom attributes as JSON.
string GetCountriesAttributes(List<Country> countries, bool prettyPrint = true)Returns attributes for specific countries.
void SetCountriesAttributes(string jSON)Loads country attributes from a JSON string.
Coordinate Conversion
Static methods in the WPM.Conversion class for converting between coordinate systems:
Lat/Lon ↔ Sphere
static Vector3 GetSpherePointFromLatLon(float lat, float lon, float altitude = 0)Converts latitude/longitude to a sphere position. Also accepts Vector2 latLon or double precision.
static void GetLatLonFromSpherePoint(Vector3 p, out float lat, out float lon)Converts a sphere position to latitude/longitude. Also has overloads for out Vector2 latLon and out double.
static void GetLatLonFromSpherePoint(Vector3 p, out float lat, out float lon, out float altitude)Also returns the altitude (distance from the unit sphere surface).
UV Coordinates
static Vector2 GetUVFromLatLon(float lat, float lon)Converts lat/lon to UV texture coordinates (0-1 range).
static Vector2 GetUVFromSpherePoint(Vector3 p)Converts a sphere position to UV coordinates.
static Vector2 GetLatLonFromUV(Vector2 uv)Converts UV coordinates to lat/lon.
Distances & Tiles
static float Distance(float latDec1, float lonDec1, float latDec2, float lonDec2)Calculates the real-world distance in km between two lat/lon coordinates using the Haversine formula.
static float Distance(Vector3 position1, Vector3 position2)Calculates the real-world distance in km between two sphere positions.
static void GetTileFromLatLon(int zoomLevel, float lat, float lon, out int xtile, out int ytile)Gets tile coordinates for a lat/lon at a specific zoom level.
static Vector2 GetLatLonFromTile(float x, float y, int zoomLevel)Converts tile coordinates to lat/lon.
Texture Coordinates
static Vector2 ConvertToTextureCoordinates(Vector3 p, int width, int height)Converts a sphere position to pixel coordinates on a texture.
Code Example
using UnityEngine;
using WPM;
public class ConversionExample : MonoBehaviour {
void Start() {
// Madrid, Spain
float lat = 40.4168f, lon = -3.7038f;
// To sphere position
Vector3 spherePos = Conversion.GetSpherePointFromLatLon(lat, lon);
// Back to lat/lon
float lat2, lon2;
Conversion.GetLatLonFromSpherePoint(spherePos, out lat2, out lon2);
// Distance between two cities
float dist = Conversion.Distance(40.4168f, -3.7038f, // Madrid
48.8566f, 2.3522f); // Paris
Debug.Log($"Madrid to Paris: {dist:F0} km");
// Fly to the position
WorldMapGlobe.instance.FlyToLocation(spherePos, 2f, 0.3f);
}
}
Suggest an improvement
Help us improve this documentation page.