Detours rendering

Quick reference

This notebook draws routes and detours with plain ipyleaflet objects instead of the demo ResponseMap/RouteController pair, to show how the feature plugs into an existing map. Most-used elements:

  1. flexpolyline.decode(polyline) → ipyleaflet.Polyline(locations=...)

  2. ipyleaflet.Map / Marker / GeoJSON and Map.add / Map.remove

  3. GeoJSON.on_click(...) carrying the detour annotation in the feature properties

  4. a green at → result leg and a purple result → stop leg, drawn from the cached polylines returned by the reranking — no extra Routing API call

For the high-level equivalent, see the page about Detour Map. For the complete reference, see the API reference.

Methods used in this notebook

class here_search_demo.routing_api.RoutingAPI(credentials=None, cache=None, raise_for_status=True, options=None, log_fn=None, on_request_sent=None)

https://www.here.com/docs/bundle/routing-api-v8-api-reference/page/index.html

async routes(session, origin, destination, via=None, transport_mode=None, return_fields=None, spans=None, x_headers=None, **kwargs)

Calls the HERE Routing /v8/routes endpoint.

Parameters:
  • session (ClientSession) – instance of HTTPSession

  • origin – route origin, a Waypoint or a (lat, lon[, name_hint]) tuple

  • destination – route destination, in the same formats as origin

  • via – optional intermediate waypoint(s), in the same formats as origin

  • transport_mode (str | None) – overrides the instance transportMode option

  • return_fields (Sequence[str] | None) – overrides the instance return option

  • spans (Sequence[str] | None) – overrides the instance spans option

  • x_headers (dict | None) – Optional X-* headers (X-Request-Id, …)

  • kwargs – additional request URL parameters

Return type:

Response

Returns:

a Response object whose data is the routing payload

static sections(response, route_index=0)

Return the sections of one route of a routing response.

The Routing API starts a new section at each via waypoint and wherever the journey changes transport mode – a Berlin/London route is split by the channel ferry, for instance. Callers that need the at → result and result → stop legs must therefore group these sections with split_at() and merge_sections() rather than assume one section per leg.

Parameters:
  • response (Response) – a Response returned by routes()

  • route_index (int) – index in the routes[] array

Return type:

list[RouteSection]

Returns:

list of RouteSection

class here_search_demo.widgets.route.RouteController(map_instance, credentials, routing_api_call_handler=None)

Route acquisition and rendering controller for map widgets.

The controller fetches route geometry, renders route overlays/markers, and exposes helpers used by notebooks and UI callbacks to update route start/stop/at positions and corridor width.

Parameters:
  • map_instance (PositionMap) – Map widget receiving route layers.

  • credentials (Credentials) – HERE credentials used for routing requests.

clear_detour_routes()

Remove any rendered detour overlays without touching the route.

draw_detour_routes(route_from, route_to)

Render a green polyline from current_position → result and a purple one from result → stop_position, replacing any previously shown detour routes.

class here_search_demo.widgets.output_map.ResponseMap(queue=None, state=None, search_center_handler=None, tile_opacity=0.6, **kwargs)

Map widget used to render search responses and selection actions.

The map displays results as GeoJSON markers, optionally adds extra labels (fuel prices / TripAdvisor), and can fit bounds to returned items. It is also interactive: marker clicks push ActionIntent instances to queue so upper layers can retrieve details or trigger detour logic.

Parameters:
  • queue (Queue | None) – Queue used for emitted intents from map interactions.

  • state (SearchState | None) – Shared state containing ranked response items.

  • search_center_handler (Callable[[tuple[float, float]], None]) – Callback invoked when the map center changes.

  • tile_opacity (float) – Base map tile opacity.

  • kwargs – Forwarded to PositionMap.

click_result(rank, *, emit_action=True, recenter=True, show_details=True)

Programmatically simulate a map click on the result at rank.

This pushes an ActionIntent to the queue and, when travel-time mode is active, draws the detour route for the clicked result.

Example:

app.map_w.click_result(6)
Return type:

None