RouteController¶
Quick reference¶
This notebook focuses on rendering detours: the ipyleaflet adapter around the route
model, the reranked result overlays and the detour legs. Most-used elements:
ResponseMap(credentials, center=..., zoom=...)and itsrouteattributeRouteController.set_route_start/set_route_stop/set_route_width(...)RouteController.draw_detour_routes(...)/clear_detour_routes()ResponseMap.display(resp, fit=True)SearchState.hydrate(resp)/SearchState.title_for(rank)ResponseMap.click_result(rank)
For the complete reference, see the API reference. For the layering rationale, see Route engine and widget controller architecture.
Methods used in this notebook¶
- 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
- 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.
- on_drawn(callback)
Register callback to be called each time a route is fully drawn.
The callback receives this
RouteControllerinstance so it can inspectflexpolyline,waypoints_count,start_position, etc. Multiple callbacks may be registered; they are called in registration order.Example:
def my_handler(route): print(f"Route ready: {route.waypoints_count} waypoints") controller.on_drawn(my_handler)
- Return type:
None
- on_removed(callback)
Register callback to be called when a route is removed.
- Return type:
None
- set_current_position(latlon=None)
Set the current car position on the route.
- Parameters:
latlon (
tuple[float,float] |None) –(lat, lon)current position.
- set_route_start(latlon)
Set the route origin marker and trigger route acquisition when complete.
- Parameters:
latlon (
tuple[float,float]) –(lat, lon)origin position.
- set_route_stop(latlon)
Set the route destination marker and trigger route acquisition when complete.
- Parameters:
latlon (
tuple[float,float]) –(lat, lon)destination position.
- set_route_width(width)
Set corridor width (meters) used for route geometry and rerender it.
- Parameters:
width (
int|None) – Corridor width in meters;Nonekeeps/defaults width.
- class here_search_demo.widgets.state.SearchState
Widget-local search view state.
This object keeps presentation-oriented data that helps widgets render the current response and preserve UI interactions between updates.