This is the documentation of version 0.63.0. 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: starting one aborts its predecessor, and an answer that arrives after a newer request or a cancel is dropped rather than returned.

      Returns LatestRequest

      Use one per thing that can be superseded — a click lookup, a search box, 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.

      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);