Skip to main content
Version: 6.0

Areas & Shapes

Using Mappedin SDK for Android with your own map requires a Pro license. Try a demo map for free or refer to the Pricing page for more information.

Areas

An Area represents a logical region on the map. They do not represent a physical attribute like a wall or desk, but rather a region that can be used to trigger events, display information, or affect wayfinding. An area is made up of a polygon stored as a GeoJSON Feature, which can be accessed using Area.geoJSON. The Feature can be passed to other methods in Mappedin SDKs.

tip

A complete example demonstrating Areas and Shapes can be found in the Mappedin Android Github repo: AreaShapesDemoActivity.kt

Shapes.add() accepts an FeatureCollection and can be used to display one or more areas on the map. The code snippet below demonstrates how to get an Area and create a Shape and add it to the map with a Label.

private fun loadAreasAndShapes() {
// Get current floor for zone avoidance
mapView.currentFloor { floorResult ->
floorResult.onSuccess { floor ->
currentFloor = floor

// Get all areas
mapView.mapData.getByType<Area>(MapDataType.AREA) { result ->
result.onSuccess { areas ->
// Find the Forklift Area
forkLiftArea = areas.find { it.name == "Forklift Area" }
forkLiftArea?.let { area ->
createShapeFromArea(
area,
"Maintenance Area",
"red",
0.7,
0.2,
0.1,
)
}

// Find the Maintenance Area
maintenanceArea = areas.find { it.name == "Maintenance Area" }
maintenanceArea?.let { area ->
createShapeFromArea(
area,
"Forklift Area",
"orange",
0.7,
0.2,
1.0,
)
}

// Get origin and destination for paths
setupPathEndpoints()
}
}
}
}
}

private fun createShapeFromArea(
area: Area,
labelText: String,
color: String,
opacity: Double,
altitude: Double,
height: Double,
) {
// Get the GeoJSON Feature from the area
val feature = area.geoJSON ?: return

// Create a FeatureCollection containing the single Feature
val featureCollection = FeatureCollection(features = listOf(feature))

// Draw the shape using the strongly-typed API
mapView.shapes.add(
featureCollection,
PaintStyle(color = color, opacity = opacity, altitude = altitude, height = height),
) {}

// Label the area
mapView.labels.add(area, labelText) {}
}

Within Mappedin Maker, it is possible to create an area and set it to be off limits for wayfinding. This means that the area will be excluded from the route calculation and directions will be rerouted around the area. This is useful for creating areas that are permanently off limits.

At runtime, it is also possible to use an area as an exclusion zone for wayfinding. This is useful for creating areas that are temporarily off limits. Below is a code snippet that demonstrates how to use an Area to define a region that a wayfinding route should avoid at runtime. Refer to the Dynamic Routing section of the Wayfinding Guide for an interactive example that demonstrates clicking to set an exclusion zone.

DirectionZone is the type of the GetDirectionsOptions.zones property that is passed to MapData.getDirections, MapData.getDirectionsMultiDestination() and MapData.getDistance(). These zones can be used to affect the route calculation by excluding a polygon from the route.

tip

A complete example demonstrating Areas and Shapes can be found in the Mappedin Android Github repo: AreaShapesDemoActivity.kt

The following code snippet demonstrates how to use an Area to define a region that a wayfinding route should avoid.

private fun drawPath(avoidZone: Boolean) {
// Remove existing paths
mapView.paths.removeAll()

val originTarget = origin
val destinationTarget = destination

if (originTarget == null || destinationTarget == null || maintenanceArea == null) {
return
}

// Create NavigationTargets
val from =
when (originTarget) {
is com.mappedin.models.MapObject -> NavigationTarget.MapObjectTarget(originTarget)
else -> return
}

val to =
when (destinationTarget) {
is com.mappedin.models.Door -> NavigationTarget.DoorTarget(destinationTarget)
else -> return
}

// Create zone for avoidance if needed
val options =
if (avoidZone && maintenanceArea?.geoJSON != null && currentFloor != null) {
val feature = maintenanceArea!!.geoJSON!!

if (feature.geometry != null) {
val zone =
DirectionZone(
cost = Double.MAX_VALUE,
floor = currentFloor,
geometry = feature,
)
GetDirectionsOptions(zones = listOf(zone))
} else {
null
}
} else {
null
}

// Get directions
mapView.mapData.getDirections(from, to, options) { result ->
result.onSuccess { directions ->
if (directions != null) {
android.util.Log.d("AreaShapes", "Got directions! Distance: ${directions.distance}m")
// Draw the path
val pathColor = if (avoidZone) "cornflowerblue" else "green"
mapView.paths.add(
directions.coordinates,
AddPathOptions(color = pathColor),
) {}
} else {
android.util.Log.w("AreaShapes", "getDirections returned null - no path found!")
}
}
result.onFailure { error ->
android.util.Log.e("AreaShapes", "getDirections failed: ${error.message}", error)
}
}
}

Shapes

The Shapes class draws 3 dimensional shapes on top of a map. The shapes are created using GeoJSON geometry, which could be a Polygon, MultiPolygon (array of polygons) or a LineString.

tip

Access the Shapes class through the MapView class using MapView.shapes.

Shapes are added by calling Shapes.add() and removed individually by calling Shapes.remove() and passing in the Shape object to be removed. All shapes can be removed at once by calling Shapes.removeAll().

The following code example adds a shape to the map.

mapView.shapes.add(
shapeGeometry,
PaintStyle(
color = "red",
altitude = 0.2,
height = 2.0,
opacity = 0.7,
),
) { result ->
result.onSuccess { createdShape ->
shape = createdShape
}
}