text: TC.control=TC.control||{};TC.Control||TC.syncLoadJS(TC.apiLocation+"TC/Control");TC.control.MapInfo=function(){TC.Control.apply(this,arguments)};TC.inherit(TC.control.MapInfo,TC.Control);!function(){var t=TC.control.MapInfo.prototype;t.CLASS="tc-ctl-mi";t.register=function(t){const e=this,n=TC.Control.prototype.register.call(e,t);e.QR_MAX_URL_LENGTH=150;e.SHORTEN_URL_LENGTH=32715;e.exportsState=!1;e.includeControls=void 0===e.options.includeControls||e.options.includeControls;t.ready(function(){const n=t.state&&t.state.ctl;if(n&&!t._controlStatesLoaded){e.importControlStates(n);t._controlStatesLoaded=!0}});return n};t.exportControlStates=function(){const t=this;return t.map?t.map.controls.map(function(t){return t.exportState()}).filter(function(t){if(t)for(var e in t)if(t.hasOwnProperty(e))return!0;return!1}):[]};t.importControlStates=function(t){const e=this;e.map&&t.forEach(function(t){const n=e.map.getControlById(t.id);n&&e.map.loaded(function(){n.importState(t)})})};t.exportState=function(){const t=this;if(t.exportsState){const n={};if(t.featureToShare||t.sharedFeaturesLayer){var e;n.id=t.id;if(t.featureToShare){const n=t.featureToShare.clone();n.showsPopup=!0;e=t.featureToShare.layer.exportState({features:[n]})}else e=t.sharedFeaturesLayer.exportState();n.features=e.features;e.crs&&(n.crs=e.crs)}return n}return null};t.importState=function(t){const e=this;e.map&&t.features.length&&e.map.addLayer({id:e.getUID(),owner:e,type:TC.Consts.layerType.VECTOR,title:e.getLocaleString("foi"),stealth:!0}).then(function(n){e.sharedFeaturesLayer=n;n.importState({features:t.features,crs:t.crs}).then(function(){e.map.zoomToFeatures(n.features)})})};t.manageMaxLengthExceed=function(){throw"Falta implementaci\xf3n del m\xe9todo manageMaxLengthExceed"};t.generateLink=function(){var t=window.location.href,e=t.indexOf("#");e>0&&(t=t.substring(0,e));if(this.extraParams){var n=TC.Util.getQueryStringParams(t);TC.Util.extend(n,this.extraParams);var o=t.indexOf("?");o>=0&&(t=t.substring(0,o));t=t.concat("?",TC.Util.getParamString(n))}TC.Util.getParameterByName("lang").length>0&&(t=t.indexOf("&")>-1?t.replace("lang="+TC.Util.getParameterByName("lang")+"&",""):t.replace("?lang="+TC.Util.getParameterByName("lang"),""));const r=this.includeControls?this.exportControlStates():[];this.exportsState&&(this.featureToShare||this.sharedFeaturesLayer)&&r.push(this.exportState());const i=r.length?{ctl:r}:void 0;var a=this.map.getMapState(i),l=t.concat("#",a);this.manageMaxLengthExceed({browser:l.length>TC.Consts.URL_MAX_LENGTH,qr:l.length>this.SHORTEN_URL_LENGTH});return l};t.shortenedLink=function(){const t=this;var e;return new Promise(function(n,o){const r=function(){t.map.toast(t.getLocaleString("urlTooLongForShortener"),{type:TC.Consts.msgType.ERROR});t.map.getLoadingIndicator().removeWait(e);n("")};var i=function(){var e=t.generateLink(),n=e.indexOf("?"),o=e.indexOf("#");n>0&&(e=n<o?e.replace(e.substring(n,o),""):e.replace(e.substring(n,e.length-1),""));return e}();if(i.length>t.QR_MAX_URL_LENGTH&&i.length<t.SHORTEN_URL_LENGTH){e=t.map.getLoadingIndicator().addWait();(function(t){TC.tool&&TC.tool.Proxification||TC.syncLoadJS(TC.apiLocation+"TC/tool/Proxification");var e=new FormData;e.append("url",t);return new TC.tool.Proxification(TC.proxify,{allowedMixedContent:!1}).fetch("https://tinyurl.com/api-create.php",{type:"POST",data:e}).then(function(t){return t}).catch(function(t){return null})})(i).then(function(o){if(o&&o.responseText){t.map.getLoadingIndicator().removeWait(e);n(o.responseText.replace("http://","https://"))}else r()},r)}else{i.length>=t.SHORTEN_URL_LENGTH&&r();n("")}})};t.makeQRCode=function(t,e,n){const o=this;return new Promise(function(r,i){TC.loadJS("undefined"==typeof QRCode,[TC.apiLocation+"lib/qrcode/qrcode.min.js"],function(){o.shortenedLink().then(function(o){if((o=o||"").length>0){var i={text:o};if(e&&n){i.width=e;i.height=n}new MutationObserver(function(t,e){var n=t.filter(function(t){return"attributes"===t.type}).filter(function(t){return t.attributeName.indexOf("src")>-1});if(n.length>0){e.disconnect();r(n[0].target.src)}}).observe(t,{attributes:!0,childList:!0,subtree:!0});new QRCode(t,i)}else r()})})})};t.drawScaleBarIntoCanvas=function(t){var e,n=this.map.getControlsByClass(TC.control.ScaleBar);if(0==n.length)return null;var o=(e=(t=t||{}).canvas?t.canvas:document.createElement("CANVAS")).getContext("2d");o.save();var r,i,a=document.getElementsByClassName("ol-scale-line-inner").item(0),l=TC.Util.extend({},a.getBoundingClientRect()),s=a.textContent;o.beginPath();o.strokeStyle=window.getComputedStyle(a).borderColor;if(l.width>l.height){r=l.width;i=l.height}else{r=l.height;i=l.width}if(t.setSize){e.width=r;e.height=i}l.left=null!=t.left?t.left:15;l.top=null!=t.top?t.top:15;o.moveTo(l.left,l.top);o.lineTo(l.left,l.top+i);o.lineTo(l.left+r,l.top+i);o.lineTo(l.left+r,l.top);o.stroke();o.measureText(s);var c={x:l.left+r/2,y:l.top+i/2};t.fill&&function(e,o,r){var i=document.getElementsByClassName(n[0].CLASS).item(0),a=TC.Util.extend({},i.getBoundingClientRect());a.left=(t.left||15)-2;a.top=t.top||15;a.top--;e.globalAlpha=.5;e.fillStyle=window.getComputedStyle(i).backgroundColor;o+=4;r+=4;e.fillRect(a.left,a.top,o,r)}(o,r,i);o.globalAlpha=1;o.fillStyle=null!=t.textColor?t.textColor:window.getComputedStyle(a).color;o.font=null!=t.font?t.font:window.getComputedStyle(a).fontSize+" "+window.getComputedStyle(a).fontFamily;o.textAlign="center";o.textBaseline="middle";o.fillText(s,c.x,c.y);return e};t.registerListeners=function(){const t=this;if(!t.registeredListeners){t.map.on(TC.Consts.event.LAYERADD,t.generateLink.bind(t)).on(TC.Consts.event.LAYERREMOVE,t.generateLink.bind(t)).on(TC.Consts.event.FEATUREADD,t.generateLink.bind(t)).on(TC.Consts.event.FEATUREREMOVE+" "+TC.Consts.event.FEATURESCLEAR,t.generateLink.bind(t));t.registeredListeners=!0}}}();
  //# sourceMappingURL=../maps/control/MapInfo.min.js.map