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:
flexpolyline.decode(polyline)→ipyleaflet.Polyline(locations=...)ipyleaflet.Map/Marker/GeoJSONandMap.add/Map.removeGeoJSON.on_click(...)carrying the detour annotation in the feature propertiesa green
at → resultleg and a purpleresult → stopleg, 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/routesendpoint.- Parameters:
session (
ClientSession) – instance of HTTPSessionorigin – route origin, a
Waypointor a(lat, lon[, name_hint])tupledestination – 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 instancetransportModeoptionreturn_fields (
Sequence[str] |None) – overrides the instancereturnoptionspans (
Sequence[str] |None) – overrides the instancespansoptionx_headers (
dict|None) – Optional X-* headers (X-Request-Id, …)kwargs – additional request URL parameters
- Return type:
Response- Returns:
a Response object whose
datais 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 → resultandresult → stoplegs must therefore group these sections withsplit_at()andmerge_sections()rather than assume one section per leg.- Parameters:
response (
Response) – aResponsereturned byroutes()route_index (
int) – index in theroutes[]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
ActionIntentinstances toqueueso 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
ActionIntentto 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