/*---------------------------------------------------------------------------------------------
* Copyright (c) Bentley Systems, Incorporated. All rights reserved.
* See LICENSE.md in the project root for license terms and full copyright notice.
*--------------------------------------------------------------------------------------------*/
import { deflateCoordinates } from "../../../../tile/internal";
/** @internal */
export class ArcGisGeometryReaderJSON {
    _ringsOrPaths;
    _points;
    _fill;
    _relativeCoords;
    _renderer;
    constructor(geometryType, renderer, relativeCoords = false) {
        this._ringsOrPaths = geometryType === "esriGeometryPolyline" || geometryType === "esriGeometryPolygon";
        this._points = geometryType === "esriGeometryPoint" || geometryType === "esriGeometryMultiPoint";
        this._fill = geometryType === "esriGeometryPolygon";
        this._renderer = renderer;
        this._relativeCoords = relativeCoords;
    }
    async readGeometry(geometry) {
        if (this._ringsOrPaths) {
            await this.readRingsAndPaths(geometry, this._renderer, this._fill, this._relativeCoords);
        }
        else if (this._points) {
            await this.readPoints(geometry, this._renderer, this._relativeCoords);
        }
    }
    async readRingsAndPaths(geometry, renderer, fill, relativeCoords) {
        let offset = 0;
        const lengths = [];
        const coords = [];
        if (geometry?.rings) {
            for (const ring of geometry?.rings) {
                offset = deflateCoordinates(ring, coords, 2, offset);
                lengths.push(ring.length);
            }
        }
        else if (geometry?.paths) {
            for (const path of geometry?.paths) {
                offset = deflateCoordinates(path, coords, 2, offset);
                lengths.push(path.length);
            }
        }
        await renderer.renderPath(lengths, coords, fill, 2, relativeCoords);
    }
    async readPoints(geometry, renderer, relativeCoords) {
        if (geometry) {
            const lengths = [];
            const coords = [geometry.x, geometry.y];
            await renderer.renderPoint(lengths, coords, 2, relativeCoords);
        }
    }
}
//# sourceMappingURL=ArcGisGeometryReaderJSON.js.map