Skip to main content
Version: 1.8.3.X

Route Events

Route events let you respond when a route is saved or deleted. Each callback receives two positional strings, (routeId, routeName), not a CustomRoute object or a selection feature.

The examples use the control obtained in Registering for Map Events. For supported route operations and their authentication, scope and permission requirements, see the Routing API reference. For map-panel steps, see Routing.

Save and delete lifecycle​

ActionEvents, in order
First database persistenceRouteCreated -> RouteSaved
Persistence of an existing database route, including an explicit save with no changed fieldsRouteUpdated -> RouteSaved
Share/unshare that persists the routeCreated or Updated, then Saved, according to database existence
Delete a persisted route, an unsaved draft or a locally loaded route whose database record is already absentRouteDeleted, after delete-if-present and local removal
Failed save/readback or deletion; missing-local or repeated deletionNo success event
Draft creation/edits, cancelled dialogs, loading/reloading, selection, recalculation or revert aloneNone of these completion events

Database existence determines Created versus Updated, not the local dirty/saved flags. Each successful persistence operation emits one Created or Updated event followed by Saved. Separate explicit saves are separate operations. Listen to RouteSaved alone when you want one notification per save; subscribing to both Created/Updated and Saved intentionally gives two callbacks for that operation.

These events cover Save Route in the UI, routes persisted during a host record save, public addOrUpdateRoute() calls and share/unshare persistence. Host record saves only persist routes with outstanding dirty changes; saving the host does not emit a route event for every clean route. There is no dedicated share or recalculate event. Removing a shared route code from your list is not deleting the route.

Save timing and pending edits​

Save callbacks run after the successful database write, post-save read and local reconciliation. They do not certify provider calculation or completion of rendering/selection. For example, addOrUpdateRoute() performs recalculation after saving, so its save callbacks can run before the API promise completes.

The callback ID and name describe the submitted save snapshot. Newer edits made while that save was pending are retained locally and can still be dirty when the callback runs. Consequently, getRoutes() can show a newer name than the callback's routeName. A save notification is not a guarantee that every current local edit has been persisted.

A rejected write, rejected post-save read or missing readback result emits no success callback and does not mark the local route saved for that operation. A write can already have committed before readback fails: do not infer that no database change occurred. A later retry is classified from the database's current state.

These events are separate from FeatureSelected / FeaturesSelected, which carry Feature / Feature[] selection payloads, and shape SavingCompleted. Selection and shape-saving notifications are not route-save completion or waypoint-role round-trip checks.

RouteCreated​

Fires after a route is successfully persisted as a new database record, immediately before RouteSaved. Creating or editing an unsaved draft alone does not trigger it.

Parameters:

  • routeId (string): The ID of the route submitted for persistence.
  • routeName (string): The submitted route name, or '' for an unnamed route.

Usage:

const onRouteCreated = (routeId, routeName) => {
console.log('First route persistence:', routeId, routeName);
};

control.on('RouteCreated', onRouteCreated);

RouteUpdated​

Fires after an existing database route is successfully persisted, immediately before RouteSaved. Local edits alone do not trigger it; a successful explicit save with unchanged fields does.

Parameters:

  • routeId (string): The ID of the route submitted for persistence.
  • routeName (string): The submitted route name, or '' for an unnamed route.

Usage:

const onRouteUpdated = (routeId, routeName) => {
console.log('Existing route persisted:', routeId, routeName);
};

control.on('RouteUpdated', onRouteUpdated);

RouteSaved​

Fires after each successful persistence operation, immediately after RouteCreated or RouteUpdated. Use this event for one notification per route save across the entry points above.

Parameters:

  • routeId (string): The ID of the route submitted for persistence.
  • routeName (string): The submitted route name, or '' for an unnamed route.

Usage:

const onRouteSaved = (routeId, routeName) => {
console.log('Route save completed:', routeId, routeName);
};

control.on('RouteSaved', onRouteSaved);

Do not unconditionally save the same route inside its save listener: that save triggers another notification.

RouteDeleted​

Fires after delete-if-present succeeds and the route is removed from the local collection. It also covers deleting an unsaved draft or removing a locally loaded route whose database record is already absent.

Parameters:

  • routeId (string): The deleted route's last local ID.
  • routeName (string): Its last local name captured before deletion, or '' for an unnamed route.

The route is no longer returned by getRoutes() when this callback runs. A failed deletion retains the local route and emits no deletion callback. A missing-local route or repeated deletion does not emit another callback.

Usage:

const onRouteDeleted = (routeId, routeName) => {
console.log('Route removed:', routeId, routeName);
};

control.on('RouteDeleted', onRouteDeleted);

API save example​

On an authenticated, authorised map, this example uses a disposable personal route and a fixed ID for both calls. With the listeners above registered, first persistence emits Created then Saved; the second call with the same fields emits Updated then Saved. The callbacks still receive only ID/name, not the waypoint list.

const routeId = globalThis.crypto.randomUUID();
const route = {
routeId,
routeName: 'Route event example',
scope: 'MyRoute',
waypoints: [
{ name: 'Depot', lng: 115.9086, lat: -31.9753, waypointType: 'source' },
{ name: 'Visit', lng: 115.83754, lat: -32.11547, waypointType: 'destination' },
],
};

await control.addOrUpdateRoute(route);
await control.addOrUpdateRoute(route);

Each API call replaces the full public waypoint list; internal waypoint IDs and other unexposed properties do not round-trip. This is not a claim that a public read/write is a lossless internal no-op.

Removing listeners​

Pass the same function references used when registering:

control.off('RouteCreated', onRouteCreated);
control.off('RouteUpdated', onRouteUpdated);
control.off('RouteSaved', onRouteSaved);
control.off('RouteDeleted', onRouteDeleted);

control.off(eventName) removes all listeners for that event on this control, not just yours. Avoid repeated registration or your listener can run more than once per event.