import Point from '@arcgis/core/geometry/Point'; import SpatialReference from '@arcgis/core/geometry/SpatialReference'; /** * Parsing succeeded and returned a valid value. */ interface ParseSuccess { kind: "success"; value: T; } /** * Parsing resulted in an error. */ interface ParseError { kind: "error"; /** * Human readable error message. * This message may be presented to the user. */ message?: string; } /** * The result of parsing inputs. */ type ParseResult = ParseSuccess | ParseError; /** * Implements a format for coordinate conversions. * * You can extend the builtin set of formats by providing a service with `"coordinateconversion.SegmentedFormat"`. */ interface SegmentedFormat { /** * Unique id of this format. */ readonly id: string; /** * Human readable label of this format. */ readonly label: string; /** * Input segments required by the format, for example `x` and `y` coordinates. * The coordinate conversion widget shows one input field for each segment. */ readonly segments: CoordinateSegment[]; /** * When specified, points will be projected to this spatial reference before being passed to {@link pointToSegments}. * * If this is not specified, you will receive the point in the current spatial reference of the view, and * you will have to perform any necessary projections yourself. */ readonly spatialReference?: SpatialReference; /** * Renders a point to _segment_ values. * The returned record is indexed by segment ids and contains a string for each segment. * * The output of this function should be compatible with {@link segmentsToPoint}. * * Example: * * ```js * const point = ...; * const segments = format.pointToSegments(point); * // segments == { x: "...", y: "..." } * ``` */ pointToSegments(point: Point): Promise>; /** * Formats a set of _segment_ values to a human readable string. * This combines the segment values to a final display string, including separating characters (like ',' or ' ') * and units (like '°' and '"'). * * The `segments` parameter can be assumed to contain valid strings: either * - user input validated by {@link CoordinateSegment.validate} or * - segment values generated by {@link pointToSegments}. * * The value returned here should be compatible with {@link stringToSegments}. * * Example: * * ```js * const segments = { x: "1", y: "2" } * const output = format.segmentsToString(segments); * // output == "1°, 2°" * `` */ segmentsToString(segments: Record): string; /** * Splits a human readable coordinates string (like returned by {@link segmentsToString}) into its input segment. * * For example: * * ```js * const input = "123.4 567.8"; * const segments = format.stringToSegments(input).value; // assumes success * // segments == { x: "123.4", y: "567.8" }; * ``` */ stringToSegments(input: string): ParseResult>; /** * Parses a set of (validated) segment values into a `Point`. * This can be used, for example, to place a marker on the map. * * Example: * * ```js * const segments = { x: "1", y: "2" } * const point = await format.segmentsToPoint(segments).value; // assumes success * // point == { x: 1234, y: 5678, spatialReference: { ... }} * ``` */ segmentsToPoint(segments: Record): Promise>; } /** * A coordinate segment within a {@link SegmentedFormat}. */ interface CoordinateSegment { /** * Id of this segment. * * This should be unique within the context of its format. */ id: string; /** * Human readable label for this coordinate segment (e.g. "Latitude"). */ label: string; /** * Example for this segment, like '51° 57' 40"N' */ example?: string; /** * A prefix value that will be shown as part of the input field for this coordinate segment. * * This is a display-only field for strings that do not need to be typed by the user (such as "°"). */ prefix?: string; /** * A suffix value that will be shown as part of the input field for this coordinate segment. * * This is a display-only field for strings that do not need to be typed by the user (such as "°"). */ suffix?: string; /** * Validates an input string for this coordinate segment. * `input` is the (trimmed) text typed by the user. * * This function should return `true` if the input is valid, * or an error message otherwise. * * `validate()` usually only performs text based validation (e.g. regular expressions). * Parsing the actual input string (using {@link SegmentedFormat.segmentsToPoint}) can return additional errors. * * Only valid inputs will be passed to {@link SegmentedFormat.segmentsToPoint}. */ validate(input: string): true | false | ParseError; } /** * A model that provides access to the current state of the coordinate conversion widget. * Properties and methods are designed to be used together with the Reactivity API. * * It is available as service `coordinateconversion.Model`. */ interface CoordinateConversionModel { /** * True if the widget is currently active. */ readonly active: boolean; /** * The current marker location, if any. * This value represents explicit location inputs and also locations from mouse movements. */ readonly currentLocation: Point | undefined; /** * The current marker location, if any. * * This value represents explicit location inputs only, i.e. if the user clicked on the map (not just moving the mouse) * or confirmed the input form. */ readonly confirmedLocation: Point | undefined; } export type { CoordinateConversionModel, CoordinateSegment, ParseError, ParseResult, ParseSuccess, SegmentedFormat };