Overview
Open Mobile Maps uses coordinate objects to represent positions, rectangles, and polygons in various coordinate systems. Understanding these types is essential for working with map positioning and geometry.
Coord
Represents a single point in a specific coordinate system.
Constructor
Coord(
systemIdentifier: CoordinateSystemIdentifier,
x: Double,
y: Double,
z: Double
)
systemIdentifier
CoordinateSystemIdentifier
required
The coordinate system identifier (e.g., EPSG 4326, EPSG 3857)
The x-coordinate (longitude in geographic systems)
The y-coordinate (latitude in geographic systems)
The z-coordinate (elevation/height, typically 0.0)
Examples
EPSG 4326 (WGS84 - Latitude/Longitude):
val coordinate = Coord(
CoordinateSystemIdentifiers.EPSG4326(),
8.378232525377973, // longitude
46.962592372639634, // latitude
0.0 // elevation
)
EPSG 3857 (Web Mercator):
val coordinate = Coord(
CoordinateSystemIdentifiers.EPSG3857(),
932445.23, // x in meters
5879564.87, // y in meters
0.0
)
RectCoord
Represents a rectangular area defined by two corner coordinates.
Constructor
RectCoord(
topLeft: Coord,
bottomRight: Coord
)
The top-left corner coordinate
The bottom-right corner coordinate
Example
val epsg3857Bounds = RectCoord(
Coord(
CoordinateSystemIdentifiers.EPSG3857(),
-20037508.34, // left
20037508.34, // top
0.0
),
Coord(
CoordinateSystemIdentifiers.EPSG3857(),
20037508.34, // right
-20037508.34, // bottom
0.0
)
)
Both coordinates in a RectCoord must use the same coordinate system.
PolygonCoord
Represents a polygon with an outer boundary and optional holes.
Constructor
PolygonCoord(
positions: List<Coord>,
holes: List<List<Coord>>
)
List of coordinates defining the outer boundary of the polygon
holes
List<List<Coord>>
required
List of coordinate lists, each defining a hole in the polygon
Example
Simple Polygon (No Holes):
val polygonCoord = PolygonCoord(
positions = listOf(
Coord(CoordinateSystemIdentifiers.EPSG4326(), 8.0, 47.0, 0.0),
Coord(CoordinateSystemIdentifiers.EPSG4326(), 9.0, 47.0, 0.0),
Coord(CoordinateSystemIdentifiers.EPSG4326(), 9.0, 46.0, 0.0),
Coord(CoordinateSystemIdentifiers.EPSG4326(), 8.0, 46.0, 0.0),
Coord(CoordinateSystemIdentifiers.EPSG4326(), 8.0, 47.0, 0.0) // Close the polygon
),
holes = emptyList()
)
Polygon with Hole:
val polygonWithHole = PolygonCoord(
positions = listOf(
// Outer boundary
Coord(CoordinateSystemIdentifiers.EPSG4326(), 8.0, 47.0, 0.0),
Coord(CoordinateSystemIdentifiers.EPSG4326(), 9.0, 47.0, 0.0),
Coord(CoordinateSystemIdentifiers.EPSG4326(), 9.0, 46.0, 0.0),
Coord(CoordinateSystemIdentifiers.EPSG4326(), 8.0, 46.0, 0.0),
Coord(CoordinateSystemIdentifiers.EPSG4326(), 8.0, 47.0, 0.0)
),
holes = listOf(
// Hole
listOf(
Coord(CoordinateSystemIdentifiers.EPSG4326(), 8.3, 46.7, 0.0),
Coord(CoordinateSystemIdentifiers.EPSG4326(), 8.7, 46.7, 0.0),
Coord(CoordinateSystemIdentifiers.EPSG4326(), 8.7, 46.3, 0.0),
Coord(CoordinateSystemIdentifiers.EPSG4326(), 8.3, 46.3, 0.0),
Coord(CoordinateSystemIdentifiers.EPSG4326(), 8.3, 46.7, 0.0)
)
)
)
Coordinate System Identifiers
CoordinateSystemIdentifiers
Provides standard coordinate system identifiers.
EPSG 4326 (WGS84):
CoordinateSystemIdentifiers.EPSG4326()
Standard latitude/longitude coordinates used by GPS.
EPSG 3857 (Web Mercator):
CoordinateSystemIdentifiers.EPSG3857()
Projected coordinate system used by most web mapping services (Google Maps, OpenStreetMap).
CoordinateSystemFactory
Creates coordinate system objects for use in MapConfig.
val coordinateSystem = CoordinateSystemFactory.getEpsg3857System()
Example in MapView setup:
mapView.setupMap(MapConfig(CoordinateSystemFactory.getEpsg3857System()))
Usage in Layers
Icon Layer
val icon = IconFactory.createIcon(
identifier = "marker",
coordinate = Coord(
CoordinateSystemIdentifiers.EPSG4326(),
8.378232,
46.962592,
0.0
),
texture = texture,
iconSize = Vec2F(32.0f, 32.0f),
scaleType = IconType.INVARIANT,
blendMode = BlendMode.NORMAL
)
Polygon Layer
val polygon = PolygonInfo(
identifier = "area",
coordinates = PolygonCoord(
positions = listOf(/* coords */),
holes = listOf(/* hole coords */)
),
color = Color(1.0f, 0.0f, 0.0f, 0.5f),
highlightColor = Color(1.0f, 0.4f, 0.4f, 0.7f)
)
Line Layer
val line = LineFactory.createLine(
identifier = "route",
coordinates = listOf(
Coord(CoordinateSystemIdentifiers.EPSG4326(), 8.0, 47.0, 0.0),
Coord(CoordinateSystemIdentifiers.EPSG4326(), 9.0, 47.0, 0.0),
Coord(CoordinateSystemIdentifiers.EPSG4326(), 9.0, 46.0, 0.0)
),
style = lineStyle
)