function _slicedToArray(e,t){return _arrayWithHoles(e)||_iterableToArrayLimit(e,t)||_unsupportedIterableToArray(e,t)||_nonIterableRest()}function _nonIterableRest(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}function _unsupportedIterableToArray(e,t){var n;if(e)return"string"==typeof e?_arrayLikeToArray(e,t):"Map"===(n="Object"===(n={}.toString.call(e).slice(8,-1))&&e.constructor?e.constructor.name:n)||"Set"===n?Array.from(e):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?_arrayLikeToArray(e,t):void 0}function _arrayLikeToArray(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,i=Array(t);n<t;n++)i[n]=e[n];return i}function _iterableToArrayLimit(e,t){var n=null==e?null:"undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(null!=n){var i,r,a,o,l=[],c=!0,s=!1;try{if(a=(n=n.call(e)).next,0===t){if(Object(n)!==n)return;c=!1}else for(;!(c=(i=a.call(n)).done)&&(l.push(i.value),l.length!==t);c=!0);}catch(e){s=!0,r=e}finally{try{if(!c&&null!=n.return&&(o=n.return(),Object(o)!==o))return}finally{if(s)throw r}}return l}}function _arrayWithHoles(e){if(Array.isArray(e))return e}(()=>{function e(v,A,w,T,I,N,$){return{link:function(n){var o=[],i="c8y_Position",r=g,a=b,l=[];function e(){l.length=0,o.length=0,n.deviceId?c(n.deviceId):d()}function c(e){A.detail(e).then(I.getResData).then(t)}function t(e){l.push(e),n.multipleDevices?(e=n.deviceId,v.all([A.childDevices(e),A.childAssets(e)]).then(_.flattenDeep).then(s)):d(u(l))}function s(e){d(u(_.union(l,e)))}function u(e){return _.map(_.filter(e,function(e){return!N.isGroup(e)}),"id")}function d(e){var t={},e=e&&e.length?(t.ids=e.join(","),A.list(t)):A.list({fragmentType:i});e.then(f).then(g)}function f(e){return n.withPosition=_.filter(e,p),_.filter(_.map(n.withPosition,b),_.identity)}function m(){n.realtimeAnimation=!1}function h(e,t){w.addListener(n.$id,n.realtimeChannel,e,t)}function y(e,t){p(t)&&(a(t),r())}function p(e){return e[i]}function g(e){e&&e.length&&_.forEach(e,function(e){o.push(e)}),n.withPosition.length&&T.getMap("c8y-map-".concat(n.$id)).then(function(e){e.fitBounds(o,{padding:[50,50]})})}function b(e){var t,n=p(e),i=_.cloneDeep(n||{}),r=null,a=_.find(o,{id:e.id});return a?(n.lat=Number(n.lat),a.lat=n.lat,n.lng=Number(n.lng),a.lng=n.lng):(n.lat=Number(n.lat),i.lat=n.lat,n.lng=Number(n.lng),i.lng=n.lng,n&&_.isNumber(n.lat)&&_.isNumber(n.lng)&&!_.isNaN(_.toNumber(n.lat))&&!_.isNaN(_.toNumber(n.lng))&&(i.id=e.id,i.message='\n          <a\n            class="btn btn-link"\n            style="width: 100%; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;"\n            href="#/device/'.concat((a=e).id,'"\n            title="').concat(a.name,'"\n          >\n            ').concat(a.name,"\n          </a>\n        "),i.icon={className:"".concat((t=e.c8y_ActiveAlarmsStatus||{},_.find(["critical","major","minor","warning"],function(e){return t[e]})||"normal"),"-marker-icon"),iconSize:[25,41],iconAnchor:[12,41],type:"div"},r=i)),r}n.$watch("deviceId",function(e,t){e&&e!==t&&(l=[],o.length=0,c(e))}),n.markers=o,n.mapDefault={scrollWheelZoom:!1,tileLayerOptions:{referrerPolicy:"strict-origin-when-cross-origin"}},n.cssToHide=function(){return n.withPosition&&n.withPosition.length?{}:{visibility:"hidden"}},n.paging={refresh:!0},n.realtime||(n.refresh=e),v.all([$.listByUser(),T.getMap("c8y-map-".concat(n.$id))]).then(function(e){var e=_slicedToArray(e,2),t=e[0],e=e[1];_.some(t,{contextPath:"openseamap"})&&(t=L.tileLayer("/apps/openseamap/{z}/{x}/{y}.png"),L.control.layers({},{openseamap:t}).addTo(e))}),n.realtimeChannel="/managedobjects/*",h("".concat(n.$id,"-subscribed"),m),h("UPDATE",y),n.realtime&&(n.$on("$destroy",function(){w.stop(n.$id,n.realtimeChannel)}),w.start(n.$id,n.realtimeChannel)),e()},restrict:"E",scope:{deviceId:"=?",multipleDevices:"=",cssClass:"@",width:"=?",height:"=?",config:"=",realtime:"="},templateUrl:":::PLUGIN_PATH:::/ui/views/map.html"}}e.$inject=["$q","c8yInventory","c8yRealtime","leafletData","c8yBase","c8yGroups","c8yApplication"],angular.module("c8y.ui").directive("c8yMap",e)})();