"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.FormatDriver = void 0;
var tslib_1 = require("tslib");
var parsed_features_1 = require("./parsed-features");
/**
 * A default format driver implementation primarily for interfacing with any
 * existing OpenLayers format driver instances
 *
 * @export
 * @class FormatDriver
 * @implements {IFormatDriver}
 * @since 0.13
 */
var FormatDriver = /** @class */ (function () {
    function FormatDriver(type, format, defaultProjection) {
        if (defaultProjection === void 0) { defaultProjection = null; }
        this.type = type;
        this.format = format;
        this.defaultProjection = defaultProjection;
    }
    FormatDriver.prototype.tryParse = function (size, text) {
        return tslib_1.__awaiter(this, void 0, void 0, function () {
            var fs, bHasPoint, bHasLine, bHasPoly, _i, fs_1, f, g, geomTypes, propNames, first, _a, _b, k, features;
            var _this = this;
            return tslib_1.__generator(this, function (_c) {
                fs = this.format.readFeatures(text);
                bHasPoint = false;
                bHasLine = false;
                bHasPoly = false;
                for (_i = 0, fs_1 = fs; _i < fs_1.length; _i++) {
                    f = fs_1[_i];
                    g = f.getGeometry();
                    switch (g === null || g === void 0 ? void 0 : g.getType()) {
                        case "Point":
                            bHasPoint = true;
                            break;
                        case "LineString":
                            bHasLine = true;
                            break;
                        case "LinearRing":
                            bHasLine = true;
                            break;
                        case "Polygon":
                            bHasPoly = true;
                            break;
                        case "MultiPoint":
                            bHasPoint = true;
                            break;
                        case "MultiLineString":
                            bHasLine = true;
                            break;
                        case "MultiPolygon":
                            bHasPoly = true;
                            break;
                        case "GeometryCollection":
                            bHasPoint = true;
                            break;
                        case "Circle":
                            bHasPoly = true;
                            break;
                    }
                }
                geomTypes = [];
                if (bHasPoint) {
                    geomTypes.push("Point");
                }
                if (bHasLine) {
                    geomTypes.push("LineString");
                }
                if (bHasPoly) {
                    geomTypes.push("Polygon");
                }
                propNames = [];
                if (fs.length > 0) {
                    first = fs[0];
                    for (_a = 0, _b = first.getKeys(); _a < _b.length; _a++) {
                        k = _b[_a];
                        if (k == first.getGeometryName()) {
                            continue;
                        }
                        propNames.push(k);
                    }
                }
                features = function () { return tslib_1.__awaiter(_this, void 0, void 0, function () { return tslib_1.__generator(this, function (_a) {
                    return [2 /*return*/, fs];
                }); }); };
                return [2 /*return*/, new parsed_features_1.ParsedFeatures(this.type, size, features, fs.length > 0, geomTypes, propNames, this.defaultProjection)];
            });
        });
    };
    return FormatDriver;
}());
exports.FormatDriver = FormatDriver;
//# sourceMappingURL=format-driver.js.map