import{LngLat as t,LngLatBounds as e}from"maplibre-gl";import{AssetModelUtil as n}from"@openremote/model";import{Util as r}from"@openremote/core";export function metersToPixelsAtMaxZoom(t,e){return t/.075/Math.cos(e*Math.PI/180)}export function getLngLat(e){if(e){if(e instanceof t)return e;if(e.lat)return e.lon?{lng:e.lon,lat:e.lat}:{lng:e.lng,lat:e.lat};if(Array.isArray(e))return{lng:e[0],lat:e[1]};if(e.coordinates&&Array.isArray(e.coordinates)&&e.coordinates.length>=2)return getLngLat(e.coordinates);if(e.attributes){let t=e.attributes.location;return t&&t.value?getLngLat(t.value):void 0}if(e.value)return getLngLat(e.value)}}export function getGeoJSONPoint(t){if(t)return Array.isArray(t)?{type:"Point",coordinates:t}:{type:"Point",coordinates:[t.hasOwnProperty("lng")?t.lng:t.lon,t.lat]}}export function getLngLatBounds(t){if(t){if(t instanceof e)return t;if(2===t.length){let n=getLngLat(t[0]),r=getLngLat(t[1]);if(n&&r)return new e(n,r)}if(4===t.length)return new e([t[0],t[1],t[2],t[3]])}}export function getMarkerIconAndColorFromAssetType(t,e){if(!t)return;let r="string"==typeof t?n.getAssetDescriptor(t):t,o=r&&r.icon?r.icon:"help-circle",i=r&&r.colour?r.colour:void 0;if(e&&e.markerConfig){let t=e.markerConfig,n=e.currentValue;if("range"===t.type&&t.ranges&&"number"==typeof n){let e=t.ranges;i=(e.sort((t,e)=>e.min-t.min).find(t=>n>=t.min)||e.reduce((t,e)=>e.min>t.min?t:e)).colour||void 0}else"boolean"===t.type?i=t[!!n+""]:"string"===t.type&&(i=t[n+""])}return{color:i,icon:o}}export function isWebglSupported(){if(window.WebGLRenderingContext){let t=document.createElement("canvas");try{let e=t.getContext("webgl2")||t.getContext("webgl");if(e&&"function"==typeof e.getParameter)return!0}catch(t){}}return!1}export function isAssetWithLocation(t){var e;if(!(null==t?void 0:t.attributes))return!1;let n=t.attributes.location;return!!(null==(e=null==n?void 0:n.value)?void 0:e.coordinates)&&(!n.meta||!("showOnDashboard"in n.meta)||!!r.getMetaValue("showOnDashboard",n))}