Skip to main content

Display paths

|

Paths can be displayed by adding them into MapViewPathCollection. The MapViewPathCollection is an iterable collection, having fields like size, add, remove, removeAt, getPathAt and getPathByName.

mapView.preferences?.paths?.add(path)

The add method of MapViewPathCollection includes optional parameters for customizing the appearance of paths on the map, such as border, fill, szBorder, and szInner. To center the map on a path, use the MapView.centerOnArea() method with the path's area retrieved from the area property.

mapView.preferences?.paths?.add(
path,
border = Rgba.black(),
fill = Rgba.orange(),
szBorder = 0.5,
szInner = 1.0
)

path.area?.let { mapView.centerOnArea(it) }
Path displayed

Convenience methods

The MapView class provides convenient methods for displaying and managing paths:

Display paths

// Display a single path
mapView.displayPath(path, border = Rgba.black(), fill = Rgba.orange())

// Display multiple paths
mapView.displayPaths(pathsList, border = Rgba.black(), fill = Rgba.orange())

Present a path with centering

// Present a path and automatically center the map on it
mapView.presentPath(
path = path,
border = Rgba.black(),
fill = Rgba.orange(),
doCenterOn = true,
animation = Animation(EAnimation.Linear, 1000),
zoomLevel = -1 // Automatic zoom level selection
)

Remove paths

// Hide a specific path
mapView.hidePath(path)

// Remove all paths from the map
mapView.preferences?.paths?.clear()

// Remove a specific path from the collection
mapView.preferences?.paths?.remove(path)

// Remove a path by index
mapView.preferences?.paths?.removeAt(index)

Working with path collections

SdkCall.execute {
mapView.preferences?.paths?.let { pathCollection ->
// Add a path with custom appearance
pathCollection.add(
path,
border = Rgba(255, 0, 0, 255), // Red border
fill = Rgba(0, 255, 0, 255), // Green fill
szBorder = 1.0, // Border size in mm
szInner = 2.0 // Inner size in mm
)

// Get collection size
val pathCount = pathCollection.size

// Get a path by index
val firstPath = pathCollection.getPathAt(0)

// Get a path by name
val namedPath = pathCollection.getPathByName("My Path")

// Get path colors and sizes
val borderColor = pathCollection.getBorderColorAt(0)
val fillColor = pathCollection.getFillColorAt(0)
val borderSize = pathCollection.getBorderSizeAt(0)
val innerSize = pathCollection.getInnerSizeAt(0)
}
}

Creating paths from GPX data

SdkCall.execute {
// Load a path from GPX file in assets
val input = applicationContext.resources.assets.open("gpx/route.gpx")
val path = Path.produceWithGpx(input)

path?.let {
// Display the path on the map
mapView.presentPath(it, border = Rgba.blue(), fill = Rgba.cyan())
}
}

To remove all paths from the map use MapViewPathCollection.clear(). To remove selectively, use MapViewPathCollection.remove(path) or MapViewPathCollection.removeAt(index).