"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.UTFGridTrackingTooltip = void 0;
var tslib_1 = require("tslib");
var Overlay_1 = tslib_1.__importDefault(require("ol/Overlay"));
var dompurify_1 = require("dompurify");
var UTFGridTrackingTooltip = /** @class */ (function () {
    function UTFGridTrackingTooltip(map, gridSource, isContextMenuOpen) {
        this.map = map;
        this.gridSource = gridSource;
        this.isContextMenuOpen = isContextMenuOpen;
        this.map.getViewport().addEventListener("mouseout", this.onMouseOut.bind(this));
        this.tooltipElement = document.createElement("div");
        this.tooltipElement.className = 'feature-tooltip';
        this.tooltip = new Overlay_1.default({
            element: this.tooltipElement,
            offset: [15, 0],
            positioning: 'center-left'
        });
        this.map.addOverlay(this.tooltip);
        this.text = null;
    }
    UTFGridTrackingTooltip.prototype.dispose = function () {
        this.tooltip.dispose();
    };
    UTFGridTrackingTooltip.prototype.onMouseMove = function (e) {
        var _this = this;
        if (this.isContextMenuOpen())
            return;
        //this.tooltip.setPosition(e.coordinate);
        var viewResolution = /** @type {number} */ (this.map.getView().getResolution());
        if (viewResolution) {
            this.gridSource.forDataAtCoordinateAndResolution(e.coordinate, viewResolution, function (data) {
                // If you want to use the template from the TileJSON,
                //  load the mustache.js library separately and call
                //
                //mapElement.style.cursor = data ? 'pointer' : '';
                if (data) {
                    var html = "";
                    if (data.MG_TOOLTIP)
                        html += (0, dompurify_1.sanitize)(data.MG_TOOLTIP.replace(/(\\n)+/g, '<br />'));
                    if (data.MG_URL) {
                        html += "<br/><br/>";
                        html += "<strong>CTRL + Click for more information</strong>";
                    }
                    _this.tooltipElement.innerHTML = html;
                }
                _this.tooltip.setPosition(data ? e.coordinate : undefined);
            });
        }
    };
    UTFGridTrackingTooltip.prototype.onMouseOut = function () {
    };
    UTFGridTrackingTooltip.prototype.setText = function (prompt) {
        this.text = prompt;
        this.tooltipElement.innerHTML = this.text;
    };
    UTFGridTrackingTooltip.prototype.clear = function () {
        this.text = null;
        this.tooltipElement.innerHTML = "";
    };
    UTFGridTrackingTooltip.prototype.destroy = function () {
        if (this.tooltipElement && this.tooltipElement.parentNode) {
            this.tooltipElement.parentNode.removeChild(this.tooltipElement);
        }
    };
    return UTFGridTrackingTooltip;
}());
exports.UTFGridTrackingTooltip = UTFGridTrackingTooltip;
//# sourceMappingURL=utfgrid.js.map