text: TC.control=TC.control||{};TC.control.MapInfo||TC.syncLoadJS(TC.apiLocation+"TC/control/MapInfo");TC.filter||TC.syncLoadJS(TC.apiLocation+"TC/Filter");TC.Consts.DownloadError={MIMETYPE_NOT_SUPORTED:"MimeTypeNotSupported"};TC.control.Download=function(n){this._classSelector="."+this.CLASS;TC.Control.apply(this,arguments);this._hiddenElms=[];var t=n||{};this._dialogDiv=TC.Util.getDiv(t.dialogDiv);window.$&&(this._$dialogDiv=$(this._dialogDiv));t.dialogDiv||document.body.appendChild(this._dialogDiv)};TC.inherit(TC.control.Download,TC.control.MapInfo);!function(){var n=TC.control.Download.prototype;n.CLASS="tc-ctl-download";n.template={};n.template[n.CLASS]={compiler:[8,">= 4.3.0"],main:function(n,t,e,l,a){var o=null!=t?t:n.nullContext||{},i=n.escapeExpression,r=n.lambda,c=n.lookupProperty||function(n,t){if(Object.prototype.hasOwnProperty.call(n,t))return n[t]};return"<h2>"+i(c(e,"i18n").call(o,"download",{name:"i18n",hash:{},data:a,loc:{start:{line:1,column:4},end:{line:1,column:23}}}))+' </h2>\r\n<div class="tc-ctl-tctr tc-ctl-tctr-select">\r\n    <label class="tc-ctl-tctr-tab tc-ctl-download-image" style="width:calc(100%/2 - 1px)"><input type="radio" name="'+i(r(null!=t?c(t,"controlId"):t,t))+'-sel" value="image" /><span>'+i(c(e,"i18n").call(o,"dl.export.map",{name:"i18n",hash:{},data:a,loc:{start:{line:3,column:157},end:{line:3,column:181}}}))+'</span></label><label \r\n\tclass="tc-ctl-tctr-tab tc-ctl-download-data" style="width:calc(100%/2 - 1px)"><input type="radio" name="'+i(r(null!=t?c(t,"controlId"):t,t))+'-sel" value="data" /><span>'+i(c(e,"i18n").call(o,"dl.export.vector",{name:"i18n",hash:{},data:a,loc:{start:{line:4,column:145},end:{line:4,column:172}}}))+'</span></label>\r\n</div>\r\n<div class="tc-ctl tc-ctl-tctr-elm tc-ctl-tctr-elm-image tc-group tc-ctl-download-cnt tc-ctl-download-image tc-collapsed">\r\n    <div>\r\n        <label>'+i(c(e,"i18n").call(o,"format",{name:"i18n",hash:{},data:a,loc:{start:{line:8,column:15},end:{line:8,column:32}}}))+':</label><select class="tc-combo">\r\n            <option value="image/png">PNG</option>\r\n            <option value="image/jpeg">JPEG</option>\r\n        </select>\r\n        <div class="tc-ctl-download-div">\r\n            <input id="tc-ctl-download-image-qr-'+i(r(null!=t?c(t,"controlId"):t,t))+'" class="tc-hidden" type="checkbox" checked />\r\n            <label for="tc-ctl-download-image-qr-'+i(r(null!=t?c(t,"controlId"):t,t))+'" class="tc-ctl-download-image-qr-label" title="'+i(c(e,"i18n").call(o,"createQrCodeToImage",{name:"i18n",hash:{},data:a,loc:{start:{line:14,column:110},end:{line:14,column:140}}}))+'">'+i(c(e,"i18n").call(o,"appendQRCode",{name:"i18n",hash:{},data:a,loc:{start:{line:14,column:142},end:{line:14,column:165}}}))+'</label>\r\n            <input id="tc-ctl-download-image-wld-'+i(r(null!=t?c(t,"controlId"):t,t))+'" class="tc-hidden" type="checkbox" />\r\n            <label for="tc-ctl-download-image-wld-'+i(r(null!=t?c(t,"controlId"):t,t))+'" class="tc-ctl-download-image-wld-label" title="'+i(c(e,"i18n").call(o,"appendWorldFile.explanation",{name:"i18n",hash:{},data:a,loc:{start:{line:16,column:112},end:{line:16,column:150}}}))+'">'+i(c(e,"i18n").call(o,"appendWorldFile",{name:"i18n",hash:{},data:a,loc:{start:{line:16,column:152},end:{line:16,column:178}}}))+'</label>\r\n        </div>\r\n\r\n        <div class="tc-group tc-group tc-ctl-download-cnt" style="text-align:right;">\r\n            <button type="button" class="tc-ctl-download-btn tc-button tc-icon-button" title="'+i(c(e,"i18n").call(o,"downloadImageFromCurrentMap",{name:"i18n",hash:{},data:a,loc:{start:{line:20,column:94},end:{line:20,column:132}}}))+'" name="descargar">'+i(c(e,"i18n").call(o,"download",{name:"i18n",hash:{},data:a,loc:{start:{line:20,column:151},end:{line:20,column:170}}}))+'</button>\r\n        </div>\r\n        <div class="tc-ctl-download-alert tc-alert alert-warning tc-hidden">\r\n            <p>'+i(c(e,"i18n").call(o,"qrAdvice",!0,{name:"i18n",hash:{},data:a,loc:{start:{line:23,column:15},end:{line:23,column:39}}}))+'</p>\r\n        </div>\r\n    </div>\r\n</div>\r\n<div class="tc-ctl tc-ctl-tctr-elm tc-ctl-tctr-elm-data tc-group tc-ctl-download-cnt tc-collapsed">\r\n    <div>\r\n        <label>'+i(c(e,"i18n").call(o,"format",{name:"i18n",hash:{},data:a,loc:{start:{line:29,column:15},end:{line:29,column:32}}}))+':</label><select class="tc-combo">\r\n            <option value="GML32">GML</option>\r\n            <option value="application/json">GeoJSON</option>\r\n            <option value="application/vnd.google-earth.kml+xml">KML (Google Earth)</option>\r\n            <option value="shape-zip">Shapefile (ESRI)</option>\r\n        </select>\r\n\r\n        <div class="tc-ctl-download-div">\r\n            <i class="tc-ctl-download-help icon-question-sign" data-toggle="tooltip" data-placement="top" title="'+i(c(e,"i18n").call(o,"showDownloadHelp",{name:"i18n",hash:{},data:a,loc:{start:{line:37,column:113},end:{line:37,column:140}}}))+'"></i>\r\n        </div>\r\n\r\n        <div class="tc-group tc-group tc-ctl-download-cnt" style="text-align:right;">\r\n            <button type="button" class="tc-ctl-download-btn tc-button tc-icon-button" title="'+i(c(e,"i18n").call(o,"downloadLayersFromCurrentExtent",{name:"i18n",hash:{},data:a,loc:{start:{line:41,column:94},end:{line:41,column:136}}}))+'" name="descargar">'+i(c(e,"i18n").call(o,"download",{name:"i18n",hash:{},data:a,loc:{start:{line:41,column:155},end:{line:41,column:174}}}))+'</button>\r\n        </div>\r\n\r\n        <div class="tc-alert alert-warning tc-hidden">\r\n            <p id="zoom-msg-'+i(r(null!=t?c(t,"controlId"):t,t))+'"><strong>'+i(c(e,"i18n").call(o,"tooManyFeatures",{name:"i18n",hash:{},data:a,loc:{start:{line:45,column:51},end:{line:45,column:77}}}))+": </strong>"+i(c(e,"i18n").call(o,"tooManyFeatures.instructions",{name:"i18n",hash:{},data:a,loc:{start:{line:45,column:88},end:{line:45,column:127}}}))+'</p>\r\n            <p id="layers-msg-'+i(r(null!=t?c(t,"controlId"):t,t))+'"><strong>'+i(c(e,"i18n").call(o,"noLayersLoaded",{name:"i18n",hash:{},data:a,loc:{start:{line:46,column:53},end:{line:46,column:78}}}))+": </strong>"+i(c(e,"i18n").call(o,"noLayersLoaded.instructions",{name:"i18n",hash:{},data:a,loc:{start:{line:46,column:89},end:{line:46,column:127}}}))+'</p>\r\n            <p id="url-msg-'+i(r(null!=t?c(t,"controlId"):t,t))+'"><strong>'+i(c(e,"i18n").call(o,"tooManySelectedLayers",{name:"i18n",hash:{},data:a,loc:{start:{line:47,column:50},end:{line:47,column:82}}}))+": </strong>"+i(c(e,"i18n").call(o,"tooManySelectedLayers.instructions",{name:"i18n",hash:{},data:a,loc:{start:{line:47,column:93},end:{line:47,column:138}}}))+'</p>\r\n            <p id="noFeatures-msg-'+i(r(null!=t?c(t,"controlId"):t,t))+'"><strong>'+i(c(e,"i18n").call(o,"noData",{name:"i18n",hash:{},data:a,loc:{start:{line:48,column:57},end:{line:48,column:74}}}))+": </strong>"+i(c(e,"i18n").call(o,"noData.instructions",{name:"i18n",hash:{},data:a,loc:{start:{line:48,column:85},end:{line:48,column:115}}}))+'</p>\r\n            <p id="novalid-msg-'+i(r(null!=t?c(t,"controlId"):t,t))+'"><strong>'+i(c(e,"i18n").call(o,"noValidService",{name:"i18n",hash:{},data:a,loc:{start:{line:49,column:54},end:{line:49,column:79}}}))+": </strong>"+i(c(e,"i18n").call(o,"noValidService.instructions",{name:"i18n",hash:{},data:a,loc:{start:{line:49,column:90},end:{line:49,column:128}}}))+"</p>\r\n        </div>\r\n    </div>\r\n</div>\r\n\r\n"},useData:!0};n.template[n.CLASS+"-dialog"]={compiler:[8,">= 4.3.0"],main:function(n,t,e,l,a){var o=null!=t?t:n.nullContext||{},i=n.escapeExpression,r=n.lookupProperty||function(n,t){if(Object.prototype.hasOwnProperty.call(n,t))return n[t]};return'<div class="tc-ctl-download-help-dialog tc-modal">\r\n    <div class="tc-modal-background tc-modal-close"></div>\r\n    <div class="tc-modal-window">\r\n        <div class="tc-modal-header">\r\n            <h3>'+i(r(e,"i18n").call(o,"downloadData",{name:"i18n",hash:{},data:a,loc:{start:{line:5,column:16},end:{line:5,column:39}}}))+'</h3>\r\n            <div class="tc-modal-close"></div>\r\n        </div>\r\n        <div class="tc-modal-body">\r\n            <p>'+i(r(e,"i18n").call(o,"dl.instructions.1",!0,{name:"i18n",hash:{},data:a,loc:{start:{line:9,column:15},end:{line:9,column:48}}}))+"</p>\r\n            <ul>\r\n                <li>"+i(r(e,"i18n").call(o,"dl.instructions.2",!0,{name:"i18n",hash:{},data:a,loc:{start:{line:11,column:20},end:{line:11,column:53}}}))+"</li>\r\n                <li>"+i(r(e,"i18n").call(o,"dl.instructions.3",!0,{name:"i18n",hash:{},data:a,loc:{start:{line:12,column:20},end:{line:12,column:53}}}))+"</li>\r\n                    <li>\r\n                        "+i(r(e,"i18n").call(o,"dl.instructions.4",!0,{name:"i18n",hash:{},data:a,loc:{start:{line:14,column:24},end:{line:14,column:57}}}))+"\r\n                    <ul>\r\n                        <li>"+i(r(e,"i18n").call(o,"dl.instructions.5",!0,{name:"i18n",hash:{},data:a,loc:{start:{line:16,column:28},end:{line:16,column:61}}}))+"</li>\r\n                        <li>"+i(r(e,"i18n").call(o,"dl.instructions.6",!0,{name:"i18n",hash:{},data:a,loc:{start:{line:17,column:28},end:{line:17,column:61}}}))+'</li>\r\n                    </ul>\r\n                </li>\r\n            </ul>\r\n        </div>\r\n        <div class="tc-modal-footer">\r\n            <button type="button" class="tc-button tc-modal-close">'+i(r(e,"i18n").call(o,"close",{name:"i18n",hash:{},data:a,loc:{start:{line:23,column:67},end:{line:23,column:83}}}))+"</button>\r\n        </div>\r\n    </div>\r\n</div>\r\n\r\n"},useData:!0};n.render=function(n){const t=this;return t.getRenderedHtml(t.CLASS+"-dialog",null,function(n){t._dialogDiv.innerHTML=n}).then(function(){return TC.Control.prototype.renderData.call(t,{controlId:t.id},function(){const e=".tc-ctl-tctr";t._selectors={TAB:e+"-tab",RADIOBUTTON:`input[type=radio][name="${t.id}-sel"]`,ELEMENT:e+"-elm"};const l=function(n){for(var e=this;e&&!e.matches(t._selectors.TAB);)e=e.parentElement;if(e){const n=e.querySelector(t._selectors.RADIOBUTTON),l=n.value,a=t.div.querySelectorAll(t._selectors.ELEMENT);if(t._oldValue===l&&t.options.deselectable){setTimeout(function(){n.checked=!1},0);t._oldValue=null;t._activeElm=null;a.forEach(function(n){t._hiddenElms.push(n)})}else{a.forEach(function(n){n.matches(t._selectors.ELEMENT+"-"+l)?t._activeElm=n:t._hiddenElms.push(n)});t._oldValue=l}t._hiddenElms.forEach(function(n){n.classList.add(TC.Consts.classes.COLLAPSED)});t._activeElm&&t._activeElm.classList.remove(TC.Consts.classes.COLLAPSED);n.checked=!0}};t.div.querySelectorAll("span").forEach(function(n){n.addEventListener(TC.Consts.event.CLICK,l,{passive:!0})});n&&n()})})};const t=function(n){let t=n.toFixed(20);t.indexOf(".")>=0&&(t=t.replace(/0+$/,"").replace(/\.$/,""));return t};n.register=function(n){var e=this;const l=TC.control.MapInfo.prototype.register.call(e,n);e.map.mustBeExportable=!0;var a=function(n,t){const l=e.div.querySelector(".alert-warning:not(."+e.CLASS+"-alert)");var a;switch(n.key){case TC.Consts.WFSErrors.MAX_NUM_FEATURES:a=l.querySelector("#zoom-msg-"+e.id).innerHTML.format({serviceName:n.params.serviceTitle});break;case TC.Consts.WFSErrors.NO_LAYERS:a=e.getLocaleString("noLayersLoaded");break;case TC.Consts.WFSErrors.GETCAPABILITIES:a=l.querySelector("#novalid-msg-"+e.id).innerHTML.format({serviceName:n.params.serviceTitle});break;case TC.Consts.WFSErrors.NO_FEATURES:a=l.querySelector("#noFeatures-msg-"+e.id).innerHTML;break;case TC.Consts.WFSErrors.INDETERMINATE:a=e.getLocaleString("wfs.IndeterminateError");e.map.toast(a,{type:TC.Consts.msgType.ERROR});TC.error("Error:{error} \r\n Descripcion:{descripcion} \r\n Servicio:{serviceName}".format({error:n.params.err,descripcion:n.params.errorThrown,serviceName:n.params.serviceTitle}),TC.Consts.msgErrorMode.CONSOLE);e.map.getLoadingIndicator().removeWait(t);return;default:a=e.getLocaleString("wfs."+n.key,n.params)}e.map.toast(a,{type:TC.Consts.msgType.WARNING});e.map.getLoadingIndicator().removeWait(t)};e.div.addEventListener(TC.Consts.event.CLICK,TC.EventTarget.listenerBySelector(".tc-ctl-download-btn",function(){var n="";e._activeElm&&(n=e._activeElm.querySelector("select").value);n.indexOf("image")>-1?function(n){const l=e.map.getLoadingIndicator(),a=l&&l.addWait(),o=e.map.getExtent();new Promise(function(n,t){var o=e.map.wrap.getViewport({synchronous:!0}).getElementsByTagName("canvas")[0],i=TC.Util.cloneCanvas(o);e.map.getControlsByClass(TC.control.ScaleBar)&&e.drawScaleBarIntoCanvas({canvas:i,fill:!0});if(!e._activeElm.querySelector(`#${e.CLASS}-image-qr-${e.id}:disabled`)&&e._activeElm.querySelector(`#${e.CLASS}-image-qr-${e.id}:checked`)){const t="qrcode";var r=document.getElementById(t);if(r)r.innerHTML="";else{(r=document.createElement("div")).setAttribute("id",t);document.body.appendChild(r)}r.style.top="-200px";r.style.left="-200px";r.style.position="absolute";e.makeQRCode(r,87,87).then(function(t){if(t){var e=i.getContext("2d");e.fillStyle="#ffffff";e.fillRect(i.width-91,i.height-91,91,91);TC.Util.addToCanvas(i,t,{x:i.width-88,y:i.height-88}).then(function(t){n(t)})}else l&&l.removeWait(a)})}else n(i)}).then(function(i){const r=window.location.hostname+"_"+e.map.crs.replace(":","")+"_"+TC.Util.getFormattedDate((new Date).toString(),!0),c="."+n.split("/")[1],s=n===TC.Consts.mimeType.JPEG?".jgw":".pgw";if(e._activeElm.querySelector(`#${e.CLASS}-image-wld-${e.id}:checked`))TC.loadJS(!window.JSZip,TC.apiLocation+"lib/jszip/jszip",function(){const d=(o[2]-o[0])/i.width,m=(o[1]-o[3])/i.height,u=o[0],p=o[3],h=new JSZip;i.toBlob(function(n){h.file(r+c,n);h.file(r+s,`${t(d)}\n${(0).toFixed(1)}\n${(0).toFixed(1)}\n${t(m)}\n${t(u)}\n${t(p)}`);h.generateAsync({type:"blob"}).then(function(n){TC.Util.downloadBlob(r+".zip",n);l&&l.removeWait(a)},function(n){TC.error(e.getLocaleString("dl.export.map.error")+": "+n.message);l&&l.removeWait(a)})},n)});else{try{const t=i.toDataURL(n);TC.Util.downloadDataURI(r+c,n,t)}catch(n){TC.error(e.getLocaleString("dl.export.map.error")+": "+n.message)}l&&l.removeWait(a)}})}(n):function(n){const t=e.map.getLoadingIndicator(),l=t&&t.addWait(),o=e.map.extractFeatures({filter:TC.filter.bbox(e.map.getExtent(),e.map.getCRS()),outputFormat:n,download:!0});Promise.all(o).then(async function(o){var i=o.filter(function(n){return null!=n});if(0!==i.length){for(var r=[],c=0;c<i.length;c++)if(i[c].errors&&i[c].errors.length)for(var s=0;s<i[c].errors.length;s++){var d=i[c].errors[s];a(d,l)}else{var m=i[c].data,u=i[c].url;m&&u&&r.push({url:u+"?download=zip",data:m})}try{await TC.Util.downloadFileForm(r)}catch(t){if(t.key===TC.Consts.DownloadError.MIMETYPE_NOT_SUPORTED){const l=o.find(function(n){return n.data===t.data}).service,a={plural:l.layers.length>1?e.getLocaleString("dl.format.notSupported.plural"):"",layerNames:l.layers.reduce(function(n,t,l,a){return(n instanceof Array?n:[n]).concat([t.title]).join(l<a.length-1?", ":" "+e.getLocaleString("dl.format.notSupported.conjunction")+" ")},[]),serviceTitle:l.mapLayers[0].title,format:n};e.map.toast(e.getLocaleString("dl.format.notSupported").format(a),{type:TC.Consts.msgType.ERROR})}}t&&t.removeWait(l)}else a({key:TC.Consts.WFSErrors.NO_LAYERS},l)})}(n)}),{passive:!0});e.div.addEventListener(TC.Consts.event.CLICK,TC.EventTarget.listenerBySelector(".tc-ctl-download-help",function(n){n.stopPropagation();TC.Util.showModal(e._dialogDiv.querySelector(e._classSelector+"-help-dialog"))}),{passive:!0});e.div.addEventListener("change",TC.EventTarget.listenerBySelector(`#${e.CLASS}-image-qr-${e.id}`,function(n){n.target.checked?e.generateLink():e.div.querySelector("."+e.CLASS+"-alert").classList.add(TC.Consts.classes.HIDDEN)}));e.div.addEventListener("click",TC.EventTarget.listenerBySelector("h2",function(n){e.registeredListeners||e.generateLink();e.registerListeners()}));return l};n.manageMaxLengthExceed=function(n){const t=this.div.querySelector("."+this.CLASS+"-alert"),e=document.getElementById(`${this.CLASS}-image-qr-${this.id}`);e.disabled=n.qr;e.checked?t.classList.toggle(TC.Consts.classes.HIDDEN,!n.qr):t.classList.add(TC.Consts.classes.HIDDEN)};n.generateLink=async function(){const n=this.div.querySelector(`.${this.CLASS}-div input[id|="${this.CLASS}-image-qr-download"]`),t=this.div.querySelector(`label[for="${n.id}"]`);n.disabled=!0;t.classList.add(TC.Consts.classes.LOADING);const e=await TC.control.MapInfo.prototype.generateLink.call(this);t.classList.remove(TC.Consts.classes.LOADING);return e}}();
  //# sourceMappingURL=../maps/control/Download.min.js.map