FakeFeatureQuery
A scripted FeatureQuery with no network and no timers.
This is a class exported by @mapcairn/core, checked against version 0.2.0.
Signature
import { FakeFeatureQuery } from "@mapcairn/core";
class FakeFeatureQuery implements FeatureQuery
Description
How to script it:
respondWith(hits)says what lies inside whatever area is asked about. It answers every later query with the firstlimitof those hits in the layers asked about, each feature once, as the port rules require. With no script it finds nothing.failWith(kind)makes every query reject with aFeatureQueryErroruntilclearFailure().hold()keeps every later query pending until the function it returns is called, which also lets the queries held since then answer. Releasing an earlier hold does not free queries made under a later one.- A request is checked first: a
limitthat is not a whole number of at least 1, or anareathat is not a polygon with at least one closed ring on the globe, rejects asinvalid. The check comes before any hold or failure, so a bad request never uses a script. - Every query honours its
AbortSignalby rejecting with aFeatureQueryErrorof kindaborted, before the call or while it is held. callsrecords what the ui asked.
Properties
calls
readonly calls: FeatureQueryRequest[];
Every request the ui made, in order, including ones that were refused or failed.
Methods
clearFailure
clearFailure(): void;
Stops FakeFeatureQuery failing queries.
failWith
failWith(kind: FakeFeatureQueryFailure): void;
Makes every later query reject with a FeatureQueryError of this kind.
kind(FakeFeatureQueryFailure)
hold
hold(): () => void;
Holds every later query until the returned function is called. A later
hold replaces this one for queries made after it, and releasing this one
then leaves that hold in place.
respondWith
respondWith(hits: readonly SelectionHit[]): void;
Answers every later query from these hits.
hits(readonly SelectionHit[])
within
within(request: FeatureQueryRequest): Promise<readonly SelectionHit[]>;
Checks the request, then answers as scripted: the first limit of the scripted hits in the layers asked about, a held, failed or aborted query, or no hits when nothing is scripted.
request(FeatureQueryRequest)