Skip to content

New Feature: Add API to draw a “direction cone” (sector shape) easily #2682

@tungnk123

Description

@tungnk123

Description

Currently, the Mapbox Maps SDK for Android does not provide a built-in way to render a direction cone (also known as a sector, view cone, or field-of-view arc).
Developers must manually compute latitude/longitude points along an arc and create a polygon to visualize a directional area — for example, a Qibla direction cone or camera field of view.

This requires repetitive math and custom logic:

  • Computing arc coordinates using spherical trigonometry
  • Handling wrap-around at 0°/360° and anti-meridian crossings
  • Creating polygons manually with PolygonAnnotation or FillLayer

Example use case

Visualizing directional areas such as:

  • Camera or compass “view cones”
  • Radar or sensor field of view
  • Qibla direction cone from a user’s location

Suggested solution

Add a lightweight helper API to easily draw a directional cone centered on a Point, given:

  • center: geographic point (latitude, longitude)
  • bearing: direction in degrees
  • halfAngle: cone spread in degrees
  • radius: distance in meters or kilometers
  • fillColor / fillOpacity: optional styling
Example usage
mapView.annotations.createDirectionCone(
    center = Point.fromLngLat(lon, lat),
    bearing = heading,
    halfAngle = 25.0,
    radius = 300000.0, // meters
    fillColor = Color.parseColor("#6600EEFF"),
    fillOpacity = 0.35
)

Expected behavior:

  • SDK internally computes and renders the cone polygon
  • Automatically handles projection and anti-meridian issues
  • Provides consistent results across zoom levels and map projections

Why

Drawing a simple fan-shaped area currently requires non-trivial math and boilerplate, which developers have to reimplement in every project.
A built-in API would:

  • Simplify rendering of directional indicators
  • Reduce code duplication across apps
  • Improve maintainability and readability
  • Enable new UX patterns (e.g., navigation view cones, AR guidance, Qibla direction indicators)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions