@maptiler/client 1.1.0 → 1.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (66) hide show
  1. package/dist/maptiler-client.cjs +122 -1
  2. package/dist/maptiler-client.cjs.map +1 -1
  3. package/dist/maptiler-client.d.ts +12 -2
  4. package/dist/maptiler-client.min.mjs +1 -1
  5. package/dist/maptiler-client.mjs +122 -1
  6. package/dist/maptiler-client.mjs.map +1 -1
  7. package/dist/maptiler-client.umd.js +122 -1
  8. package/dist/maptiler-client.umd.js.map +1 -1
  9. package/dist/maptiler-client.umd.min.js +1 -1
  10. package/docs/classes/config.ClientConfig.html +9 -9
  11. package/docs/classes/services_ServiceError.ServiceError.html +7 -7
  12. package/docs/functions/language.getAutoLanguageGeocoding.html +5 -5
  13. package/docs/functions/services_simplify.default.html +5 -5
  14. package/docs/index.html +28 -35
  15. package/docs/modules/config.html +5 -5
  16. package/docs/modules/language.html +5 -5
  17. package/docs/modules/services_ServiceError.html +5 -5
  18. package/docs/modules/services_coordinates.html +5 -5
  19. package/docs/modules/services_data.html +5 -5
  20. package/docs/modules/services_geocoding.html +5 -5
  21. package/docs/modules/services_geolocation.html +5 -5
  22. package/docs/modules/services_simplify.html +5 -5
  23. package/docs/modules/services_staticMaps.html +5 -5
  24. package/docs/modules.html +4 -4
  25. package/docs/types/config.FetchFunction.html +5 -5
  26. package/docs/types/language.LanguageGeocodingString.html +5 -5
  27. package/docs/types/services_coordinates.CoordinateExport.html +5 -5
  28. package/docs/types/services_coordinates.CoordinateGrid.html +5 -5
  29. package/docs/types/services_coordinates.CoordinateId.html +5 -5
  30. package/docs/types/services_coordinates.CoordinateSearch.html +5 -5
  31. package/docs/types/services_coordinates.CoordinateSearchResult.html +5 -5
  32. package/docs/types/services_coordinates.CoordinateTransformResult.html +5 -5
  33. package/docs/types/services_coordinates.CoordinateTransformation.html +5 -5
  34. package/docs/types/services_coordinates.CoordinatesSearchOptions.html +5 -5
  35. package/docs/types/services_coordinates.CoordinatesTransformOptions.html +5 -5
  36. package/docs/types/services_coordinates.XYZ.html +5 -5
  37. package/docs/types/services_data.GetDataOptions.html +5 -5
  38. package/docs/types/services_geocoding.Coordinates.html +5 -5
  39. package/docs/types/services_geocoding.FeatureHierarchy.html +5 -5
  40. package/docs/types/services_geocoding.GeocodingFeature.html +5 -5
  41. package/docs/types/services_geocoding.GeocodingOptions.html +5 -5
  42. package/docs/types/services_geocoding.GeocodingSearchResult.html +5 -5
  43. package/docs/types/services_geocoding.ReverseGeocodingOptions.html +5 -5
  44. package/docs/types/services_geolocation.GeolocationInfoOptions.html +5 -5
  45. package/docs/types/services_geolocation.GeolocationResult.html +5 -5
  46. package/docs/types/services_staticMaps.AutomaticStaticMapOptions.html +5 -5
  47. package/docs/types/services_staticMaps.BoundedStaticMapOptions.html +5 -5
  48. package/docs/types/services_staticMaps.CenteredStaticMapOptions.html +5 -5
  49. package/docs/types/services_staticMaps.StaticMapBaseOptions.html +5 -5
  50. package/docs/types/services_staticMaps.StaticMapMarker.html +5 -5
  51. package/docs/variables/config.config.html +5 -5
  52. package/docs/variables/language.LanguageGeocoding.html +5 -5
  53. package/docs/variables/services_coordinates.coordinates.html +5 -5
  54. package/docs/variables/services_data.data.html +5 -5
  55. package/docs/variables/services_geocoding.geocoding.html +5 -5
  56. package/docs/variables/services_geolocation.geolocation.html +5 -5
  57. package/docs/variables/services_staticMaps.staticMaps.html +5 -5
  58. package/docsmd/README.md +46 -44
  59. package/docsmd/classes/ClientConfig.md +5 -5
  60. package/docsmd/classes/MapStyleVariant.md +29 -12
  61. package/docsmd/classes/ReferenceMapStyle.md +9 -9
  62. package/docsmd/classes/ServiceError.md +3 -3
  63. package/package.json +1 -1
  64. package/readme.md +28 -28
  65. package/src/index.ts +2 -2
  66. package/src/mapstyle.ts +33 -0
@@ -1 +1 @@
1
- function V(){return typeof self<"u"?fetch.bind(self):typeof global<"u"&&global.fetch?global.fetch:null}class ${constructor(){this._apiKey="",this._fetch=V()}set apiKey(t){this._apiKey=t}get apiKey(){return this._apiKey}set fetch(t){this._fetch=t}get fetch(){return this._fetch}}const u=new $,A={AUTO:"auto",ALBANIAN:"sq",ARABIC:"ar",ARMENIAN:"hy",AZERBAIJANI:"az",BELORUSSIAN:"be",BOSNIAN:"bs",BRETON:"br",BULGARIAN:"bg",CATALAN:"ca",CHINESE:"zh",CROATIAN:"hr",CZECH:"cs",DANISH:"da",DUTCH:"nl",ENGLISH:"en",ESPERANTO:"eo",ESTONIAN:"et",FINNISH:"fi",FRENCH:"fr",FRISIAN:"fy",GEORGIAN:"ka",GERMAN:"de",GREEK:"el",HEBREW:"he",HUNGARIAN:"hu",ICELANDIC:"is",IRISH:"ga",ITALIAN:"it",JAPANESE:"ja",KANNADA:"kn",KAZAKH:"kk",KOREAN:"ko",ROMAN_LATIN:"la",LATVIAN:"lv",LITHUANIAN:"lt",LUXEMBOURGISH:"lb",MACEDONIAN:"mk",MALTESE:"mt",NORWEGIAN:"no",POLISH:"pl",PORTUGUESE:"pt",ROMANIAN:"ro",ROMANSH:"rm",RUSSIAN:"ru",SCOTTISH_GAELIC:"gd",SERBIAN_CYRILLIC:"sr",SLOVAK:"sk",SLOVENE:"sl",SPANISH:"es",SWEDISH:"sv",THAI:"th",TURKISH:"tr",UKRAINIAN:"uk",WELSH:"cy"},j=new Set(Object.values(A));function N(){if(typeof navigator>"u")return Intl.DateTimeFormat().resolvedOptions().locale.split("-")[0];const r=Array.from(new Set(navigator.languages.map(t=>t.split("-")[0]))).filter(t=>j.has(t));return r.length?r[0]:A.ENGLISH}var G=(r,t,e)=>new Promise((i,n)=>{var s=o=>{try{c(e.next(o))}catch(l){n(l)}},a=o=>{try{c(e.throw(o))}catch(l){n(l)}},c=o=>o.done?i(o.value):Promise.resolve(o.value).then(s,a);c((e=e.apply(r,t)).next())});function S(r){return G(this,arguments,function*(t,e={}){if(u.fetch===null)throw new Error("The fetch function was not found. If on NodeJS < 18 please specify the fetch function with config.fetch");if(new URL(t).searchParams.get("key").trim()==="")throw new Error("The MapTiler Cloud API key is missing. Set it in `config.apiKey` or get one for free at https://maptiler.com");return u.fetch(t,e)})}const y={maptilerApiURL:"https://api.maptiler.com/",mapStyle:"streets-v2"};Object.freeze(y);class v extends Error{constructor(t,e=""){super(`Call to enpoint ${t.url} failed with the status code ${t.status}. ${e}`),this.res=t}}var b=(r,t,e)=>new Promise((i,n)=>{var s=o=>{try{c(e.next(o))}catch(l){n(l)}},a=o=>{try{c(e.throw(o))}catch(l){n(l)}},c=o=>o.done?i(o.value):Promise.resolve(o.value).then(s,a);c((e=e.apply(r,t)).next())});const I={400:"Query too long / Invalid parameters",403:"Key is missing, invalid or restricted"};function F(r){return b(this,arguments,function*(t,e={}){var i;if(typeof t!="string"||t.trim().length===0)throw new Error("The query must be a non-empty string");const n=new URL(`geocoding/${encodeURIComponent(t)}.json`,y.maptilerApiURL);if(n.searchParams.set("key",(i=e.apiKey)!=null?i:u.apiKey),"bbox"in e&&n.searchParams.set("bbox",e.bbox.join(",")),"proximity"in e&&n.searchParams.set("proximity",e.proximity.join(",")),"language"in e){const c=Array.from(new Set((Array.isArray(e.language)?e.language:[e.language]).map(o=>o===A.AUTO?N():o))).join(",");n.searchParams.set("language",c)}const s=n.toString(),a=yield S(s);if(!a.ok)throw new v(a,a.status in I?I[a.status]:"");return yield a.json()})}function B(r){return b(this,arguments,function*(t,e={}){var i;if(!Array.isArray(t)||t.length<2)throw new Error("The position must be an array of form [lng, lat].");const n=new URL(`geocoding/${t[0]},${t[1]}.json`,y.maptilerApiURL);if(n.searchParams.set("key",(i=e.apiKey)!=null?i:u.apiKey),"language"in e){const c=Array.from(new Set((Array.isArray(e.language)?e.language:[e.language]).map(o=>o===A.AUTO?N():o))).join(",");n.searchParams.set("language",c)}const s=n.toString(),a=yield S(s);if(!a.ok)throw new v(a,a.status in I?I[a.status]:"");return yield a.json()})}const M={forward:F,reverse:B,language:A};var W=(r,t,e)=>new Promise((i,n)=>{var s=o=>{try{c(e.next(o))}catch(l){n(l)}},a=o=>{try{c(e.throw(o))}catch(l){n(l)}},c=o=>o.done?i(o.value):Promise.resolve(o.value).then(s,a);c((e=e.apply(r,t)).next())});const C={403:"Key is missing, invalid or restricted"};function _(){return W(this,arguments,function*(r={}){var t;const e=new URL("geolocation/ip.json",y.maptilerApiURL);e.searchParams.set("key",(t=r.apiKey)!=null?t:u.apiKey);const i=e.toString(),n=yield S(i);if(!n.ok)throw new v(n,n.status in C?C[n.status]:"");return yield n.json()})}const q={info:_};var K=(r,t,e)=>new Promise((i,n)=>{var s=o=>{try{c(e.next(o))}catch(l){n(l)}},a=o=>{try{c(e.throw(o))}catch(l){n(l)}},c=o=>o.done?i(o.value):Promise.resolve(o.value).then(s,a);c((e=e.apply(r,t)).next())});const L={403:"Key is missing, invalid or restricted"};function Y(r){return K(this,arguments,function*(t,e={}){var i;if(typeof t!="string"||t.trim().length===0)throw new Error("The query must be a non-empty string");const n=new URL(`coordinates/search/${t}.json`,y.maptilerApiURL);n.searchParams.set("key",(i=e.apiKey)!=null?i:u.apiKey),"limit"in e&&n.searchParams.set("limit",e.limit.toString()),"transformations"in e&&n.searchParams.set("transformations",e.transformations.toString()),"exports"in e&&n.searchParams.set("exports",e.exports.toString());const s=n.toString(),a=yield S(s);if(!a.ok)throw new v(a,a.status in L?L[a.status]:"");return yield a.json()})}function z(r){return K(this,arguments,function*(t,e={}){var i;const n=(Array.isArray(t[0])?t:[t]).map(o=>`${o[0]},${o[1]}`).join(";"),s=new URL(`coordinates/transform/${n}.json`,y.maptilerApiURL);s.searchParams.set("key",(i=e.apiKey)!=null?i:u.apiKey),"sourceCrs"in e&&s.searchParams.set("s_srs",e.sourceCrs.toString()),"targetCrs"in e&&s.searchParams.set("t_srs",e.targetCrs.toString()),"operations"in e&&s.searchParams.set("ops",(Array.isArray(e.operations)?e.operations:[e.operations]).join("|"));const a=s.toString(),c=yield S(a);if(!c.ok)throw new v(c,c.status in L?L[c.status]:"");return yield c.json()})}const J={search:Y,transform:z};var Z=(r,t,e)=>new Promise((i,n)=>{var s=o=>{try{c(e.next(o))}catch(l){n(l)}},a=o=>{try{c(e.throw(o))}catch(l){n(l)}},c=o=>o.done?i(o.value):Promise.resolve(o.value).then(s,a);c((e=e.apply(r,t)).next())});const O={403:"Key is missing, invalid or restricted"};function Q(r){return Z(this,arguments,function*(t,e={}){var i;if(typeof t!="string"||t.trim().length===0)throw new Error("The data ID must be a non-empty string");const n=new URL(`data/${encodeURIComponent(t)}/features.json`,y.maptilerApiURL);n.searchParams.set("key",(i=e.apiKey)!=null?i:u.apiKey);const s=n.toString(),a=yield S(s);if(!a.ok)throw new v(a,a.status in O?O[a.status]:"");return yield a.json()})}const X={get:Q};class k{constructor(t,e,i,n,s,a){this.name=t,this.variantType=e,this.id=i,this.referenceStyle=n,this.description=s,this.imageURL=a}getName(){return this.name}getFullName(){return`${this.referenceStyle.getName()} ${this.name}`}getType(){return this.variantType}getId(){return this.id}getDescription(){return this.description}getReferenceStyle(){return this.referenceStyle}hasVariant(t){return this.referenceStyle.hasVariant(t)}getVariant(t){return this.referenceStyle.getVariant(t)}getVariants(){return this.referenceStyle.getVariants().filter(t=>t!==this)}getImageURL(){return this.imageURL}}class D{constructor(t,e){this.name=t,this.id=e,this.variants={},this.orderedVariants=[]}getName(){return this.name}getId(){return this.id}addVariant(t){this.variants[t.getType()]=t,this.orderedVariants.push(t)}hasVariant(t){return t in this.variants}getVariant(t){return t in this.variants?this.variants[t]:this.orderedVariants[0]}getVariants(){return Object.values(this.variants)}getDefaultVariant(){return this.orderedVariants[0]}}const R=[{referenceStyleID:"STREETS",name:"Streets",description:"",variants:[{id:"streets-v2",name:"Default",variantType:"DEFAULT",description:"",imageURL:""},{id:"streets-v2-dark",name:"Dark",variantType:"DARK",description:"",imageURL:""},{id:"streets-v2-light",name:"Light",variantType:"LIGHT",description:"",imageURL:""},{id:"streets-v2-pastel",name:"Pastel",variantType:"PASTEL",description:"",imageURL:""}]},{referenceStyleID:"OUTDOOR",name:"Outdoor",description:"",variants:[{id:"outdoor-v2",name:"Default",variantType:"DEFAULT",description:"",imageURL:""}]},{referenceStyleID:"WINTER",name:"Winter",description:"",variants:[{id:"winter-v2",name:"Winter",variantType:"DEFAULT",description:"",imageURL:""}]},{referenceStyleID:"SATELLITE",name:"Satellite",description:"",variants:[{id:"satellite",name:"Default",variantType:"DEFAULT",description:"",imageURL:""}]},{referenceStyleID:"HYBRID",name:"Hybrid",description:"",variants:[{id:"hybrid",name:"Default",variantType:"DEFAULT",description:"",imageURL:""}]},{referenceStyleID:"BASIC",name:"Basic",description:"",variants:[{id:"basic-v2",name:"Default",variantType:"DEFAULT",description:"",imageURL:""},{id:"basic-v2-dark",name:"Dark",variantType:"DARK",description:"",imageURL:""},{id:"basic-v2-light",name:"Light",variantType:"LIGHT",description:"",imageURL:""}]},{referenceStyleID:"BRIGHT",name:"Bright",description:"",variants:[{id:"bright-v2",name:"Default",variantType:"DEFAULT",description:"",imageURL:""},{id:"bright-v2-dark",name:"Dark",variantType:"DARK",description:"",imageURL:""},{id:"bright-v2-light",name:"Light",variantType:"LIGHT",description:"",imageURL:""},{id:"bright-v2-pastel",name:"Pastel",variantType:"PASTEL",description:"",imageURL:""}]},{referenceStyleID:"OPENSTREETMAP",name:"OpenStreetMap",description:"",variants:[{id:"openstreetmap",name:"Default",variantType:"DEFAULT",description:"",imageURL:""}]},{referenceStyleID:"TOPO",name:"Topo",description:"",variants:[{id:"topo-v2",name:"Default",variantType:"DEFAULT",description:"",imageURL:""},{id:"topo-v2-shiny",name:"Shiny",variantType:"SHINY",description:"",imageURL:""},{id:"topo-v2-pastel",name:"Pastel",variantType:"PASTEL",description:"",imageURL:""},{id:"topo-v2-topographique",name:"Topographique",variantType:"TOPOGRAPHIQUE",description:"",imageURL:""}]},{referenceStyleID:"VOYAGER",name:"Voyager",description:"",variants:[{id:"voyager-v2",name:"Default",variantType:"DEFAULT",description:"",imageURL:""},{id:"voyager-v2-darkmatter",name:"Darkmatter",variantType:"DARK",description:"",imageURL:""},{id:"voyager-v2-positron",name:"Positron",variantType:"LIGHT",description:"",imageURL:""},{id:"voyager-v2-vintage",name:"Vintage",variantType:"VINTAGE",description:"",imageURL:""}]},{referenceStyleID:"TONER",name:"Toner",description:"",variants:[{id:"toner-v2",name:"Default",variantType:"DEFAULT",description:"",imageURL:""},{id:"toner-v2-background",name:"Background",variantType:"BACKGROUND",description:"",imageURL:""},{id:"toner-v2-lite",name:"Lite",variantType:"LITE",description:"",imageURL:""},{id:"toner-v2-lines",name:"Lines",variantType:"LINES",description:"",imageURL:""}]},{referenceStyleID:"STAGE",name:"Stage",description:"",variants:[{id:"stage",name:"Default",variantType:"DEFAULT",description:"",imageURL:""},{id:"stage-dark",name:"Dark",variantType:"DARK",description:"",imageURL:""},{id:"stage-light",name:"Light",variantType:"LIGHT",description:"",imageURL:""}]},{referenceStyleID:"OCEAN",name:"Ocean",description:"",variants:[{id:"ocean",name:"Default",variantType:"DEFAULT",description:"",imageURL:""}]}];function ee(r){return new Proxy(r,{get(t,e,i){return t.hasVariant(e)?t.getVariant(e):e.toString().toUpperCase()===e?r.getDefaultVariant():Reflect.get(t,e,i)}})}function te(){const r={};for(let t=0;t<R.length;t+=1){const e=R[t],i=ee(new D(e.name,e.referenceStyleID));for(let n=0;n<e.variants.length;n+=1){const s=e.variants[n],a=new k(s.name,s.variantType,s.id,i,s.description,s.imageURL);i.addVariant(a)}r[e.referenceStyleID]=i}return r}function T(r){if(!r)return H[R[0].referenceStyleID].getDefaultVariant().getId();if(typeof r=="string"||r instanceof String)return r.trim().toLowerCase();if(r instanceof k)return r.getId();if(r instanceof D)return r.getDefaultVariant().getId()}const H=te();function re(r,t,e){let i=t[0],n=t[1],s=e[0]-i,a=e[1]-n;if(s!==0||a!==0){const c=((r[0]-i)*s+(r[1]-n)*a)/(s*s+a*a);c>1?(i=e[0],n=e[1]):c>0&&(i+=s*c,n+=a*c)}return s=r[0]-i,a=r[1]-n,s*s+a*a}function E(r,t,e,i,n){let s=i,a;for(let c=t+1;c<e;c++){const o=re(r[c],r[t],r[e]);o>s&&(a=c,s=o)}s>i&&(a-t>1&&E(r,t,a,i,n),n.push(r[a]),e-a>1&&E(r,a,e,i,n))}function ne(r,t){const e=r.length-1,i=[r[0]];return E(r,0,e,t,i),i.push(r[e]),i}function ae(r,t){if(r.length<=2)return r;const e=t!==void 0?t*t:1;return ne(r,e)}function P(r,t=!0){let e=`${r[0]},${r[1]}`;return r.length===3&&t&&(e+=`,${r[2]}`),e}function w(r,t=3e3){let e=r.map(s=>s.join(",")).join("|"),i=5e-6;const n=1e-5;for(;e.length>t;)e=ae(r,i).map(s=>`${s[0]},${s[1]}`).join("|"),i+=n;return e}function ie(r,t,e={}){var i,n,s,a,c;const o=T(e.style),l=e.hiDPI?"@2x":"",f=(i=e.format)!=null?i:"png";let g=~~((n=e.width)!=null?n:1024),m=~~((s=e.height)!=null?s:1024);e.hiDPI&&(g=~~(g/2),m=~~(m/2));const p=new URL(`maps/${encodeURIComponent(o)}/static/${r[0]},${r[1]},${t}/${g}x${m}${l}.${f}`,y.maptilerApiURL);if("attribution"in e&&p.searchParams.set("attribution",e.attribution.toString()),"markers"in e){let h="";const d="markerIcon"in e;d&&(h+=`icon:${e.markerIcon}|`),d&&"markerAnchor"in e&&(h+=`anchor:${e.markerAnchor}|`),d&&e.hiDPI&&(h+="scale:2|");const U=Array.isArray(e.markers[0])?e.markers:[e.markers];h+=U.map(x=>P(x,!d)).join("|"),p.searchParams.set("markers",h)}if("path"in e){let h="";if(h+=`fill:${(a=e.pathFillColor)!=null?a:"none"}|`,"pathStrokeColor"in e&&(h+=`stroke:${e.pathStrokeColor}|`),"pathWidth"in e){const d=e.pathWidth/(e.hiDPI?2:1);h+=`width:${d.toString()}|`}h+=w(e.path),p.searchParams.set("path",h)}return p.searchParams.set("key",(c=e.apiKey)!=null?c:u.apiKey),p.toString()}function se(r,t={}){var e,i,n,s,a;const c=T(t.style),o=t.hiDPI?"@2x":"",l=(e=t.format)!=null?e:"png";let f=~~((i=t.width)!=null?i:1024),g=~~((n=t.height)!=null?n:1024);t.hiDPI&&(f=~~(f/2),g=~~(g/2));const m=new URL(`maps/${encodeURIComponent(c)}/static/${r[0]},${r[1]},${r[2]},${r[3]}/${f}x${g}${o}.${l}`,y.maptilerApiURL);if("attribution"in t&&m.searchParams.set("attribution",t.attribution.toString()),"padding"in t&&m.searchParams.set("padding",t.padding.toString()),"markers"in t){let p="";const h="markerIcon"in t;h&&(p+=`icon:${t.markerIcon}|`),h&&"markerAnchor"in t&&(p+=`anchor:${t.markerAnchor}|`),h&&t.hiDPI&&(p+="scale:2|");const d=Array.isArray(t.markers[0])?t.markers:[t.markers];p+=d.map(U=>P(U,!h)).join("|"),m.searchParams.set("markers",p)}if("path"in t){let p="";if(p+=`fill:${(s=t.pathFillColor)!=null?s:"none"}|`,"pathStrokeColor"in t&&(p+=`stroke:${t.pathStrokeColor}|`),"pathWidth"in t){const h=t.pathWidth/(t.hiDPI?2:1);p+=`width:${h.toString()}|`}p+=w(t.path),m.searchParams.set("path",p)}return m.searchParams.set("key",(a=t.apiKey)!=null?a:u.apiKey),m.toString()}function oe(r={}){var t,e,i,n,s;if(!("markers"in r)&&!("path"in r))throw new Error("Automatic static maps require markers and/or path to be created.");const a=T(r.style),c=r.hiDPI?"@2x":"",o=(t=r.format)!=null?t:"png";let l=~~((e=r.width)!=null?e:1024),f=~~((i=r.height)!=null?i:1024);r.hiDPI&&(l=~~(l/2),f=~~(f/2));const g=new URL(`maps/${encodeURIComponent(a)}/static/auto/${l}x${f}${c}.${o}`,y.maptilerApiURL);if("attribution"in r&&g.searchParams.set("attribution",r.attribution.toString()),"padding"in r&&g.searchParams.set("padding",r.padding.toString()),"markers"in r){let m="";const p="markerIcon"in r;p&&(m+=`icon:${r.markerIcon}|`),p&&"markerAnchor"in r&&(m+=`anchor:${r.markerAnchor}|`),p&&r.hiDPI&&(m+="scale:2|");const h=Array.isArray(r.markers[0])?r.markers:[r.markers];m+=h.map(d=>P(d,!p)).join("|"),g.searchParams.set("markers",m)}if("path"in r){let m="";if(m+=`fill:${(n=r.pathFillColor)!=null?n:"none"}|`,"pathStrokeColor"in r&&(m+=`stroke:${r.pathStrokeColor}|`),"pathWidth"in r){const p=r.pathWidth/(r.hiDPI?2:1);m+=`width:${p.toString()}|`}m+=w(r.path),g.searchParams.set("path",m)}return g.searchParams.set("key",(s=r.apiKey)!=null?s:u.apiKey),g.toString()}const ce={centered:ie,bounded:se,automatic:oe};export{$ as ClientConfig,A as LanguageGeocoding,H as MapStyle,k as MapStyleVariant,D as ReferenceMapStyle,v as ServiceError,u as config,J as coordinates,X as data,M as geocoding,q as geolocation,R as mapStylePresetList,ce as staticMaps,T as styleToStyle};
1
+ function V(){return typeof self<"u"?fetch.bind(self):typeof global<"u"&&global.fetch?global.fetch:null}class w{constructor(){this._apiKey="",this._fetch=V()}set apiKey(t){this._apiKey=t}get apiKey(){return this._apiKey}set fetch(t){this._fetch=t}get fetch(){return this._fetch}}const u=new w,A={AUTO:"auto",ALBANIAN:"sq",ARABIC:"ar",ARMENIAN:"hy",AZERBAIJANI:"az",BELORUSSIAN:"be",BOSNIAN:"bs",BRETON:"br",BULGARIAN:"bg",CATALAN:"ca",CHINESE:"zh",CROATIAN:"hr",CZECH:"cs",DANISH:"da",DUTCH:"nl",ENGLISH:"en",ESPERANTO:"eo",ESTONIAN:"et",FINNISH:"fi",FRENCH:"fr",FRISIAN:"fy",GEORGIAN:"ka",GERMAN:"de",GREEK:"el",HEBREW:"he",HUNGARIAN:"hu",ICELANDIC:"is",IRISH:"ga",ITALIAN:"it",JAPANESE:"ja",KANNADA:"kn",KAZAKH:"kk",KOREAN:"ko",ROMAN_LATIN:"la",LATVIAN:"lv",LITHUANIAN:"lt",LUXEMBOURGISH:"lb",MACEDONIAN:"mk",MALTESE:"mt",NORWEGIAN:"no",POLISH:"pl",PORTUGUESE:"pt",ROMANIAN:"ro",ROMANSH:"rm",RUSSIAN:"ru",SCOTTISH_GAELIC:"gd",SERBIAN_CYRILLIC:"sr",SLOVAK:"sk",SLOVENE:"sl",SPANISH:"es",SWEDISH:"sv",THAI:"th",TURKISH:"tr",UKRAINIAN:"uk",WELSH:"cy"},G=new Set(Object.values(A));function N(){if(typeof navigator>"u")return Intl.DateTimeFormat().resolvedOptions().locale.split("-")[0];const r=Array.from(new Set(navigator.languages.map(t=>t.split("-")[0]))).filter(t=>G.has(t));return r.length?r[0]:A.ENGLISH}var F=(r,t,e)=>new Promise((a,n)=>{var s=o=>{try{c(e.next(o))}catch(l){n(l)}},i=o=>{try{c(e.throw(o))}catch(l){n(l)}},c=o=>o.done?a(o.value):Promise.resolve(o.value).then(s,i);c((e=e.apply(r,t)).next())});function S(r){return F(this,arguments,function*(t,e={}){if(u.fetch===null)throw new Error("The fetch function was not found. If on NodeJS < 18 please specify the fetch function with config.fetch");if(new URL(t).searchParams.get("key").trim()==="")throw new Error("The MapTiler Cloud API key is missing. Set it in `config.apiKey` or get one for free at https://maptiler.com");return u.fetch(t,e)})}const y={maptilerApiURL:"https://api.maptiler.com/",mapStyle:"streets-v2"};Object.freeze(y);class v extends Error{constructor(t,e=""){super(`Call to enpoint ${t.url} failed with the status code ${t.status}. ${e}`),this.res=t}}var b=(r,t,e)=>new Promise((a,n)=>{var s=o=>{try{c(e.next(o))}catch(l){n(l)}},i=o=>{try{c(e.throw(o))}catch(l){n(l)}},c=o=>o.done?a(o.value):Promise.resolve(o.value).then(s,i);c((e=e.apply(r,t)).next())});const I={400:"Query too long / Invalid parameters",403:"Key is missing, invalid or restricted"};function B(r){return b(this,arguments,function*(t,e={}){var a;if(typeof t!="string"||t.trim().length===0)throw new Error("The query must be a non-empty string");const n=new URL(`geocoding/${encodeURIComponent(t)}.json`,y.maptilerApiURL);if(n.searchParams.set("key",(a=e.apiKey)!=null?a:u.apiKey),"bbox"in e&&n.searchParams.set("bbox",e.bbox.join(",")),"proximity"in e&&n.searchParams.set("proximity",e.proximity.join(",")),"language"in e){const c=Array.from(new Set((Array.isArray(e.language)?e.language:[e.language]).map(o=>o===A.AUTO?N():o))).join(",");n.searchParams.set("language",c)}const s=n.toString(),i=yield S(s);if(!i.ok)throw new v(i,i.status in I?I[i.status]:"");return yield i.json()})}function M(r){return b(this,arguments,function*(t,e={}){var a;if(!Array.isArray(t)||t.length<2)throw new Error("The position must be an array of form [lng, lat].");const n=new URL(`geocoding/${t[0]},${t[1]}.json`,y.maptilerApiURL);if(n.searchParams.set("key",(a=e.apiKey)!=null?a:u.apiKey),"language"in e){const c=Array.from(new Set((Array.isArray(e.language)?e.language:[e.language]).map(o=>o===A.AUTO?N():o))).join(",");n.searchParams.set("language",c)}const s=n.toString(),i=yield S(s);if(!i.ok)throw new v(i,i.status in I?I[i.status]:"");return yield i.json()})}const W={forward:B,reverse:M,language:A};var _=(r,t,e)=>new Promise((a,n)=>{var s=o=>{try{c(e.next(o))}catch(l){n(l)}},i=o=>{try{c(e.throw(o))}catch(l){n(l)}},c=o=>o.done?a(o.value):Promise.resolve(o.value).then(s,i);c((e=e.apply(r,t)).next())});const C={403:"Key is missing, invalid or restricted"};function q(){return _(this,arguments,function*(r={}){var t;const e=new URL("geolocation/ip.json",y.maptilerApiURL);e.searchParams.set("key",(t=r.apiKey)!=null?t:u.apiKey);const a=e.toString(),n=yield S(a);if(!n.ok)throw new v(n,n.status in C?C[n.status]:"");return yield n.json()})}const Y={info:q};var K=(r,t,e)=>new Promise((a,n)=>{var s=o=>{try{c(e.next(o))}catch(l){n(l)}},i=o=>{try{c(e.throw(o))}catch(l){n(l)}},c=o=>o.done?a(o.value):Promise.resolve(o.value).then(s,i);c((e=e.apply(r,t)).next())});const L={403:"Key is missing, invalid or restricted"};function z(r){return K(this,arguments,function*(t,e={}){var a;if(typeof t!="string"||t.trim().length===0)throw new Error("The query must be a non-empty string");const n=new URL(`coordinates/search/${t}.json`,y.maptilerApiURL);n.searchParams.set("key",(a=e.apiKey)!=null?a:u.apiKey),"limit"in e&&n.searchParams.set("limit",e.limit.toString()),"transformations"in e&&n.searchParams.set("transformations",e.transformations.toString()),"exports"in e&&n.searchParams.set("exports",e.exports.toString());const s=n.toString(),i=yield S(s);if(!i.ok)throw new v(i,i.status in L?L[i.status]:"");return yield i.json()})}function J(r){return K(this,arguments,function*(t,e={}){var a;const n=(Array.isArray(t[0])?t:[t]).map(o=>`${o[0]},${o[1]}`).join(";"),s=new URL(`coordinates/transform/${n}.json`,y.maptilerApiURL);s.searchParams.set("key",(a=e.apiKey)!=null?a:u.apiKey),"sourceCrs"in e&&s.searchParams.set("s_srs",e.sourceCrs.toString()),"targetCrs"in e&&s.searchParams.set("t_srs",e.targetCrs.toString()),"operations"in e&&s.searchParams.set("ops",(Array.isArray(e.operations)?e.operations:[e.operations]).join("|"));const i=s.toString(),c=yield S(i);if(!c.ok)throw new v(c,c.status in L?L[c.status]:"");return yield c.json()})}const Z={search:z,transform:J};var Q=(r,t,e)=>new Promise((a,n)=>{var s=o=>{try{c(e.next(o))}catch(l){n(l)}},i=o=>{try{c(e.throw(o))}catch(l){n(l)}},c=o=>o.done?a(o.value):Promise.resolve(o.value).then(s,i);c((e=e.apply(r,t)).next())});const O={403:"Key is missing, invalid or restricted"};function X(r){return Q(this,arguments,function*(t,e={}){var a;if(typeof t!="string"||t.trim().length===0)throw new Error("The data ID must be a non-empty string");const n=new URL(`data/${encodeURIComponent(t)}/features.json`,y.maptilerApiURL);n.searchParams.set("key",(a=e.apiKey)!=null?a:u.apiKey);const s=n.toString(),i=yield S(s);if(!i.ok)throw new v(i,i.status in O?O[i.status]:"");return yield i.json()})}const ee={get:X};function x(r){const t=/^maptiler:\/\/(.*)/;let e;const a=r.trim();let n;return a.startsWith("http://")||a.startsWith("https://")?n=a:(e=t.exec(a))!==null?n=`https://api.maptiler.com/maps/${e[1]}/style.json`:n=`https://api.maptiler.com/maps/${a}/style.json`,n}class U{constructor(t,e,a,n,s,i){this.name=t,this.variantType=e,this.id=a,this.referenceStyle=n,this.description=s,this.imageURL=i}getName(){return this.name}getFullName(){return`${this.referenceStyle.getName()} ${this.name}`}getType(){return this.variantType}getId(){return this.id}getDescription(){return this.description}getReferenceStyle(){return this.referenceStyle}hasVariant(t){return this.referenceStyle.hasVariant(t)}getVariant(t){return this.referenceStyle.getVariant(t)}getVariants(){return this.referenceStyle.getVariants().filter(t=>t!==this)}getImageURL(){return this.imageURL}getExpandedStyleURL(){return x(this.getId())}}class k{constructor(t,e){this.name=t,this.id=e,this.variants={},this.orderedVariants=[]}getName(){return this.name}getId(){return this.id}addVariant(t){this.variants[t.getType()]=t,this.orderedVariants.push(t)}hasVariant(t){return t in this.variants}getVariant(t){return t in this.variants?this.variants[t]:this.orderedVariants[0]}getVariants(){return Object.values(this.variants)}getDefaultVariant(){return this.orderedVariants[0]}}const R=[{referenceStyleID:"STREETS",name:"Streets",description:"",variants:[{id:"streets-v2",name:"Default",variantType:"DEFAULT",description:"",imageURL:""},{id:"streets-v2-dark",name:"Dark",variantType:"DARK",description:"",imageURL:""},{id:"streets-v2-light",name:"Light",variantType:"LIGHT",description:"",imageURL:""},{id:"streets-v2-pastel",name:"Pastel",variantType:"PASTEL",description:"",imageURL:""}]},{referenceStyleID:"OUTDOOR",name:"Outdoor",description:"",variants:[{id:"outdoor-v2",name:"Default",variantType:"DEFAULT",description:"",imageURL:""}]},{referenceStyleID:"WINTER",name:"Winter",description:"",variants:[{id:"winter-v2",name:"Winter",variantType:"DEFAULT",description:"",imageURL:""}]},{referenceStyleID:"SATELLITE",name:"Satellite",description:"",variants:[{id:"satellite",name:"Default",variantType:"DEFAULT",description:"",imageURL:""}]},{referenceStyleID:"HYBRID",name:"Hybrid",description:"",variants:[{id:"hybrid",name:"Default",variantType:"DEFAULT",description:"",imageURL:""}]},{referenceStyleID:"BASIC",name:"Basic",description:"",variants:[{id:"basic-v2",name:"Default",variantType:"DEFAULT",description:"",imageURL:""},{id:"basic-v2-dark",name:"Dark",variantType:"DARK",description:"",imageURL:""},{id:"basic-v2-light",name:"Light",variantType:"LIGHT",description:"",imageURL:""}]},{referenceStyleID:"BRIGHT",name:"Bright",description:"",variants:[{id:"bright-v2",name:"Default",variantType:"DEFAULT",description:"",imageURL:""},{id:"bright-v2-dark",name:"Dark",variantType:"DARK",description:"",imageURL:""},{id:"bright-v2-light",name:"Light",variantType:"LIGHT",description:"",imageURL:""},{id:"bright-v2-pastel",name:"Pastel",variantType:"PASTEL",description:"",imageURL:""}]},{referenceStyleID:"OPENSTREETMAP",name:"OpenStreetMap",description:"",variants:[{id:"openstreetmap",name:"Default",variantType:"DEFAULT",description:"",imageURL:""}]},{referenceStyleID:"TOPO",name:"Topo",description:"",variants:[{id:"topo-v2",name:"Default",variantType:"DEFAULT",description:"",imageURL:""},{id:"topo-v2-shiny",name:"Shiny",variantType:"SHINY",description:"",imageURL:""},{id:"topo-v2-pastel",name:"Pastel",variantType:"PASTEL",description:"",imageURL:""},{id:"topo-v2-topographique",name:"Topographique",variantType:"TOPOGRAPHIQUE",description:"",imageURL:""}]},{referenceStyleID:"VOYAGER",name:"Voyager",description:"",variants:[{id:"voyager-v2",name:"Default",variantType:"DEFAULT",description:"",imageURL:""},{id:"voyager-v2-darkmatter",name:"Darkmatter",variantType:"DARK",description:"",imageURL:""},{id:"voyager-v2-positron",name:"Positron",variantType:"LIGHT",description:"",imageURL:""},{id:"voyager-v2-vintage",name:"Vintage",variantType:"VINTAGE",description:"",imageURL:""}]},{referenceStyleID:"TONER",name:"Toner",description:"",variants:[{id:"toner-v2",name:"Default",variantType:"DEFAULT",description:"",imageURL:""},{id:"toner-v2-background",name:"Background",variantType:"BACKGROUND",description:"",imageURL:""},{id:"toner-v2-lite",name:"Lite",variantType:"LITE",description:"",imageURL:""},{id:"toner-v2-lines",name:"Lines",variantType:"LINES",description:"",imageURL:""}]},{referenceStyleID:"STAGE",name:"Stage",description:"",variants:[{id:"stage",name:"Default",variantType:"DEFAULT",description:"",imageURL:""},{id:"stage-dark",name:"Dark",variantType:"DARK",description:"",imageURL:""},{id:"stage-light",name:"Light",variantType:"LIGHT",description:"",imageURL:""}]},{referenceStyleID:"OCEAN",name:"Ocean",description:"",variants:[{id:"ocean",name:"Default",variantType:"DEFAULT",description:"",imageURL:""}]}];function te(r){return new Proxy(r,{get(t,e,a){return t.hasVariant(e)?t.getVariant(e):e.toString().toUpperCase()===e?r.getDefaultVariant():Reflect.get(t,e,a)}})}function re(){const r={};for(let t=0;t<R.length;t+=1){const e=R[t],a=te(new k(e.name,e.referenceStyleID));for(let n=0;n<e.variants.length;n+=1){const s=e.variants[n],i=new U(s.name,s.variantType,s.id,a,s.description,s.imageURL);a.addVariant(i)}r[e.referenceStyleID]=a}return r}function D(r){if(!r)return H[R[0].referenceStyleID].getDefaultVariant().getId();if(typeof r=="string"||r instanceof String)return r.trim().toLowerCase();if(r instanceof U)return r.getId();if(r instanceof k)return r.getDefaultVariant().getId()}const H=re();function ne(r,t,e){let a=t[0],n=t[1],s=e[0]-a,i=e[1]-n;if(s!==0||i!==0){const c=((r[0]-a)*s+(r[1]-n)*i)/(s*s+i*i);c>1?(a=e[0],n=e[1]):c>0&&(a+=s*c,n+=i*c)}return s=r[0]-a,i=r[1]-n,s*s+i*i}function E(r,t,e,a,n){let s=a,i;for(let c=t+1;c<e;c++){const o=ne(r[c],r[t],r[e]);o>s&&(i=c,s=o)}s>a&&(i-t>1&&E(r,t,i,a,n),n.push(r[i]),e-i>1&&E(r,i,e,a,n))}function ae(r,t){const e=r.length-1,a=[r[0]];return E(r,0,e,t,a),a.push(r[e]),a}function ie(r,t){if(r.length<=2)return r;const e=t!==void 0?t*t:1;return ae(r,e)}function P(r,t=!0){let e=`${r[0]},${r[1]}`;return r.length===3&&t&&(e+=`,${r[2]}`),e}function $(r,t=3e3){let e=r.map(s=>s.join(",")).join("|"),a=5e-6;const n=1e-5;for(;e.length>t;)e=ie(r,a).map(s=>`${s[0]},${s[1]}`).join("|"),a+=n;return e}function se(r,t,e={}){var a,n,s,i,c;const o=D(e.style),l=e.hiDPI?"@2x":"",f=(a=e.format)!=null?a:"png";let g=~~((n=e.width)!=null?n:1024),m=~~((s=e.height)!=null?s:1024);e.hiDPI&&(g=~~(g/2),m=~~(m/2));const p=new URL(`maps/${encodeURIComponent(o)}/static/${r[0]},${r[1]},${t}/${g}x${m}${l}.${f}`,y.maptilerApiURL);if("attribution"in e&&p.searchParams.set("attribution",e.attribution.toString()),"markers"in e){let h="";const d="markerIcon"in e;d&&(h+=`icon:${e.markerIcon}|`),d&&"markerAnchor"in e&&(h+=`anchor:${e.markerAnchor}|`),d&&e.hiDPI&&(h+="scale:2|");const T=Array.isArray(e.markers[0])?e.markers:[e.markers];h+=T.map(j=>P(j,!d)).join("|"),p.searchParams.set("markers",h)}if("path"in e){let h="";if(h+=`fill:${(i=e.pathFillColor)!=null?i:"none"}|`,"pathStrokeColor"in e&&(h+=`stroke:${e.pathStrokeColor}|`),"pathWidth"in e){const d=e.pathWidth/(e.hiDPI?2:1);h+=`width:${d.toString()}|`}h+=$(e.path),p.searchParams.set("path",h)}return p.searchParams.set("key",(c=e.apiKey)!=null?c:u.apiKey),p.toString()}function oe(r,t={}){var e,a,n,s,i;const c=D(t.style),o=t.hiDPI?"@2x":"",l=(e=t.format)!=null?e:"png";let f=~~((a=t.width)!=null?a:1024),g=~~((n=t.height)!=null?n:1024);t.hiDPI&&(f=~~(f/2),g=~~(g/2));const m=new URL(`maps/${encodeURIComponent(c)}/static/${r[0]},${r[1]},${r[2]},${r[3]}/${f}x${g}${o}.${l}`,y.maptilerApiURL);if("attribution"in t&&m.searchParams.set("attribution",t.attribution.toString()),"padding"in t&&m.searchParams.set("padding",t.padding.toString()),"markers"in t){let p="";const h="markerIcon"in t;h&&(p+=`icon:${t.markerIcon}|`),h&&"markerAnchor"in t&&(p+=`anchor:${t.markerAnchor}|`),h&&t.hiDPI&&(p+="scale:2|");const d=Array.isArray(t.markers[0])?t.markers:[t.markers];p+=d.map(T=>P(T,!h)).join("|"),m.searchParams.set("markers",p)}if("path"in t){let p="";if(p+=`fill:${(s=t.pathFillColor)!=null?s:"none"}|`,"pathStrokeColor"in t&&(p+=`stroke:${t.pathStrokeColor}|`),"pathWidth"in t){const h=t.pathWidth/(t.hiDPI?2:1);p+=`width:${h.toString()}|`}p+=$(t.path),m.searchParams.set("path",p)}return m.searchParams.set("key",(i=t.apiKey)!=null?i:u.apiKey),m.toString()}function ce(r={}){var t,e,a,n,s;if(!("markers"in r)&&!("path"in r))throw new Error("Automatic static maps require markers and/or path to be created.");const i=D(r.style),c=r.hiDPI?"@2x":"",o=(t=r.format)!=null?t:"png";let l=~~((e=r.width)!=null?e:1024),f=~~((a=r.height)!=null?a:1024);r.hiDPI&&(l=~~(l/2),f=~~(f/2));const g=new URL(`maps/${encodeURIComponent(i)}/static/auto/${l}x${f}${c}.${o}`,y.maptilerApiURL);if("attribution"in r&&g.searchParams.set("attribution",r.attribution.toString()),"padding"in r&&g.searchParams.set("padding",r.padding.toString()),"markers"in r){let m="";const p="markerIcon"in r;p&&(m+=`icon:${r.markerIcon}|`),p&&"markerAnchor"in r&&(m+=`anchor:${r.markerAnchor}|`),p&&r.hiDPI&&(m+="scale:2|");const h=Array.isArray(r.markers[0])?r.markers:[r.markers];m+=h.map(d=>P(d,!p)).join("|"),g.searchParams.set("markers",m)}if("path"in r){let m="";if(m+=`fill:${(n=r.pathFillColor)!=null?n:"none"}|`,"pathStrokeColor"in r&&(m+=`stroke:${r.pathStrokeColor}|`),"pathWidth"in r){const p=r.pathWidth/(r.hiDPI?2:1);m+=`width:${p.toString()}|`}m+=$(r.path),g.searchParams.set("path",m)}return g.searchParams.set("key",(s=r.apiKey)!=null?s:u.apiKey),g.toString()}const le={centered:se,bounded:oe,automatic:ce};export{w as ClientConfig,A as LanguageGeocoding,H as MapStyle,U as MapStyleVariant,k as ReferenceMapStyle,v as ServiceError,u as config,Z as coordinates,ee as data,x as expandMapStyle,W as geocoding,Y as geolocation,R as mapStylePresetList,le as staticMaps};
@@ -9,18 +9,37 @@ function tryGettingFetch() {
9
9
  }
10
10
  class ClientConfig {
11
11
  constructor() {
12
+ /**
13
+ * MapTiler Cloud API key
14
+ */
12
15
  this._apiKey = "";
16
+ /**
17
+ * The fetch function. To be set if in Node < 18, otherwise
18
+ * will be automatically resolved.
19
+ */
13
20
  this._fetch = tryGettingFetch();
14
21
  }
22
+ /**
23
+ * Set the MapTiler Cloud API key
24
+ */
15
25
  set apiKey(k) {
16
26
  this._apiKey = k;
17
27
  }
28
+ /**
29
+ * Get the MapTiler Cloud API key
30
+ */
18
31
  get apiKey() {
19
32
  return this._apiKey;
20
33
  }
34
+ /**
35
+ * Set a the custom fetch function to replace the default one
36
+ */
21
37
  set fetch(f) {
22
38
  this._fetch = f;
23
39
  }
40
+ /**
41
+ * Get the fetch fucntion
42
+ */
24
43
  get fetch() {
25
44
  return this._fetch;
26
45
  }
@@ -438,6 +457,20 @@ const data = {
438
457
  get
439
458
  };
440
459
 
460
+ function expandMapStyle(style) {
461
+ const maptilerDomainRegex = /^maptiler:\/\/(.*)/;
462
+ let match;
463
+ const trimmed = style.trim();
464
+ let expandedStyle;
465
+ if (trimmed.startsWith("http://") || trimmed.startsWith("https://")) {
466
+ expandedStyle = trimmed;
467
+ } else if ((match = maptilerDomainRegex.exec(trimmed)) !== null) {
468
+ expandedStyle = `https://api.maptiler.com/maps/${match[1]}/style.json`;
469
+ } else {
470
+ expandedStyle = `https://api.maptiler.com/maps/${trimmed}/style.json`;
471
+ }
472
+ return expandedStyle;
473
+ }
441
474
  class MapStyleVariant {
442
475
  constructor(name, variantType, id, referenceStyle, description, imageURL) {
443
476
  this.name = name;
@@ -447,63 +480,146 @@ class MapStyleVariant {
447
480
  this.description = description;
448
481
  this.imageURL = imageURL;
449
482
  }
483
+ /**
484
+ * Get the human-friendly name
485
+ * @returns
486
+ */
450
487
  getName() {
451
488
  return this.name;
452
489
  }
453
490
  getFullName() {
454
491
  return `${this.referenceStyle.getName()} ${this.name}`;
455
492
  }
493
+ /**
494
+ * Get the variant type (eg. "DEFAULT", "DARK", "PASTEL", etc.)
495
+ * @returns
496
+ */
456
497
  getType() {
457
498
  return this.variantType;
458
499
  }
500
+ /**
501
+ * Get the MapTiler Cloud id
502
+ * @returns
503
+ */
459
504
  getId() {
460
505
  return this.id;
461
506
  }
507
+ /**
508
+ * Get the human-friendly description
509
+ */
462
510
  getDescription() {
463
511
  return this.description;
464
512
  }
513
+ /**
514
+ * Get the reference style this variant belongs to
515
+ * @returns
516
+ */
465
517
  getReferenceStyle() {
466
518
  return this.referenceStyle;
467
519
  }
520
+ /**
521
+ * Check if a variant of a given type exists for _this_ variants
522
+ * (eg. if this is a "DARK", then we can check if there is a "LIGHT" variant of it)
523
+ * @param variantType
524
+ * @returns
525
+ */
468
526
  hasVariant(variantType) {
469
527
  return this.referenceStyle.hasVariant(variantType);
470
528
  }
529
+ /**
530
+ * Retrieve the variant of a given type. If not found, will return the "DEFAULT" variant.
531
+ * (eg. _this_ "DARK" variant does not have any "PASTEL" variant, then the "DEFAULT" is returned)
532
+ * @param variantType
533
+ * @returns
534
+ */
471
535
  getVariant(variantType) {
472
536
  return this.referenceStyle.getVariant(variantType);
473
537
  }
538
+ /**
539
+ * Get all the variants for _this_ variants, except _this_ current one
540
+ * @returns
541
+ */
474
542
  getVariants() {
475
543
  return this.referenceStyle.getVariants().filter((v) => v !== this);
476
544
  }
545
+ /**
546
+ * Get the image URL that represent _this_ variant
547
+ * @returns
548
+ */
477
549
  getImageURL() {
478
550
  return this.imageURL;
479
551
  }
552
+ /**
553
+ * Get the style as usable by MapLibre, a string (URL) or a plain style description (StyleSpecification)
554
+ * @returns
555
+ */
556
+ getExpandedStyleURL() {
557
+ return expandMapStyle(this.getId());
558
+ }
480
559
  }
481
560
  class ReferenceMapStyle {
482
561
  constructor(name, id) {
483
562
  this.name = name;
484
563
  this.id = id;
564
+ /**
565
+ * Variants that belong to this reference style, key being the reference type
566
+ */
485
567
  this.variants = {};
568
+ /**
569
+ * Variants that belong to this reference style, ordered by relevance
570
+ */
486
571
  this.orderedVariants = [];
487
572
  }
573
+ /**
574
+ * Get the human-friendly name of this reference style
575
+ * @returns
576
+ */
488
577
  getName() {
489
578
  return this.name;
490
579
  }
580
+ /**
581
+ * Get the id of _this_ reference style
582
+ * @returns
583
+ */
491
584
  getId() {
492
585
  return this.id;
493
586
  }
587
+ /**
588
+ * Add a variant to _this_ reference style
589
+ * @param v
590
+ */
494
591
  addVariant(v) {
495
592
  this.variants[v.getType()] = v;
496
593
  this.orderedVariants.push(v);
497
594
  }
595
+ /**
596
+ * Check if a given variant type exists for this reference style
597
+ * @param variantType
598
+ * @returns
599
+ */
498
600
  hasVariant(variantType) {
499
601
  return variantType in this.variants;
500
602
  }
603
+ /**
604
+ * Get a given variant. If the given type of variant does not exist for this reference style,
605
+ * then the most relevant default variant is returned instead
606
+ * @param variantType
607
+ * @returns
608
+ */
501
609
  getVariant(variantType) {
502
610
  return variantType in this.variants ? this.variants[variantType] : this.orderedVariants[0];
503
611
  }
612
+ /**
613
+ * Get the list of variants for this reference style
614
+ * @returns
615
+ */
504
616
  getVariants() {
505
617
  return Object.values(this.variants);
506
618
  }
619
+ /**
620
+ * Get the defualt variant for this reference style
621
+ * @returns
622
+ */
507
623
  getDefaultVariant() {
508
624
  return this.orderedVariants[0];
509
625
  }
@@ -849,11 +965,16 @@ function buildMapStyles() {
849
965
  const variantInfo = refStyleInfo.variants[j];
850
966
  const variant = new MapStyleVariant(
851
967
  variantInfo.name,
968
+ // name
852
969
  variantInfo.variantType,
970
+ // variantType
853
971
  variantInfo.id,
972
+ // id
854
973
  refStyle,
974
+ // referenceStyle
855
975
  variantInfo.description,
856
976
  variantInfo.imageURL
977
+ // imageURL
857
978
  );
858
979
  refStyle.addVariant(variant);
859
980
  }
@@ -1115,5 +1236,5 @@ const staticMaps = {
1115
1236
  automatic
1116
1237
  };
1117
1238
 
1118
- export { ClientConfig, LanguageGeocoding, MapStyle, MapStyleVariant, ReferenceMapStyle, ServiceError, config, coordinates, data, geocoding, geolocation, mapStylePresetList, staticMaps, styleToStyle };
1239
+ export { ClientConfig, LanguageGeocoding, MapStyle, MapStyleVariant, ReferenceMapStyle, ServiceError, config, coordinates, data, expandMapStyle, geocoding, geolocation, mapStylePresetList, staticMaps };
1119
1240
  //# sourceMappingURL=maptiler-client.mjs.map