Skip to main content
Version: 6.0

Areas & Shapes

Using Mappedin SDK for iOS 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 iOS Github repo: AreaShapesDemoViewController.swift

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 func loadAreasAndShapes() {
// Get current floor for zone avoidance
mapView.currentFloor { [weak self] result in
guard let self = self else { return }
if case .success(let floor) = result {
self.currentFloor = floor

// Get all areas
self.mapView.mapData.getByType(.area) { [weak self] (result: Result<[Area], Error>) in
guard let self = self else { return }
if case .success(let areas) = result {
// Find the Forklift Area
self.forkLiftArea = areas.first { $0.name == "Forklift Area" }
if let area = self.forkLiftArea {
self.createShapeFromArea(
area: area,
labelText: "Maintenance Area",
color: "red",
opacity: 0.7,
altitude: 0.2,
height: 0.1
)
}

// Find the Maintenance Area
self.maintenanceArea = areas.first { $0.name == "Maintenance Area" }
if let area = self.maintenanceArea {
self.createShapeFromArea(
area: area,
labelText: "Forklift Area",
color: "orange",
opacity: 0.7,
altitude: 0.2,
height: 1.0
)
}

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

private func createShapeFromArea(area: Area, labelText: String, color: String, opacity: Double, altitude: Double, height: Double) {
// Get the GeoJSON Feature from the area
guard let feature = area.geoJSON else { return }

// Create a FeatureCollection containing the single Feature
let featureCollection = FeatureCollection(features: [feature])

// Draw the shape using the typed API
mapView.shapes.add(
geometry: featureCollection,
style: PaintStyle(color: color, altitude: altitude, height: height, opacity: opacity)
) { _ in }

// Label the area
mapView.labels.add(target: area, text: labelText) { _ in }
}

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 iOS Github repo: AreaShapesDemoViewController.swift

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

private func drawPath(avoidZone: Bool) {
// Remove existing paths
mapView.paths.removeAll()

guard let origin = origin,
let destination = destination,
let maintenanceArea = maintenanceArea else {
return
}

// Create NavigationTargets
let from = NavigationTarget.mapObject(origin)
let to = NavigationTarget.door(destination)

// Create zone for avoidance if needed
var options: GetDirectionsOptions?
if avoidZone, let feature = maintenanceArea.geoJSON, let currentFloor = currentFloor {
let zone = DirectionZone(
cost: Double.greatestFiniteMagnitude,
floor: currentFloor,
geometry: feature
)
options = GetDirectionsOptions(zones: [zone])
}

// Get directions
mapView.mapData.getDirections(from: from, to: to, options: options) { [weak self] result in
guard let self = self else { return }
if case .success(let directions) = result, let directions = directions {
// Draw the path
let pathColor = avoidZone ? "cornflowerblue" : "green"
self.mapView.paths.add(
coordinates: directions.coordinates,
options: AddPathOptions(color: pathColor)
) { _ in }
}
}
}

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(
geometry: shapeGeometry,
style: PaintStyle(
color: "red",
altitude: 0.2,
height: 2.0,
opacity: 0.7
)
) { [weak self] result in
if case .success(let createdShape) = result {
shape = createdShape
}
}