This is the documentation of version 1.0.0-rc.4. Go to the latest version, 1.0.0-rc.5.
TomTom Maps for JavaScript
    Preparing search index...

    Function createLatestRequest

    • Creates a slot that keeps only the latest request.

      A newer request aborts the ones started before it, and an answer arriving after a newer one or a cancel is dropped rather than returned.

      Parameters

      Returns LatestRequest

      Use one per thing that can be superseded, like a click lookup, a search box or a refetch on map move. Aborting stops the network work. Checking again once the answer is in also catches a cancel that arrives after the response but before the caller paints it.

      By default a request retires the older ones as it starts. With supersede: 'on-answer' they keep running until a newer answer arrives, so a stream of requests faster than their answers still shows each answer in order.

      const lookup = createLatestRequest();

      map.mapLibreMap.on('click', async (event) => {
      const result = await lookup.run((signal) => reverseGeocode({ position: event.lngLat.toArray(), signal }));
      if (!result.current) return;
      showAddress(result.value);
      });
      clearButton.addEventListener('click', lookup.cancel);

      Show each route re-planned during a drag as it arrives, never an older one after a newer one:

      const latestRoute = createLatestRequest({ supersede: 'on-answer' });
      const result = await latestRoute.run((signal) => calculateRoute({ locations, signal }));
      if (result.current) await routingModule.showRoutes(result.value);