"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const laji_map_1 = __importDefault(require("@luomus/laji-map"));
/**
 * Service used for accessing a singlet on instance of LajiMap. Using a singleton instance increases performance, as
 * the map needs to be initialized only once. Control of the map of simply grabbed, making the previous owner lose
 * control of the map.
 */
class SingletonMapService {
    destroy() {
        var _a;
        (_a = this.map) === null || _a === void 0 ? void 0 : _a.destroy();
    }
    /**
     * Grab control of the singleton map.
     * @param instance should be the Map component instance, that is set as the controller of the map.
     * @param mapOptions Map options to set to the map.
     */
    grab(instance, mapOptions) {
        this.owner = instance;
        if (!this.map) {
            this.map = new laji_map_1.default(mapOptions);
            // this.map = singletonMapService.map;
            // this.mounted && props.singleton && this.hasSingletonHandle && props.zoomToData && this.map.zoomToData(props.zoomToData);
            // props.zoomToData && this.map.zoomToData(props.zoomToData);
        }
        else {
            this.owner.setMapOptions(this.map.getOptions(), mapOptions, this.owner.props.id);
        }
        return this.map;
    }
    release(instance) {
        if (instance === this.owner) {
            this.owner = undefined;
        }
    }
    /**
     * Ask whether given instance has control of the map.
     */
    amOwner(instance) {
        return this.owner === instance;
    }
}
exports.default = SingletonMapService;
