"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var tslib_1 = require("../polyfills/tslib.js");
var chunk_853b4351_js_1 = require("./chunk-853b4351.js");
var Map = function () { function t() { this.drawing = !1, this.zoom = 10, this.minzoom = 0, this.maxzoom = 22; } return t.prototype.componentWillLoad = function () { var t = this; this._style = this.loadStyle(), this.map = new mapboxgl.Map({ container: this.el, center: [this.longitude, this.latitude], zoom: this.zoom, minZoom: this.minzoom, maxZoom: this.maxzoom, style: this._style }), window.addEventListener("resize", this.resizeMap.bind(this)), this.map.on("draw.create", function (e) { return t.glDrawCreate.emit({ mapId: t.id, features: e.features }); }), this.map.on("draw.delete", function (e) { return t.glDrawDelete.emit({ mapId: t.id, features: e.features }); }); }, t.prototype.componentDidUpdate = function () { this.resizeMap(); }, t.prototype.updateStyle = function () { return tslib_1.__awaiter(this, void 0, void 0, function () { var t = this; return tslib_1.__generator(this, function (e) { return this._updateStyleTimeout ? [2] : (this._updateStyleTimeout = window.setTimeout(function () { return tslib_1.__awaiter(t, void 0, void 0, function () { var t; return tslib_1.__generator(this, function (e) { switch (e.label) {
    case 0: return this._updateStyleTimeout = null, t = this, [4, this.loadStyle()];
    case 1: return t._style = e.sent(), this.map.setStyle(this._style), this.glStyleUpdated.emit(this._style), [2];
} }); }); }, 66), [2]); }); }); }, t.prototype.handleStyleAdded = function () { return tslib_1.__awaiter(this, void 0, void 0, function () { return tslib_1.__generator(this, function (t) { return this.updateStyle(), [2]; }); }); }, t.prototype.handleStyleModified = function () { return tslib_1.__awaiter(this, void 0, void 0, function () { return tslib_1.__generator(this, function (t) { return this.updateStyle(), [2]; }); }); }, t.prototype.handleStyleRemoved = function () { return tslib_1.__awaiter(this, void 0, void 0, function () { return tslib_1.__generator(this, function (t) { return this.updateStyle(), [2]; }); }); }, t.prototype.updateDrawing = function () { return tslib_1.__awaiter(this, void 0, void 0, function () { return tslib_1.__generator(this, function (t) { return this.drawing ? (this.draw = new MapboxDraw(this.drawOptions), this.map.addControl(this.draw), this.glDrawEnter.emit({ mapId: this.id })) : (this.map.removeControl(this.draw), this.draw = null, this.glDrawExit.emit({ mapId: this.id })), [2]; }); }); }, t.prototype.resizeMap = function () { var t = this; this._resizeMapTimeout || (this._resizeMapTimeout = window.setTimeout(function () { return tslib_1.__awaiter(t, void 0, void 0, function () { return tslib_1.__generator(this, function (t) { return this._resizeMapTimeout = null, this.map && this.map.resize(), [2]; }); }); }, 66)); }, t.prototype.getStyleLayers = function (t, e) { if (!e.layers)
    return []; for (var r = [], i = 0, n = e.layers; i < n.length; i++) {
    var o = n[i], a = Object.assign({}, o, { id: this.prefix(t, o.id) });
    o.source && (a.source = this.prefix(t, o.source)), r.push(a);
} return r; }, t.prototype.getStyleSources = function (t, e) { if (!e.sources)
    return []; var r = {}; for (var i in e.sources)
    r[this.prefix(t, i)] = e.sources[i]; return r; }, t.prototype.loadStyle = function () { var t = this, e = { version: 8, metadata: {}, sources: {}, layers: [] }; return this.glyphs && (e.glyphs = this.glyphs), this.sprite && (e.sprite = this.sprite), Array.from(this.el.querySelectorAll("gl-style")).forEach(function (r) { if (r.enabled) {
    var i = r.id, n = r.json;
    n && (e.layers = t.getStyleLayers(i, n).concat(e.layers), e.sources = Object.assign({}, e.sources, t.getStyleSources(i, n)), n.glyphs && !e.glyphs && (e.glyphs = n.glyphs), n.sprite && !e.sprite && (e.sprite = n.sprite));
} }), e.glyphs && (e.glyphs = chunk_853b4351_js_1.c(e.glyphs).replace("%7Bfontstack%7D", "{fontstack}").replace("%7Brange%7D", "{range}")), e.sprite && (e.sprite = chunk_853b4351_js_1.c(e.sprite)), e; }, t.prototype.prefix = function (t, e) { return t + ":" + e; }, Object.defineProperty(t, "is", { get: function () { return "gl-map"; }, enumerable: !0, configurable: !0 }), Object.defineProperty(t, "properties", { get: function () { return { draw: { type: "Any", attr: "draw", mutable: !0 }, drawing: { type: Boolean, attr: "drawing", watchCallbacks: ["updateDrawing"] }, drawOptions: { type: "Any", attr: "draw-options" }, el: { elementRef: !0 }, glyphs: { type: String, attr: "glyphs" }, id: { type: String, attr: "id" }, latitude: { type: Number, attr: "latitude" }, longitude: { type: Number, attr: "longitude" }, map: { type: "Any", attr: "map", mutable: !0 }, maxzoom: { type: Number, attr: "maxzoom" }, minzoom: { type: Number, attr: "minzoom" }, resizeMap: { method: !0 }, sprite: { type: String, attr: "sprite" }, zoom: { type: Number, attr: "zoom" } }; }, enumerable: !0, configurable: !0 }), Object.defineProperty(t, "events", { get: function () { return [{ name: "glDrawCreate", method: "glDrawCreate", bubbles: !0, cancelable: !0, composed: !0 }, { name: "glDrawDelete", method: "glDrawDelete", bubbles: !0, cancelable: !0, composed: !0 }, { name: "glDrawEnter", method: "glDrawEnter", bubbles: !0, cancelable: !0, composed: !0 }, { name: "glDrawExit", method: "glDrawExit", bubbles: !0, cancelable: !0, composed: !0 }, { name: "glStyleUpdated", method: "glStyleUpdated", bubbles: !0, cancelable: !0, composed: !0 }]; }, enumerable: !0, configurable: !0 }), Object.defineProperty(t, "listeners", { get: function () { return [{ name: "glStyleElementAdded", method: "handleStyleAdded" }, { name: "glStyleElementModified", method: "handleStyleModified" }, { name: "glStyleElementRemoved", method: "handleStyleRemoved" }]; }, enumerable: !0, configurable: !0 }), Object.defineProperty(t, "style", { get: function () { return "gl-map{display:block;height:100%;width:100%}"; }, enumerable: !0, configurable: !0 }), t; }();
exports.GlMap = Map;
