@maptiler/sdk 1.0.11 → 1.0.12

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.
package/CHANGELOG.md CHANGED
@@ -1,4 +1,8 @@
1
1
  # Changelog
2
+ ## [v1.0.12](https://github.com/maptiler/maptiler-sdk-js/releases/tag/v1.0.12)
3
+ - ADD a new language flag `Language.STYLE_LOCK` to force keep the language form the style and prevent any further update. Can be at a sigle map instance level (via constuctor option `language`) or via global config (`config.primaryLanguage`)
4
+ - FIX the fallback language was `{name:latin}`, it is now replaced by `{name}`, which is for the local name (present by default for many places while `latin` is less frequent).
5
+
2
6
  ## [v1.0.11](https://github.com/maptiler/maptiler-sdk-js/releases/tag/v1.0.11)
3
7
  - DOC update for `Map`'s `option.maptilerLogo` that was a bit unclear
4
8
  - FIX now exporting `MaptilerNavigationControl`
@@ -883,6 +883,12 @@
883
883
  * AUTO mode uses the language of the browser
884
884
  */
885
885
  AUTO: "auto",
886
+ /**
887
+ * STYLE is a custom flag to keep the language of the map as defined into the style.
888
+ * If STYLE is set in the constructor, then further modification of the language
889
+ * with `.setLanguage()` is not possible.
890
+ */
891
+ STYLE_LOCK: "style_lock",
886
892
  /**
887
893
  * Default fallback languages that uses latin charaters
888
894
  */
@@ -3085,6 +3091,12 @@
3085
3091
  * @param language
3086
3092
  */
3087
3093
  setPrimaryLanguage(language = defaults.primaryLanguage) {
3094
+ if (this.primaryLanguage === Language.STYLE_LOCK) {
3095
+ console.warn(
3096
+ "The language cannot be changed because this map has been instantiated with the STYLE_LOCK language flag."
3097
+ );
3098
+ return;
3099
+ }
3088
3100
  if (!isLanguageSupported(language)) {
3089
3101
  return;
3090
3102
  }
@@ -3103,7 +3115,7 @@
3103
3115
  "case",
3104
3116
  ["has", langStr],
3105
3117
  ["get", langStr],
3106
- ["get", "name:latin"]
3118
+ ["get", "name"]
3107
3119
  ];
3108
3120
  for (let i = 0; i < layers.length; i += 1) {
3109
3121
  const layer = layers[i];
@@ -3164,6 +3176,12 @@
3164
3176
  * @param language
3165
3177
  */
3166
3178
  setSecondaryLanguage(language = defaults.secondaryLanguage) {
3179
+ if (this.primaryLanguage === Language.STYLE_LOCK) {
3180
+ console.warn(
3181
+ "The language cannot be changed because this map has been instantiated with the STYLE_LOCK language flag."
3182
+ );
3183
+ return;
3184
+ }
3167
3185
  if (!isLanguageSupported(language)) {
3168
3186
  return;
3169
3187
  }
@@ -0,0 +1,67 @@
1
+ <html>
2
+ <head>
3
+ <title>MapTiler JS SDK example</title>
4
+ <style>
5
+ html, body {
6
+ margin: 0;
7
+ }
8
+
9
+ #map-container {
10
+ position: absolute;
11
+ width: 100vw;
12
+ height: 100vh;
13
+ background: radial-gradient(circle, rgb(186 226 255) 5%, rgb(0 100 159) 98%);
14
+ }
15
+
16
+ #style-picker-container {
17
+ position: absolute;
18
+ z-index: 2;
19
+ margin: 10px;
20
+ }
21
+
22
+ </style>
23
+
24
+ <link rel="stylesheet" href="maptiler-sdk.css">
25
+ </head>
26
+
27
+ <body>
28
+ <div id="map-container"></div>
29
+ <div id="style-picker-container">
30
+ <select name="mapstyles" id="mapstyles-picker">
31
+
32
+ </select>
33
+
34
+ </div>
35
+
36
+ <script src ="maptiler-sdk.umd.js"></script>
37
+
38
+ <script>
39
+ maptilersdk.config.apiKey = "YOUR_API_KEY";
40
+
41
+ const map = new maptilersdk.Map({
42
+ container: document.getElementById("map-container"),
43
+ style: maptilersdk.MapStyle.OUTDOOR.DARK,
44
+ hash: true,
45
+ scaleControl: true,
46
+ fullscreenControl: true,
47
+ terrainControl: true,
48
+ geolocate: true,
49
+ })
50
+
51
+ const styleDropDown = document.getElementById("mapstyles-picker")
52
+
53
+ styleDropDown.onchange = (evt) => {
54
+ map.setStyle(styleDropDown.value)
55
+ }
56
+
57
+ Object.keys(maptilersdk.MapStyle).forEach(s => {
58
+ const styleOption = document.createElement('option');
59
+ styleOption.value = maptilersdk.MapStyle[s].DEFAULT.id;
60
+ styleOption.innerHTML = s.replace("_", " ").toLowerCase();
61
+ styleDropDown.appendChild(styleOption);
62
+ })
63
+
64
+
65
+ </script>
66
+ </body>
67
+ </html>
@@ -14,6 +14,12 @@ declare const Language: {
14
14
  * AUTO mode uses the language of the browser
15
15
  */
16
16
  readonly AUTO: "auto";
17
+ /**
18
+ * STYLE is a custom flag to keep the language of the map as defined into the style.
19
+ * If STYLE is set in the constructor, then further modification of the language
20
+ * with `.setLanguage()` is not possible.
21
+ */
22
+ readonly STYLE_LOCK: "style_lock";
17
23
  /**
18
24
  * Default fallback languages that uses latin charaters
19
25
  */
@@ -1 +1 @@
1
- import a from"maplibre-gl";export*from"maplibre-gl";import{Base64 as W}from"js-base64";import{v4 as J}from"uuid";import Z from"events";import{config as T,expandMapStyle as Y,MapStyleVariant as X,ReferenceMapStyle as Q,MapStyle as tt,mapStylePresetList as et,geolocation as w}from"@maptiler/client";import{LanguageGeocoding as me,MapStyle as ye,MapStyleVariant as Ae,ReferenceMapStyle as fe,ServiceError as Le,coordinates as _e,data as Se,geocoding as xe,geolocation as Ce,staticMaps as Te}from"@maptiler/client";const L={AUTO:"auto",LATIN:"latin",NON_LATIN:"nonlatin",LOCAL:"",ALBANIAN:"sq",AMHARIC:"am",ARABIC:"ar",ARMENIAN:"hy",AZERBAIJANI:"az",BASQUE:"eu",BELORUSSIAN:"be",BOSNIAN:"bs",BRETON:"br",BULGARIAN:"bg",CATALAN:"ca",CHINESE:"zh",CORSICAN:"co",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",HINDI:"hi",HUNGARIAN:"hu",ICELANDIC:"is",INDONESIAN:"id",IRISH:"ga",ITALIAN:"it",JAPANESE:"ja",JAPANESE_HIRAGANA:"ja-Hira",JAPANESE_KANA:"ja_kana",JAPANESE_LATIN:"ja_rm",JAPANESE_2018:"ja-Latn",KANNADA:"kn",KAZAKH:"kk",KOREAN:"ko",KOREAN_LATIN:"ko-Latn",KURDISH:"ku",ROMAN_LATIN:"la",LATVIAN:"lv",LITHUANIAN:"lt",LUXEMBOURGISH:"lb",MACEDONIAN:"mk",MALAYALAM:"ml",MALTESE:"mt",NORWEGIAN:"no",OCCITAN:"oc",POLISH:"pl",PORTUGUESE:"pt",ROMANIAN:"ro",ROMANSH:"rm",RUSSIAN:"ru",SCOTTISH_GAELIC:"gd",SERBIAN_CYRILLIC:"sr",SERBIAN_LATIN:"sr-Latn",SLOVAK:"sk",SLOVENE:"sl",SPANISH:"es",SWEDISH:"sv",TAMIL:"ta",TELUGU:"te",THAI:"th",TURKISH:"tr",UKRAINIAN:"uk",WELSH:"cy"},rt=new Set(Object.values(L));function v(r){return rt.has(r)}const it=new Set(Object.values(L));function b(){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=>it.has(t));return r.length?r[0]:L.LATIN}let E=class extends Z{constructor(){super(),this.primaryLanguage=L.AUTO,this.secondaryLanguage=null,this.session=!0,this._unit="metric",this._apiKey=""}set unit(t){this._unit=t,this.emit("unit",t)}get unit(){return this._unit}set apiKey(t){this._apiKey=t,T.apiKey=t,this.emit("apiKey",t)}get apiKey(){return this._apiKey}set fetch(t){T.fetch=t}get fetch(){return T.fetch}};const A=new E,y={maptilerLogoURL:"https://api.maptiler.com/resources/logo.svg",maptilerURL:"https://www.maptiler.com/",maptilerApiHost:"api.maptiler.com",rtlPluginURL:"https://cdn.maptiler.com/mapbox-gl-rtl-text/v0.2.3/mapbox-gl-rtl-text.min.js",primaryLanguage:L.AUTO,secondaryLanguage:L.LOCAL,terrainSourceURL:"https://api.maptiler.com/tiles/terrain-rgb-v2/tiles.json",terrainSourceId:"maptiler-terrain"};Object.freeze(y);class N extends a.LogoControl{onAdd(t){return super.onAdd(t)}}class I extends N{constructor(t={}){var e,n;super(t),this.logoURL="",this.linkURL="",this.logoURL=(e=t.logoURL)!=null?e:y.maptilerLogoURL,this.linkURL=(n=t.linkURL)!=null?n:y.maptilerURL}onAdd(t){this._map=t,this._compact=this.options&&this.options.compact,this._container=window.document.createElement("div"),this._container.className="maplibregl-ctrl";const e=window.document.createElement("a");return e.style.backgroundRepeat="no-repeat",e.style.cursor="pointer",e.style.display="block",e.style.height="23px",e.style.margin="0 0 -4px -4px",e.style.overflow="hidden",e.style.width="88px",e.style.backgroundImage=`url(${this.logoURL})`,e.style.backgroundSize="100px 30px",e.style.width="100px",e.style.height="30px",e.target="_blank",e.rel="noopener nofollow",e.href=this.linkURL,e.setAttribute("aria-label",this._map._getUIString("LogoControl.Title")),e.setAttribute("rel","noopener nofollow"),this._container.appendChild(e),this._container.style.display="block",this._map.on("resize",this._updateCompact),this._updateCompact(),this._container}}function nt(){a.getRTLTextPluginStatus()==="unavailable"&&a.setRTLTextPlugin(y.rtlPluginURL,null,!0)}function at(r,t){r.forEach(e=>{t[e]&&(t[e]=t[e].bind(t))})}function S(r,t,e){const n=window.document.createElement(r);return t!==void 0&&(n.className=t),e&&e.appendChild(n),n}function ot(r){r.parentNode&&r.parentNode.removeChild(r)}function R(r){return r?typeof r=="string"||r instanceof String?!r.startsWith("http")&&r.toLowerCase().includes(".json")?r:Y(r):r instanceof X?r.getExpandedStyleURL():r instanceof Q?r.getDefaultVariant().getExpandedStyleURL():r:tt[et[0].referenceStyleID].getDefaultVariant().getExpandedStyleURL()}class P{constructor(){at(["_toggleTerrain","_updateTerrainIcon"],this)}onAdd(t){return this._map=t,this._container=S("div","maplibregl-ctrl maplibregl-ctrl-group"),this._terrainButton=S("button","maplibregl-ctrl-terrain",this._container),S("span","maplibregl-ctrl-icon",this._terrainButton).setAttribute("aria-hidden","true"),this._terrainButton.type="button",this._terrainButton.addEventListener("click",this._toggleTerrain),this._updateTerrainIcon(),this._map.on("terrain",this._updateTerrainIcon),this._container}onRemove(){ot(this._container),this._map.off("terrain",this._updateTerrainIcon),this._map=void 0}_toggleTerrain(){this._map.hasTerrain()?this._map.disableTerrain():this._map.enableTerrain(),this._updateTerrainIcon()}_updateTerrainIcon(){this._terrainButton.classList.remove("maplibregl-ctrl-terrain"),this._terrainButton.classList.remove("maplibregl-ctrl-terrain-enabled"),this._map.hasTerrain()?(this._terrainButton.classList.add("maplibregl-ctrl-terrain-enabled"),this._terrainButton.title=this._map._getUIString("TerrainControl.disableTerrain")):(this._terrainButton.classList.add("maplibregl-ctrl-terrain"),this._terrainButton.title=this._map._getUIString("TerrainControl.enableTerrain"))}}class M extends a.NavigationControl{onAdd(t){return super.onAdd(t)}}class O extends M{constructor(){super({showCompass:!0,showZoom:!0,visualizePitch:!0}),this._compass.removeEventListener("click",this._compass.clickFunction),this._compass.addEventListener("click",t=>{this._map.getPitch()===0?this._map.easeTo({pitch:Math.min(this._map.getMaxPitch(),80)}):this.options.visualizePitch?this._map.resetNorthPitch({},{originalEvent:t}):this._map.resetNorth({},{originalEvent:t})})}_createButton(t,e){const n=super._createButton(t,e);return n.clickFunction=e,n}_rotateCompassArrow(){const t=this.options.visualizePitch?`scale(${Math.min(1.5,1/Math.pow(Math.cos(this._map.transform.pitch*(Math.PI/180)),.5))}) rotateX(${Math.min(70,this._map.transform.pitch)}deg) rotateZ(${this._map.transform.angle*(180/Math.PI)}deg)`:`rotate(${this._map.transform.angle*(180/Math.PI)}deg)`;this._compassIcon.style.transform=t}}class U extends a.GeolocateControl{onAdd(t){return super.onAdd(t)}}var st=Object.defineProperty,lt=Object.defineProperties,ct=Object.getOwnPropertyDescriptors,k=Object.getOwnPropertySymbols,ht=Object.prototype.hasOwnProperty,ut=Object.prototype.propertyIsEnumerable,B=(r,t,e)=>t in r?st(r,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):r[t]=e,dt=(r,t)=>{for(var e in t||(t={}))ht.call(t,e)&&B(r,e,t[e]);if(k)for(var e of k(t))ut.call(t,e)&&B(r,e,t[e]);return r},gt=(r,t)=>lt(r,ct(t));const $=a.Marker,G=a.LngLat;class H extends U{constructor(){super(...arguments),this.lastUpdatedCenter=new G(0,0)}_updateCamera(t){const e=new G(t.coords.longitude,t.coords.latitude),n=t.coords.accuracy,s=this._map.getBearing(),d=gt(dt({bearing:s},this.options.fitBoundsOptions),{linear:!0}),u=this._map.getZoom();u>this.options.fitBoundsOptions.maxZoom&&(d.zoom=u),this._map.fitBounds(e.toBounds(n),d,{geolocateSource:!0});let h=!1;const o=()=>{h=!0};this._map.once("click",o),this._map.once("dblclick",o),this._map.once("dragstart",o),this._map.once("mousedown",o),this._map.once("touchstart",o),this._map.once("wheel",o),this._map.once("moveend",()=>{this._map.off("click",o),this._map.off("dblclick",o),this._map.off("dragstart",o),this._map.off("mousedown",o),this._map.off("touchstart",o),this._map.off("wheel",o),!h&&(this.lastUpdatedCenter=this._map.getCenter())})}_setupUI(t){if(this.lastUpdatedCenter=this._map.getCenter(),this._container.addEventListener("contextmenu",e=>e.preventDefault()),this._geolocateButton=S("button","maplibregl-ctrl-geolocate",this._container),S("span","maplibregl-ctrl-icon",this._geolocateButton).setAttribute("aria-hidden","true"),this._geolocateButton.type="button",t===!1){const e=this._map._getUIString("GeolocateControl.LocationNotAvailable");this._geolocateButton.disabled=!0,this._geolocateButton.title=e,this._geolocateButton.setAttribute("aria-label",e)}else{const e=this._map._getUIString("GeolocateControl.FindMyLocation");this._geolocateButton.title=e,this._geolocateButton.setAttribute("aria-label",e)}this.options.trackUserLocation&&(this._geolocateButton.setAttribute("aria-pressed","false"),this._watchState="OFF"),this.options.showUserLocation&&(this._dotElement=S("div","maplibregl-user-location-dot"),this._userLocationDotMarker=new $(this._dotElement),this._circleElement=S("div","maplibregl-user-location-accuracy-circle"),this._accuracyCircleMarker=new $({element:this._circleElement,pitchAlignment:"map"}),this.options.trackUserLocation&&(this._watchState="OFF"),this._map.on("move",this._onZoom)),this._geolocateButton.addEventListener("click",this.trigger.bind(this)),this._setup=!0,this.options.trackUserLocation&&this._map.on("moveend",e=>{const n=e.originalEvent&&e.originalEvent.type==="resize",s=this.lastUpdatedCenter.distanceTo(this._map.getCenter());!e.geolocateSource&&this._watchState==="ACTIVE_LOCK"&&!n&&s>1&&(this._watchState="BACKGROUND",this._geolocateButton.classList.add("maplibregl-ctrl-geolocate-background"),this._geolocateButton.classList.remove("maplibregl-ctrl-geolocate-active"),this.fire(new Event("trackuserlocationend")))})}_updateCircleRadius(){if(this._watchState!=="BACKGROUND"&&this._watchState!=="ACTIVE_LOCK")return;const t=[this._lastKnownPosition.coords.longitude,this._lastKnownPosition.coords.latitude],e=this._map.project(t),n=this._map.unproject([e.x,e.y]),s=this._map.unproject([e.x+20,e.y]),d=n.distanceTo(s)/20,u=Math.ceil(2*this._accuracy/d);this._circleElement.style.width=`${u}px`,this._circleElement.style.height=`${u}px`}_onZoom(){this.options.showUserLocation&&this.options.showAccuracyCircle&&this._updateCircleRadius()}}class j extends a.AttributionControl{onAdd(t){return super.onAdd(t)}}class K extends a.ScaleControl{onAdd(t){return super.onAdd(t)}}class F extends a.FullscreenControl{onAdd(t){return super.onAdd(t)}}var pt=Object.defineProperty,mt=Object.defineProperties,yt=Object.getOwnPropertyDescriptors,D=Object.getOwnPropertySymbols,At=Object.prototype.hasOwnProperty,ft=Object.prototype.propertyIsEnumerable,V=(r,t,e)=>t in r?pt(r,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):r[t]=e,Lt=(r,t)=>{for(var e in t||(t={}))At.call(t,e)&&V(r,e,t[e]);if(D)for(var e of D(t))ft.call(t,e)&&V(r,e,t[e]);return r},_t=(r,t)=>mt(r,yt(t)),_=(r,t,e)=>new Promise((n,s)=>{var d=o=>{try{h(e.next(o))}catch(m){s(m)}},u=o=>{try{h(e.throw(o))}catch(m){s(m)}},h=o=>o.done?n(o.value):Promise.resolve(o.value).then(d,u);h((e=e.apply(r,t)).next())});const z=J(),q={POINT:"POINT",COUNTRY:"COUNTRY"};class St extends a.Map{constructor(t){var e,n,s;t.apiKey&&(A.apiKey=t.apiKey);const d=R(t.style),u=location.hash;A.apiKey||console.warn("MapTiler Cloud API key is not set. Visit https://maptiler.com and try Cloud for free!"),super(_t(Lt({},t),{style:d,maplibreLogo:!1,transformRequest:c=>{let i=null;try{i=new URL(c)}catch{return{url:c,headers:{}}}return i.host===y.maptilerApiHost&&(i.searchParams.has("key")||i.searchParams.append("key",A.apiKey),A.session&&i.searchParams.append("mtsid",z)),{url:i.href,headers:{}}}})),this.isTerrainEnabled=!1,this.terrainExaggeration=1,this.primaryLanguage=null,this.secondaryLanguage=null,this.terrainGrowing=!1,this.terrainFlattening=!1,this.primaryLanguage=(e=t.language)!=null?e:A.primaryLanguage,this.secondaryLanguage=A.secondaryLanguage,this.terrainExaggeration=(n=t.terrainExaggeration)!=null?n:this.terrainExaggeration,this.once("styledata",()=>_(this,null,function*(){if(!t.geolocate||t.center||t.hash&&u)return;try{if(t.geolocate===q.COUNTRY){yield this.fitToIpBounds();return}}catch(i){console.warn(i.message)}let c=null;try{yield this.centerOnIpPoint(t.zoom),c=this.getCameraHash()}catch(i){console.warn(i.message)}(yield navigator.permissions.query({name:"geolocation"})).state==="granted"&&navigator.geolocation.getCurrentPosition(i=>{c===this.getCameraHash()&&(this.terrain?this.easeTo({center:[i.coords.longitude,i.coords.latitude],zoom:t.zoom||12,duration:2e3}):this.once("terrain",()=>{this.easeTo({center:[i.coords.longitude,i.coords.latitude],zoom:t.zoom||12,duration:2e3})}))},null,{maximumAge:24*3600*1e3,timeout:5e3,enableHighAccuracy:!1})})),this.on("styledata",()=>{this.setPrimaryLanguage(this.primaryLanguage),this.setSecondaryLanguage(this.secondaryLanguage)}),this.on("styledata",()=>{this.getTerrain()===null&&this.isTerrainEnabled&&this.enableTerrain(this.terrainExaggeration)}),this.once("load",()=>_(this,null,function*(){nt()})),this.once("load",()=>_(this,null,function*(){let c={logo:null};try{const i=Object.keys(this.style.sourceCaches).map(l=>this.getSource(l)).filter(l=>typeof l.url=="string"&&l.url.includes("tiles.json")),p=new URL(i[0].url);p.searchParams.has("key")||p.searchParams.append("key",A.apiKey),c=yield(yield fetch(p.href)).json()}catch{}if("logo"in c&&c.logo){const i=c.logo;this.addControl(new I({logoURL:i}),t.logoPosition),t.attributionControl===!1&&this.addControl(new j(t))}else t.maptilerLogo&&this.addControl(new I,t.logoPosition);if(t.scaleControl){const i=t.scaleControl===!0||t.scaleControl===void 0?"bottom-right":t.scaleControl,p=new K({unit:A.unit});this.addControl(p,i),A.on("unit",l=>{p.setUnit(l)})}if(t.navigationControl!==!1){const i=t.navigationControl===!0||t.navigationControl===void 0?"top-right":t.navigationControl;this.addControl(new O,i)}if(t.geolocateControl!==!1){const i=t.geolocateControl===!0||t.geolocateControl===void 0?"top-right":t.geolocateControl;this.addControl(new H({positionOptions:{enableHighAccuracy:!0,maximumAge:0,timeout:6e3},fitBoundsOptions:{maxZoom:15},trackUserLocation:!0,showAccuracyCircle:!0,showUserLocation:!0}),i)}if(t.terrainControl){const i=t.terrainControl===!0||t.terrainControl===void 0?"top-right":t.terrainControl;this.addControl(new P,i)}if(t.fullscreenControl){const i=t.fullscreenControl===!0||t.fullscreenControl===void 0?"top-right":t.fullscreenControl;this.addControl(new F({}),i)}}));let h=!1,o=!1,m=null;this.once("load",c=>{h=!0,o&&this.fire("loadWithTerrain",m)});const g=c=>{c.terrain&&(o=!0,m={type:"loadWithTerrain",target:this,terrain:c.terrain},this.off("terrain",g),h&&this.fire("loadWithTerrain",m))};this.on("terrain",g),t.terrain&&this.enableTerrain((s=t.terrainExaggeration)!=null?s:this.terrainExaggeration)}onLoadAsync(){return _(this,null,function*(){return new Promise((t,e)=>{if(this.loaded())return t(this);this.once("load",n=>{t(this)})})})}onLoadWithTerrainAsync(){return _(this,null,function*(){return new Promise((t,e)=>{if(this.loaded()&&this.terrain)return t(this);this.once("loadWithTerrain",n=>{t(this)})})})}setStyle(t,e){return super.setStyle(R(t),e)}setLanguage(t=y.primaryLanguage){if(t===L.AUTO)return this.setLanguage(b());this.setPrimaryLanguage(t)}setPrimaryLanguage(t=y.primaryLanguage){v(t)&&(this.primaryLanguage=t,this.onStyleReady(()=>{if(t===L.AUTO)return this.setPrimaryLanguage(b());const e=this.getStyle().layers,n=/^\s*{\s*name\s*(:\s*(\S*))?\s*}$/,s=/^\s*name\s*(:\s*(\S*))?\s*$/,d=/^\s*{\s*name\s*(:\s*(\S*))?\s*}(\s*){\s*name\s*(:\s*(\S*))?\s*}$/,u=/^(.*)({\s*name\s*(:\s*(\S*))?\s*})(.*)$/,h=t?`name:${t}`:"name",o=["case",["has",h],["get",h],["get","name:latin"]];for(let m=0;m<e.length;m+=1){const g=e[m],c=g.layout;if(!c||!c["text-field"])continue;const i=this.getLayoutProperty(g.id,"text-field");let p;if(Array.isArray(i)&&i.length>=2&&i[0].trim().toLowerCase()==="concat"){const l=i.slice();for(let x=0;x<i.length;x+=1){const f=i[x];if((typeof f=="string"||f instanceof String)&&n.exec(f.toString())){l[x]=o;break}else if(Array.isArray(f)&&f.length>=2&&f[0].trim().toLowerCase()==="get"&&s.exec(f[1].toString())){l[x]=o;break}else if(Array.isArray(f)&&f.length===4&&f[0].trim().toLowerCase()==="case"){l[x]=o;break}}this.setLayoutProperty(g.id,"text-field",l)}else if(Array.isArray(i)&&i.length>=2&&i[0].trim().toLowerCase()==="get"&&s.exec(i[1].toString())){const l=o;this.setLayoutProperty(g.id,"text-field",l)}else if((typeof i=="string"||i instanceof String)&&n.exec(i.toString())){const l=o;this.setLayoutProperty(g.id,"text-field",l)}else if(Array.isArray(i)&&i.length===4&&i[0].trim().toLowerCase()==="case"){const l=o;this.setLayoutProperty(g.id,"text-field",l)}else if((typeof i=="string"||i instanceof String)&&(p=d.exec(i.toString()))!==null){const l=`{${h}}${p[3]}{name${p[4]||""}}`;this.setLayoutProperty(g.id,"text-field",l)}else if((typeof i=="string"||i instanceof String)&&(p=u.exec(i.toString()))!==null){const l=`${p[1]}{${h}}${p[5]}`;this.setLayoutProperty(g.id,"text-field",l)}}}))}setSecondaryLanguage(t=y.secondaryLanguage){v(t)&&(this.secondaryLanguage=t,this.onStyleReady(()=>{if(t===L.AUTO)return this.setSecondaryLanguage(b());const e=this.getStyle().layers,n=/^\s*{\s*name\s*(:\s*(\S*))?\s*}$/,s=/^\s*name\s*(:\s*(\S*))?\s*$/,d=/^\s*{\s*name\s*(:\s*(\S*))?\s*}(\s*){\s*name\s*(:\s*(\S*))?\s*}$/;let u;for(let h=0;h<e.length;h+=1){const o=e[h],m=o.layout;if(!m||!m["text-field"])continue;const g=this.getLayoutProperty(o.id,"text-field");let c;if(Array.isArray(g)&&g.length>=2&&g[0].trim().toLowerCase()==="concat"){c=g.slice();let i=0;for(let p=0;p<g.length;p+=1){const l=g[p];if((typeof l=="string"||l instanceof String)&&n.exec(l.toString())){if(i===1){c[p]=`{name:${t}}`;break}i+=1}else if(Array.isArray(l)&&l.length>=2&&l[0].trim().toLowerCase()==="get"&&s.exec(l[1].toString())){if(i===1){c[p][1]=`name:${t}`;break}i+=1}else if(Array.isArray(l)&&l.length===4&&l[0].trim().toLowerCase()==="case"){if(i===1){c[p]=["get",`name:${t}`];break}i+=1}}this.setLayoutProperty(o.id,"text-field",c)}else if((typeof g=="string"||g instanceof String)&&(u=d.exec(g.toString()))!==null){const i=t?`name:${t}`:"name";c=`{name${u[1]||""}}${u[3]}{${i}}`,this.setLayoutProperty(o.id,"text-field",c)}}}))}getPrimaryLanguage(){return this.primaryLanguage}getSecondaryLanguage(){return this.secondaryLanguage}getTerrainExaggeration(){return this.terrainExaggeration}hasTerrain(){return this.isTerrainEnabled}growTerrain(t,e=1e3){if(!this.terrain)return;const n=performance.now(),s=this.terrain.exaggeration,d=t-s,u=()=>{if(!this.terrain||this.terrainFlattening)return;const h=(performance.now()-n)/e;if(h<.99){const o=1-Math.pow(1-h,4),m=s+o*d;this.terrain.exaggeration=m,requestAnimationFrame(u)}else this.terrainGrowing=!1,this.terrainFlattening=!1,this.terrain.exaggeration=t;this.triggerRepaint()};this.terrainGrowing=!0,this.terrainFlattening=!1,requestAnimationFrame(u)}enableTerrain(t=this.terrainExaggeration){if(t<0){console.warn("Terrain exaggeration cannot be negative.");return}const e=s=>_(this,null,function*(){!this.terrain||s.type!=="data"||s.dataType!=="source"||!("source"in s)||s.sourceId!=="maptiler-terrain"||s.source.type!=="raster-dem"||s.isSourceLoaded&&(this.off("data",e),this.growTerrain(t))}),n=()=>{this.isTerrainEnabled=!0,this.terrainExaggeration=t,this.on("data",e),this.addSource(y.terrainSourceId,{type:"raster-dem",url:y.terrainSourceURL}),this.setTerrain({source:y.terrainSourceId,exaggeration:0})};if(this.getTerrain()){this.isTerrainEnabled=!0,this.growTerrain(t);return}this.loaded()||this.isTerrainEnabled?n():this.once("load",()=>{this.getTerrain()&&this.getSource(y.terrainSourceId)||n()})}disableTerrain(){if(!this.terrain)return;this.isTerrainEnabled=!1;const t=1*1e3,e=performance.now(),n=this.terrain.exaggeration,s=()=>{if(!this.terrain||this.terrainGrowing)return;const d=(performance.now()-e)/t;if(d<.99){const u=Math.pow(1-d,4),h=n*u;this.terrain.exaggeration=h,requestAnimationFrame(s)}else this.terrain.exaggeration=0,this.terrainGrowing=!1,this.terrainFlattening=!1,this.setTerrain(null),this.getSource(y.terrainSourceId)&&this.removeSource(y.terrainSourceId);this.triggerRepaint()};this.terrainGrowing=!1,this.terrainFlattening=!0,requestAnimationFrame(s)}setTerrainExaggeration(t,e=!0){!e&&this.terrain?(this.terrainExaggeration=t,this.terrain.exaggeration=t,this.triggerRepaint()):this.enableTerrain(t)}onStyleReady(t){this.isStyleLoaded()?t():this.once("styledata",()=>{t()})}fitToIpBounds(){return _(this,null,function*(){const t=yield w.info();this.fitBounds(t.country_bounds,{duration:0,padding:100})})}centerOnIpPoint(t){return _(this,null,function*(){const e=yield w.info();this.jumpTo({center:[e.longitude,e.latitude],zoom:t||11})})}getCameraHash(){const t=new Float32Array(5),e=this.getCenter();return t[0]=e.lng,t[1]=e.lat,t[2]=this.getZoom(),t[3]=this.getPitch(),t[4]=this.getBearing(),W.fromUint8Array(new Uint8Array(t.buffer))}getSdkConfig(){return A}getMaptilerSessionId(){return z}}class xt extends a.Marker{addTo(t){return super.addTo(t)}}class Ct extends a.Popup{addTo(t){return super.addTo(t)}}class Tt extends a.Style{constructor(t,e={}){super(t,e)}}class bt extends a.CanvasSource{onAdd(t){super.onAdd(t)}}class It extends a.GeoJSONSource{onAdd(t){super.onAdd(t)}}class wt extends a.ImageSource{onAdd(t){super.onAdd(t)}}class vt extends a.RasterTileSource{onAdd(t){super.onAdd(t)}}class Et extends a.RasterDEMTileSource{onAdd(t){super.onAdd(t)}}class Nt extends a.VectorTileSource{onAdd(t){super.onAdd(t)}}class Rt extends a.VideoSource{onAdd(t){super.onAdd(t)}}class Pt extends a.TerrainControl{onAdd(t){return super.onAdd(t)}}class C{constructor(t,e){this.x=t,this.y=e}_matMult(t){const e=t[0]*this.x+t[1]*this.y,n=t[2]*this.x+t[3]*this.y;return this.x=e,this.y=n,this}_add(t){return this.x+=t.x,this.y+=t.y,this}_sub(t){return this.x-=t.x,this.y-=t.y,this}_mult(t){return this.x*=t,this.y*=t,this}_div(t){return this.x/=t,this.y/=t,this}_multByPoint(t){return this.x*=t.x,this.y*=t.y,this}_divByPoint(t){return this.x/=t.x,this.y/=t.y,this}_unit(){return this._div(this.mag()),this}_perp(){const t=this.y;return this.y=this.x,this.x=-t,this}_rotate(t){const e=Math.cos(t),n=Math.sin(t),s=e*this.x-n*this.y,d=n*this.x+e*this.y;return this.x=s,this.y=d,this}_rotateAround(t,e){const n=Math.cos(t),s=Math.sin(t),d=e.x+n*(this.x-e.x)-s*(this.y-e.y),u=e.y+s*(this.x-e.x)+n*(this.y-e.y);return this.x=d,this.y=u,this}_round(){return this.x=Math.round(this.x),this.y=Math.round(this.y),this}clone(){return new C(this.x,this.y)}add(t){return this.clone()._add(t)}sub(t){return this.clone()._sub(t)}multByPoint(t){return this.clone()._multByPoint(t)}divByPoint(t){return this.clone()._divByPoint(t)}mult(t){return this.clone()._mult(t)}div(t){return this.clone()._div(t)}rotate(t){return this.clone()._rotate(t)}rotateAround(t,e){return this.clone()._rotateAround(t,e)}matMult(t){return this.clone()._matMult(t)}unit(){return this.clone()._unit()}perp(){return this.clone()._perp()}round(){return this.clone()._round()}mag(){return Math.sqrt(this.x*this.x+this.y*this.y)}equals(t){return this.x===t.x&&this.y===t.y}dist(t){return Math.sqrt(this.distSqr(t))}distSqr(t){const e=t.x-this.x,n=t.y-this.y;return e*e+n*n}angle(){return Math.atan2(this.y,this.x)}angleTo(t){return Math.atan2(this.y-t.y,this.x-t.x)}angleWith(t){return this.angleWithSep(t.x,t.y)}angleWithSep(t,e){return Math.atan2(this.x*e-this.y*t,this.x*t+this.y*e)}static convert(t){return t instanceof C?t:Array.isArray(t)?new C(t[0],t[1]):t}}const{supported:Mt,setRTLTextPlugin:Ot,getRTLTextPluginStatus:Ut,LngLat:kt,LngLatBounds:Bt,MercatorCoordinate:$t,Evented:Gt,AJAXError:Ht,prewarm:jt,clearPrewarmedResources:Kt,version:Ft,workerCount:Dt,maxParallelImageRequests:Vt,workerUrl:zt,addProtocol:qt,removeProtocol:Wt}=a,Jt=a.Map,Zt=a.Marker,Yt=a.Popup,Xt=a.Style,Qt=a.CanvasSource,te=a.GeoJSONSource,ee=a.ImageSource,re=a.RasterTileSource,ie=a.RasterDEMTileSource,ne=a.VectorTileSource,ae=a.VideoSource;a.NavigationControl,a.GeolocateControl,a.AttributionControl,a.LogoControl,a.ScaleControl,a.FullscreenControl,a.TerrainControl;export{Ht as AJAXError,j as AttributionControl,bt as CanvasSource,Qt as CanvasSourceMLGL,Gt as Evented,F as FullscreenControl,It as GeoJSONSource,te as GeoJSONSourceMLGL,U as GeolocateControl,q as GeolocationType,wt as ImageSource,ee as ImageSourceMLGL,L as Language,me as LanguageGeocoding,kt as LngLat,Bt as LngLatBounds,N as LogoControl,St as Map,Jt as MapMLGL,ye as MapStyle,Ae as MapStyleVariant,H as MaptilerGeolocateControl,I as MaptilerLogoControl,O as MaptilerNavigationControl,P as MaptilerTerrainControl,xt as Marker,Zt as MarkerMLGL,$t as MercatorCoordinate,M as NavigationControl,C as Point,Ct as Popup,Yt as PopupMLGL,Et as RasterDEMTileSource,ie as RasterDEMTileSourceMLGL,vt as RasterTileSource,re as RasterTileSourceMLGL,fe as ReferenceMapStyle,K as ScaleControl,E as SdkConfig,Le as ServiceError,Tt as Style,Xt as StyleMLGL,Pt as TerrainControl,Nt as VectorTileSource,ne as VectorTileSourceMLGL,Rt as VideoSource,ae as VideoSourceMLGL,qt as addProtocol,Kt as clearPrewarmedResources,A as config,_e as coordinates,Se as data,xe as geocoding,Ce as geolocation,Ut as getRTLTextPluginStatus,Vt as maxParallelImageRequests,jt as prewarm,Wt as removeProtocol,Ot as setRTLTextPlugin,Te as staticMaps,Mt as supported,Ft as version,Dt as workerCount,zt as workerUrl};
1
+ import a from"maplibre-gl";export*from"maplibre-gl";import{Base64 as W}from"js-base64";import{v4 as J}from"uuid";import Z from"events";import{config as T,expandMapStyle as Y,MapStyleVariant as X,ReferenceMapStyle as Q,MapStyle as tt,mapStylePresetList as et,geolocation as E}from"@maptiler/client";import{LanguageGeocoding as me,MapStyle as ye,MapStyleVariant as Le,ReferenceMapStyle as fe,ServiceError as Ae,coordinates as _e,data as Se,geocoding as xe,geolocation as Ce,staticMaps as Te}from"@maptiler/client";const L={AUTO:"auto",STYLE_LOCK:"style_lock",LATIN:"latin",NON_LATIN:"nonlatin",LOCAL:"",ALBANIAN:"sq",AMHARIC:"am",ARABIC:"ar",ARMENIAN:"hy",AZERBAIJANI:"az",BASQUE:"eu",BELORUSSIAN:"be",BOSNIAN:"bs",BRETON:"br",BULGARIAN:"bg",CATALAN:"ca",CHINESE:"zh",CORSICAN:"co",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",HINDI:"hi",HUNGARIAN:"hu",ICELANDIC:"is",INDONESIAN:"id",IRISH:"ga",ITALIAN:"it",JAPANESE:"ja",JAPANESE_HIRAGANA:"ja-Hira",JAPANESE_KANA:"ja_kana",JAPANESE_LATIN:"ja_rm",JAPANESE_2018:"ja-Latn",KANNADA:"kn",KAZAKH:"kk",KOREAN:"ko",KOREAN_LATIN:"ko-Latn",KURDISH:"ku",ROMAN_LATIN:"la",LATVIAN:"lv",LITHUANIAN:"lt",LUXEMBOURGISH:"lb",MACEDONIAN:"mk",MALAYALAM:"ml",MALTESE:"mt",NORWEGIAN:"no",OCCITAN:"oc",POLISH:"pl",PORTUGUESE:"pt",ROMANIAN:"ro",ROMANSH:"rm",RUSSIAN:"ru",SCOTTISH_GAELIC:"gd",SERBIAN_CYRILLIC:"sr",SERBIAN_LATIN:"sr-Latn",SLOVAK:"sk",SLOVENE:"sl",SPANISH:"es",SWEDISH:"sv",TAMIL:"ta",TELUGU:"te",THAI:"th",TURKISH:"tr",UKRAINIAN:"uk",WELSH:"cy"},rt=new Set(Object.values(L));function I(r){return rt.has(r)}const it=new Set(Object.values(L));function b(){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=>it.has(t));return r.length?r[0]:L.LATIN}let v=class extends Z{constructor(){super(),this.primaryLanguage=L.AUTO,this.secondaryLanguage=null,this.session=!0,this._unit="metric",this._apiKey=""}set unit(t){this._unit=t,this.emit("unit",t)}get unit(){return this._unit}set apiKey(t){this._apiKey=t,T.apiKey=t,this.emit("apiKey",t)}get apiKey(){return this._apiKey}set fetch(t){T.fetch=t}get fetch(){return T.fetch}};const f=new v,y={maptilerLogoURL:"https://api.maptiler.com/resources/logo.svg",maptilerURL:"https://www.maptiler.com/",maptilerApiHost:"api.maptiler.com",rtlPluginURL:"https://cdn.maptiler.com/mapbox-gl-rtl-text/v0.2.3/mapbox-gl-rtl-text.min.js",primaryLanguage:L.AUTO,secondaryLanguage:L.LOCAL,terrainSourceURL:"https://api.maptiler.com/tiles/terrain-rgb-v2/tiles.json",terrainSourceId:"maptiler-terrain"};Object.freeze(y);class N extends a.LogoControl{onAdd(t){return super.onAdd(t)}}class w extends N{constructor(t={}){var e,n;super(t),this.logoURL="",this.linkURL="",this.logoURL=(e=t.logoURL)!=null?e:y.maptilerLogoURL,this.linkURL=(n=t.linkURL)!=null?n:y.maptilerURL}onAdd(t){this._map=t,this._compact=this.options&&this.options.compact,this._container=window.document.createElement("div"),this._container.className="maplibregl-ctrl";const e=window.document.createElement("a");return e.style.backgroundRepeat="no-repeat",e.style.cursor="pointer",e.style.display="block",e.style.height="23px",e.style.margin="0 0 -4px -4px",e.style.overflow="hidden",e.style.width="88px",e.style.backgroundImage=`url(${this.logoURL})`,e.style.backgroundSize="100px 30px",e.style.width="100px",e.style.height="30px",e.target="_blank",e.rel="noopener nofollow",e.href=this.linkURL,e.setAttribute("aria-label",this._map._getUIString("LogoControl.Title")),e.setAttribute("rel","noopener nofollow"),this._container.appendChild(e),this._container.style.display="block",this._map.on("resize",this._updateCompact),this._updateCompact(),this._container}}function nt(){a.getRTLTextPluginStatus()==="unavailable"&&a.setRTLTextPlugin(y.rtlPluginURL,null,!0)}function at(r,t){r.forEach(e=>{t[e]&&(t[e]=t[e].bind(t))})}function S(r,t,e){const n=window.document.createElement(r);return t!==void 0&&(n.className=t),e&&e.appendChild(n),n}function ot(r){r.parentNode&&r.parentNode.removeChild(r)}function R(r){return r?typeof r=="string"||r instanceof String?!r.startsWith("http")&&r.toLowerCase().includes(".json")?r:Y(r):r instanceof X?r.getExpandedStyleURL():r instanceof Q?r.getDefaultVariant().getExpandedStyleURL():r:tt[et[0].referenceStyleID].getDefaultVariant().getExpandedStyleURL()}class P{constructor(){at(["_toggleTerrain","_updateTerrainIcon"],this)}onAdd(t){return this._map=t,this._container=S("div","maplibregl-ctrl maplibregl-ctrl-group"),this._terrainButton=S("button","maplibregl-ctrl-terrain",this._container),S("span","maplibregl-ctrl-icon",this._terrainButton).setAttribute("aria-hidden","true"),this._terrainButton.type="button",this._terrainButton.addEventListener("click",this._toggleTerrain),this._updateTerrainIcon(),this._map.on("terrain",this._updateTerrainIcon),this._container}onRemove(){ot(this._container),this._map.off("terrain",this._updateTerrainIcon),this._map=void 0}_toggleTerrain(){this._map.hasTerrain()?this._map.disableTerrain():this._map.enableTerrain(),this._updateTerrainIcon()}_updateTerrainIcon(){this._terrainButton.classList.remove("maplibregl-ctrl-terrain"),this._terrainButton.classList.remove("maplibregl-ctrl-terrain-enabled"),this._map.hasTerrain()?(this._terrainButton.classList.add("maplibregl-ctrl-terrain-enabled"),this._terrainButton.title=this._map._getUIString("TerrainControl.disableTerrain")):(this._terrainButton.classList.add("maplibregl-ctrl-terrain"),this._terrainButton.title=this._map._getUIString("TerrainControl.enableTerrain"))}}class M extends a.NavigationControl{onAdd(t){return super.onAdd(t)}}class O extends M{constructor(){super({showCompass:!0,showZoom:!0,visualizePitch:!0}),this._compass.removeEventListener("click",this._compass.clickFunction),this._compass.addEventListener("click",t=>{this._map.getPitch()===0?this._map.easeTo({pitch:Math.min(this._map.getMaxPitch(),80)}):this.options.visualizePitch?this._map.resetNorthPitch({},{originalEvent:t}):this._map.resetNorth({},{originalEvent:t})})}_createButton(t,e){const n=super._createButton(t,e);return n.clickFunction=e,n}_rotateCompassArrow(){const t=this.options.visualizePitch?`scale(${Math.min(1.5,1/Math.pow(Math.cos(this._map.transform.pitch*(Math.PI/180)),.5))}) rotateX(${Math.min(70,this._map.transform.pitch)}deg) rotateZ(${this._map.transform.angle*(180/Math.PI)}deg)`:`rotate(${this._map.transform.angle*(180/Math.PI)}deg)`;this._compassIcon.style.transform=t}}class U extends a.GeolocateControl{onAdd(t){return super.onAdd(t)}}var st=Object.defineProperty,lt=Object.defineProperties,ct=Object.getOwnPropertyDescriptors,k=Object.getOwnPropertySymbols,ht=Object.prototype.hasOwnProperty,ut=Object.prototype.propertyIsEnumerable,B=(r,t,e)=>t in r?st(r,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):r[t]=e,gt=(r,t)=>{for(var e in t||(t={}))ht.call(t,e)&&B(r,e,t[e]);if(k)for(var e of k(t))ut.call(t,e)&&B(r,e,t[e]);return r},dt=(r,t)=>lt(r,ct(t));const $=a.Marker,G=a.LngLat;class K extends U{constructor(){super(...arguments),this.lastUpdatedCenter=new G(0,0)}_updateCamera(t){const e=new G(t.coords.longitude,t.coords.latitude),n=t.coords.accuracy,s=this._map.getBearing(),g=dt(gt({bearing:s},this.options.fitBoundsOptions),{linear:!0}),u=this._map.getZoom();u>this.options.fitBoundsOptions.maxZoom&&(g.zoom=u),this._map.fitBounds(e.toBounds(n),g,{geolocateSource:!0});let h=!1;const o=()=>{h=!0};this._map.once("click",o),this._map.once("dblclick",o),this._map.once("dragstart",o),this._map.once("mousedown",o),this._map.once("touchstart",o),this._map.once("wheel",o),this._map.once("moveend",()=>{this._map.off("click",o),this._map.off("dblclick",o),this._map.off("dragstart",o),this._map.off("mousedown",o),this._map.off("touchstart",o),this._map.off("wheel",o),!h&&(this.lastUpdatedCenter=this._map.getCenter())})}_setupUI(t){if(this.lastUpdatedCenter=this._map.getCenter(),this._container.addEventListener("contextmenu",e=>e.preventDefault()),this._geolocateButton=S("button","maplibregl-ctrl-geolocate",this._container),S("span","maplibregl-ctrl-icon",this._geolocateButton).setAttribute("aria-hidden","true"),this._geolocateButton.type="button",t===!1){const e=this._map._getUIString("GeolocateControl.LocationNotAvailable");this._geolocateButton.disabled=!0,this._geolocateButton.title=e,this._geolocateButton.setAttribute("aria-label",e)}else{const e=this._map._getUIString("GeolocateControl.FindMyLocation");this._geolocateButton.title=e,this._geolocateButton.setAttribute("aria-label",e)}this.options.trackUserLocation&&(this._geolocateButton.setAttribute("aria-pressed","false"),this._watchState="OFF"),this.options.showUserLocation&&(this._dotElement=S("div","maplibregl-user-location-dot"),this._userLocationDotMarker=new $(this._dotElement),this._circleElement=S("div","maplibregl-user-location-accuracy-circle"),this._accuracyCircleMarker=new $({element:this._circleElement,pitchAlignment:"map"}),this.options.trackUserLocation&&(this._watchState="OFF"),this._map.on("move",this._onZoom)),this._geolocateButton.addEventListener("click",this.trigger.bind(this)),this._setup=!0,this.options.trackUserLocation&&this._map.on("moveend",e=>{const n=e.originalEvent&&e.originalEvent.type==="resize",s=this.lastUpdatedCenter.distanceTo(this._map.getCenter());!e.geolocateSource&&this._watchState==="ACTIVE_LOCK"&&!n&&s>1&&(this._watchState="BACKGROUND",this._geolocateButton.classList.add("maplibregl-ctrl-geolocate-background"),this._geolocateButton.classList.remove("maplibregl-ctrl-geolocate-active"),this.fire(new Event("trackuserlocationend")))})}_updateCircleRadius(){if(this._watchState!=="BACKGROUND"&&this._watchState!=="ACTIVE_LOCK")return;const t=[this._lastKnownPosition.coords.longitude,this._lastKnownPosition.coords.latitude],e=this._map.project(t),n=this._map.unproject([e.x,e.y]),s=this._map.unproject([e.x+20,e.y]),g=n.distanceTo(s)/20,u=Math.ceil(2*this._accuracy/g);this._circleElement.style.width=`${u}px`,this._circleElement.style.height=`${u}px`}_onZoom(){this.options.showUserLocation&&this.options.showAccuracyCircle&&this._updateCircleRadius()}}class H extends a.AttributionControl{onAdd(t){return super.onAdd(t)}}class j extends a.ScaleControl{onAdd(t){return super.onAdd(t)}}class F extends a.FullscreenControl{onAdd(t){return super.onAdd(t)}}var pt=Object.defineProperty,mt=Object.defineProperties,yt=Object.getOwnPropertyDescriptors,D=Object.getOwnPropertySymbols,Lt=Object.prototype.hasOwnProperty,ft=Object.prototype.propertyIsEnumerable,V=(r,t,e)=>t in r?pt(r,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):r[t]=e,At=(r,t)=>{for(var e in t||(t={}))Lt.call(t,e)&&V(r,e,t[e]);if(D)for(var e of D(t))ft.call(t,e)&&V(r,e,t[e]);return r},_t=(r,t)=>mt(r,yt(t)),_=(r,t,e)=>new Promise((n,s)=>{var g=o=>{try{h(e.next(o))}catch(m){s(m)}},u=o=>{try{h(e.throw(o))}catch(m){s(m)}},h=o=>o.done?n(o.value):Promise.resolve(o.value).then(g,u);h((e=e.apply(r,t)).next())});const z=J(),q={POINT:"POINT",COUNTRY:"COUNTRY"};class St extends a.Map{constructor(t){var e,n,s;t.apiKey&&(f.apiKey=t.apiKey);const g=R(t.style),u=location.hash;f.apiKey||console.warn("MapTiler Cloud API key is not set. Visit https://maptiler.com and try Cloud for free!"),super(_t(At({},t),{style:g,maplibreLogo:!1,transformRequest:c=>{let i=null;try{i=new URL(c)}catch{return{url:c,headers:{}}}return i.host===y.maptilerApiHost&&(i.searchParams.has("key")||i.searchParams.append("key",f.apiKey),f.session&&i.searchParams.append("mtsid",z)),{url:i.href,headers:{}}}})),this.isTerrainEnabled=!1,this.terrainExaggeration=1,this.primaryLanguage=null,this.secondaryLanguage=null,this.terrainGrowing=!1,this.terrainFlattening=!1,this.primaryLanguage=(e=t.language)!=null?e:f.primaryLanguage,this.secondaryLanguage=f.secondaryLanguage,this.terrainExaggeration=(n=t.terrainExaggeration)!=null?n:this.terrainExaggeration,this.once("styledata",()=>_(this,null,function*(){if(!t.geolocate||t.center||t.hash&&u)return;try{if(t.geolocate===q.COUNTRY){yield this.fitToIpBounds();return}}catch(i){console.warn(i.message)}let c=null;try{yield this.centerOnIpPoint(t.zoom),c=this.getCameraHash()}catch(i){console.warn(i.message)}(yield navigator.permissions.query({name:"geolocation"})).state==="granted"&&navigator.geolocation.getCurrentPosition(i=>{c===this.getCameraHash()&&(this.terrain?this.easeTo({center:[i.coords.longitude,i.coords.latitude],zoom:t.zoom||12,duration:2e3}):this.once("terrain",()=>{this.easeTo({center:[i.coords.longitude,i.coords.latitude],zoom:t.zoom||12,duration:2e3})}))},null,{maximumAge:24*3600*1e3,timeout:5e3,enableHighAccuracy:!1})})),this.on("styledata",()=>{this.setPrimaryLanguage(this.primaryLanguage),this.setSecondaryLanguage(this.secondaryLanguage)}),this.on("styledata",()=>{this.getTerrain()===null&&this.isTerrainEnabled&&this.enableTerrain(this.terrainExaggeration)}),this.once("load",()=>_(this,null,function*(){nt()})),this.once("load",()=>_(this,null,function*(){let c={logo:null};try{const i=Object.keys(this.style.sourceCaches).map(l=>this.getSource(l)).filter(l=>typeof l.url=="string"&&l.url.includes("tiles.json")),p=new URL(i[0].url);p.searchParams.has("key")||p.searchParams.append("key",f.apiKey),c=yield(yield fetch(p.href)).json()}catch{}if("logo"in c&&c.logo){const i=c.logo;this.addControl(new w({logoURL:i}),t.logoPosition),t.attributionControl===!1&&this.addControl(new H(t))}else t.maptilerLogo&&this.addControl(new w,t.logoPosition);if(t.scaleControl){const i=t.scaleControl===!0||t.scaleControl===void 0?"bottom-right":t.scaleControl,p=new j({unit:f.unit});this.addControl(p,i),f.on("unit",l=>{p.setUnit(l)})}if(t.navigationControl!==!1){const i=t.navigationControl===!0||t.navigationControl===void 0?"top-right":t.navigationControl;this.addControl(new O,i)}if(t.geolocateControl!==!1){const i=t.geolocateControl===!0||t.geolocateControl===void 0?"top-right":t.geolocateControl;this.addControl(new K({positionOptions:{enableHighAccuracy:!0,maximumAge:0,timeout:6e3},fitBoundsOptions:{maxZoom:15},trackUserLocation:!0,showAccuracyCircle:!0,showUserLocation:!0}),i)}if(t.terrainControl){const i=t.terrainControl===!0||t.terrainControl===void 0?"top-right":t.terrainControl;this.addControl(new P,i)}if(t.fullscreenControl){const i=t.fullscreenControl===!0||t.fullscreenControl===void 0?"top-right":t.fullscreenControl;this.addControl(new F({}),i)}}));let h=!1,o=!1,m=null;this.once("load",c=>{h=!0,o&&this.fire("loadWithTerrain",m)});const d=c=>{c.terrain&&(o=!0,m={type:"loadWithTerrain",target:this,terrain:c.terrain},this.off("terrain",d),h&&this.fire("loadWithTerrain",m))};this.on("terrain",d),t.terrain&&this.enableTerrain((s=t.terrainExaggeration)!=null?s:this.terrainExaggeration)}onLoadAsync(){return _(this,null,function*(){return new Promise((t,e)=>{if(this.loaded())return t(this);this.once("load",n=>{t(this)})})})}onLoadWithTerrainAsync(){return _(this,null,function*(){return new Promise((t,e)=>{if(this.loaded()&&this.terrain)return t(this);this.once("loadWithTerrain",n=>{t(this)})})})}setStyle(t,e){return super.setStyle(R(t),e)}setLanguage(t=y.primaryLanguage){if(t===L.AUTO)return this.setLanguage(b());this.setPrimaryLanguage(t)}setPrimaryLanguage(t=y.primaryLanguage){if(this.primaryLanguage===L.STYLE_LOCK){console.warn("The language cannot be changed because this map has been instantiated with the STYLE_LOCK language flag.");return}I(t)&&(this.primaryLanguage=t,this.onStyleReady(()=>{if(t===L.AUTO)return this.setPrimaryLanguage(b());const e=this.getStyle().layers,n=/^\s*{\s*name\s*(:\s*(\S*))?\s*}$/,s=/^\s*name\s*(:\s*(\S*))?\s*$/,g=/^\s*{\s*name\s*(:\s*(\S*))?\s*}(\s*){\s*name\s*(:\s*(\S*))?\s*}$/,u=/^(.*)({\s*name\s*(:\s*(\S*))?\s*})(.*)$/,h=t?`name:${t}`:"name",o=["case",["has",h],["get",h],["get","name"]];for(let m=0;m<e.length;m+=1){const d=e[m],c=d.layout;if(!c||!c["text-field"])continue;const i=this.getLayoutProperty(d.id,"text-field");let p;if(Array.isArray(i)&&i.length>=2&&i[0].trim().toLowerCase()==="concat"){const l=i.slice();for(let x=0;x<i.length;x+=1){const A=i[x];if((typeof A=="string"||A instanceof String)&&n.exec(A.toString())){l[x]=o;break}else if(Array.isArray(A)&&A.length>=2&&A[0].trim().toLowerCase()==="get"&&s.exec(A[1].toString())){l[x]=o;break}else if(Array.isArray(A)&&A.length===4&&A[0].trim().toLowerCase()==="case"){l[x]=o;break}}this.setLayoutProperty(d.id,"text-field",l)}else if(Array.isArray(i)&&i.length>=2&&i[0].trim().toLowerCase()==="get"&&s.exec(i[1].toString())){const l=o;this.setLayoutProperty(d.id,"text-field",l)}else if((typeof i=="string"||i instanceof String)&&n.exec(i.toString())){const l=o;this.setLayoutProperty(d.id,"text-field",l)}else if(Array.isArray(i)&&i.length===4&&i[0].trim().toLowerCase()==="case"){const l=o;this.setLayoutProperty(d.id,"text-field",l)}else if((typeof i=="string"||i instanceof String)&&(p=g.exec(i.toString()))!==null){const l=`{${h}}${p[3]}{name${p[4]||""}}`;this.setLayoutProperty(d.id,"text-field",l)}else if((typeof i=="string"||i instanceof String)&&(p=u.exec(i.toString()))!==null){const l=`${p[1]}{${h}}${p[5]}`;this.setLayoutProperty(d.id,"text-field",l)}}}))}setSecondaryLanguage(t=y.secondaryLanguage){if(this.primaryLanguage===L.STYLE_LOCK){console.warn("The language cannot be changed because this map has been instantiated with the STYLE_LOCK language flag.");return}I(t)&&(this.secondaryLanguage=t,this.onStyleReady(()=>{if(t===L.AUTO)return this.setSecondaryLanguage(b());const e=this.getStyle().layers,n=/^\s*{\s*name\s*(:\s*(\S*))?\s*}$/,s=/^\s*name\s*(:\s*(\S*))?\s*$/,g=/^\s*{\s*name\s*(:\s*(\S*))?\s*}(\s*){\s*name\s*(:\s*(\S*))?\s*}$/;let u;for(let h=0;h<e.length;h+=1){const o=e[h],m=o.layout;if(!m||!m["text-field"])continue;const d=this.getLayoutProperty(o.id,"text-field");let c;if(Array.isArray(d)&&d.length>=2&&d[0].trim().toLowerCase()==="concat"){c=d.slice();let i=0;for(let p=0;p<d.length;p+=1){const l=d[p];if((typeof l=="string"||l instanceof String)&&n.exec(l.toString())){if(i===1){c[p]=`{name:${t}}`;break}i+=1}else if(Array.isArray(l)&&l.length>=2&&l[0].trim().toLowerCase()==="get"&&s.exec(l[1].toString())){if(i===1){c[p][1]=`name:${t}`;break}i+=1}else if(Array.isArray(l)&&l.length===4&&l[0].trim().toLowerCase()==="case"){if(i===1){c[p]=["get",`name:${t}`];break}i+=1}}this.setLayoutProperty(o.id,"text-field",c)}else if((typeof d=="string"||d instanceof String)&&(u=g.exec(d.toString()))!==null){const i=t?`name:${t}`:"name";c=`{name${u[1]||""}}${u[3]}{${i}}`,this.setLayoutProperty(o.id,"text-field",c)}}}))}getPrimaryLanguage(){return this.primaryLanguage}getSecondaryLanguage(){return this.secondaryLanguage}getTerrainExaggeration(){return this.terrainExaggeration}hasTerrain(){return this.isTerrainEnabled}growTerrain(t,e=1e3){if(!this.terrain)return;const n=performance.now(),s=this.terrain.exaggeration,g=t-s,u=()=>{if(!this.terrain||this.terrainFlattening)return;const h=(performance.now()-n)/e;if(h<.99){const o=1-Math.pow(1-h,4),m=s+o*g;this.terrain.exaggeration=m,requestAnimationFrame(u)}else this.terrainGrowing=!1,this.terrainFlattening=!1,this.terrain.exaggeration=t;this.triggerRepaint()};this.terrainGrowing=!0,this.terrainFlattening=!1,requestAnimationFrame(u)}enableTerrain(t=this.terrainExaggeration){if(t<0){console.warn("Terrain exaggeration cannot be negative.");return}const e=s=>_(this,null,function*(){!this.terrain||s.type!=="data"||s.dataType!=="source"||!("source"in s)||s.sourceId!=="maptiler-terrain"||s.source.type!=="raster-dem"||s.isSourceLoaded&&(this.off("data",e),this.growTerrain(t))}),n=()=>{this.isTerrainEnabled=!0,this.terrainExaggeration=t,this.on("data",e),this.addSource(y.terrainSourceId,{type:"raster-dem",url:y.terrainSourceURL}),this.setTerrain({source:y.terrainSourceId,exaggeration:0})};if(this.getTerrain()){this.isTerrainEnabled=!0,this.growTerrain(t);return}this.loaded()||this.isTerrainEnabled?n():this.once("load",()=>{this.getTerrain()&&this.getSource(y.terrainSourceId)||n()})}disableTerrain(){if(!this.terrain)return;this.isTerrainEnabled=!1;const t=1*1e3,e=performance.now(),n=this.terrain.exaggeration,s=()=>{if(!this.terrain||this.terrainGrowing)return;const g=(performance.now()-e)/t;if(g<.99){const u=Math.pow(1-g,4),h=n*u;this.terrain.exaggeration=h,requestAnimationFrame(s)}else this.terrain.exaggeration=0,this.terrainGrowing=!1,this.terrainFlattening=!1,this.setTerrain(null),this.getSource(y.terrainSourceId)&&this.removeSource(y.terrainSourceId);this.triggerRepaint()};this.terrainGrowing=!1,this.terrainFlattening=!0,requestAnimationFrame(s)}setTerrainExaggeration(t,e=!0){!e&&this.terrain?(this.terrainExaggeration=t,this.terrain.exaggeration=t,this.triggerRepaint()):this.enableTerrain(t)}onStyleReady(t){this.isStyleLoaded()?t():this.once("styledata",()=>{t()})}fitToIpBounds(){return _(this,null,function*(){const t=yield E.info();this.fitBounds(t.country_bounds,{duration:0,padding:100})})}centerOnIpPoint(t){return _(this,null,function*(){const e=yield E.info();this.jumpTo({center:[e.longitude,e.latitude],zoom:t||11})})}getCameraHash(){const t=new Float32Array(5),e=this.getCenter();return t[0]=e.lng,t[1]=e.lat,t[2]=this.getZoom(),t[3]=this.getPitch(),t[4]=this.getBearing(),W.fromUint8Array(new Uint8Array(t.buffer))}getSdkConfig(){return f}getMaptilerSessionId(){return z}}class xt extends a.Marker{addTo(t){return super.addTo(t)}}class Ct extends a.Popup{addTo(t){return super.addTo(t)}}class Tt extends a.Style{constructor(t,e={}){super(t,e)}}class bt extends a.CanvasSource{onAdd(t){super.onAdd(t)}}class wt extends a.GeoJSONSource{onAdd(t){super.onAdd(t)}}class Et extends a.ImageSource{onAdd(t){super.onAdd(t)}}class It extends a.RasterTileSource{onAdd(t){super.onAdd(t)}}class vt extends a.RasterDEMTileSource{onAdd(t){super.onAdd(t)}}class Nt extends a.VectorTileSource{onAdd(t){super.onAdd(t)}}class Rt extends a.VideoSource{onAdd(t){super.onAdd(t)}}class Pt extends a.TerrainControl{onAdd(t){return super.onAdd(t)}}class C{constructor(t,e){this.x=t,this.y=e}_matMult(t){const e=t[0]*this.x+t[1]*this.y,n=t[2]*this.x+t[3]*this.y;return this.x=e,this.y=n,this}_add(t){return this.x+=t.x,this.y+=t.y,this}_sub(t){return this.x-=t.x,this.y-=t.y,this}_mult(t){return this.x*=t,this.y*=t,this}_div(t){return this.x/=t,this.y/=t,this}_multByPoint(t){return this.x*=t.x,this.y*=t.y,this}_divByPoint(t){return this.x/=t.x,this.y/=t.y,this}_unit(){return this._div(this.mag()),this}_perp(){const t=this.y;return this.y=this.x,this.x=-t,this}_rotate(t){const e=Math.cos(t),n=Math.sin(t),s=e*this.x-n*this.y,g=n*this.x+e*this.y;return this.x=s,this.y=g,this}_rotateAround(t,e){const n=Math.cos(t),s=Math.sin(t),g=e.x+n*(this.x-e.x)-s*(this.y-e.y),u=e.y+s*(this.x-e.x)+n*(this.y-e.y);return this.x=g,this.y=u,this}_round(){return this.x=Math.round(this.x),this.y=Math.round(this.y),this}clone(){return new C(this.x,this.y)}add(t){return this.clone()._add(t)}sub(t){return this.clone()._sub(t)}multByPoint(t){return this.clone()._multByPoint(t)}divByPoint(t){return this.clone()._divByPoint(t)}mult(t){return this.clone()._mult(t)}div(t){return this.clone()._div(t)}rotate(t){return this.clone()._rotate(t)}rotateAround(t,e){return this.clone()._rotateAround(t,e)}matMult(t){return this.clone()._matMult(t)}unit(){return this.clone()._unit()}perp(){return this.clone()._perp()}round(){return this.clone()._round()}mag(){return Math.sqrt(this.x*this.x+this.y*this.y)}equals(t){return this.x===t.x&&this.y===t.y}dist(t){return Math.sqrt(this.distSqr(t))}distSqr(t){const e=t.x-this.x,n=t.y-this.y;return e*e+n*n}angle(){return Math.atan2(this.y,this.x)}angleTo(t){return Math.atan2(this.y-t.y,this.x-t.x)}angleWith(t){return this.angleWithSep(t.x,t.y)}angleWithSep(t,e){return Math.atan2(this.x*e-this.y*t,this.x*t+this.y*e)}static convert(t){return t instanceof C?t:Array.isArray(t)?new C(t[0],t[1]):t}}const{supported:Mt,setRTLTextPlugin:Ot,getRTLTextPluginStatus:Ut,LngLat:kt,LngLatBounds:Bt,MercatorCoordinate:$t,Evented:Gt,AJAXError:Kt,prewarm:Ht,clearPrewarmedResources:jt,version:Ft,workerCount:Dt,maxParallelImageRequests:Vt,workerUrl:zt,addProtocol:qt,removeProtocol:Wt}=a,Jt=a.Map,Zt=a.Marker,Yt=a.Popup,Xt=a.Style,Qt=a.CanvasSource,te=a.GeoJSONSource,ee=a.ImageSource,re=a.RasterTileSource,ie=a.RasterDEMTileSource,ne=a.VectorTileSource,ae=a.VideoSource;a.NavigationControl,a.GeolocateControl,a.AttributionControl,a.LogoControl,a.ScaleControl,a.FullscreenControl,a.TerrainControl;export{Kt as AJAXError,H as AttributionControl,bt as CanvasSource,Qt as CanvasSourceMLGL,Gt as Evented,F as FullscreenControl,wt as GeoJSONSource,te as GeoJSONSourceMLGL,U as GeolocateControl,q as GeolocationType,Et as ImageSource,ee as ImageSourceMLGL,L as Language,me as LanguageGeocoding,kt as LngLat,Bt as LngLatBounds,N as LogoControl,St as Map,Jt as MapMLGL,ye as MapStyle,Le as MapStyleVariant,K as MaptilerGeolocateControl,w as MaptilerLogoControl,O as MaptilerNavigationControl,P as MaptilerTerrainControl,xt as Marker,Zt as MarkerMLGL,$t as MercatorCoordinate,M as NavigationControl,C as Point,Ct as Popup,Yt as PopupMLGL,vt as RasterDEMTileSource,ie as RasterDEMTileSourceMLGL,It as RasterTileSource,re as RasterTileSourceMLGL,fe as ReferenceMapStyle,j as ScaleControl,v as SdkConfig,Ae as ServiceError,Tt as Style,Xt as StyleMLGL,Pt as TerrainControl,Nt as VectorTileSource,ne as VectorTileSourceMLGL,Rt as VideoSource,ae as VideoSourceMLGL,qt as addProtocol,jt as clearPrewarmedResources,f as config,_e as coordinates,Se as data,xe as geocoding,Ce as geolocation,Ut as getRTLTextPluginStatus,Vt as maxParallelImageRequests,Ht as prewarm,Wt as removeProtocol,Ot as setRTLTextPlugin,Te as staticMaps,Mt as supported,Ft as version,Dt as workerCount,zt as workerUrl};
@@ -11,6 +11,12 @@ const Language = {
11
11
  * AUTO mode uses the language of the browser
12
12
  */
13
13
  AUTO: "auto",
14
+ /**
15
+ * STYLE is a custom flag to keep the language of the map as defined into the style.
16
+ * If STYLE is set in the constructor, then further modification of the language
17
+ * with `.setLanguage()` is not possible.
18
+ */
19
+ STYLE_LOCK: "style_lock",
14
20
  /**
15
21
  * Default fallback languages that uses latin charaters
16
22
  */
@@ -924,6 +930,12 @@ class Map extends maplibregl__default.Map {
924
930
  * @param language
925
931
  */
926
932
  setPrimaryLanguage(language = defaults.primaryLanguage) {
933
+ if (this.primaryLanguage === Language.STYLE_LOCK) {
934
+ console.warn(
935
+ "The language cannot be changed because this map has been instantiated with the STYLE_LOCK language flag."
936
+ );
937
+ return;
938
+ }
927
939
  if (!isLanguageSupported(language)) {
928
940
  return;
929
941
  }
@@ -942,7 +954,7 @@ class Map extends maplibregl__default.Map {
942
954
  "case",
943
955
  ["has", langStr],
944
956
  ["get", langStr],
945
- ["get", "name:latin"]
957
+ ["get", "name"]
946
958
  ];
947
959
  for (let i = 0; i < layers.length; i += 1) {
948
960
  const layer = layers[i];
@@ -1003,6 +1015,12 @@ class Map extends maplibregl__default.Map {
1003
1015
  * @param language
1004
1016
  */
1005
1017
  setSecondaryLanguage(language = defaults.secondaryLanguage) {
1018
+ if (this.primaryLanguage === Language.STYLE_LOCK) {
1019
+ console.warn(
1020
+ "The language cannot be changed because this map has been instantiated with the STYLE_LOCK language flag."
1021
+ );
1022
+ return;
1023
+ }
1006
1024
  if (!isLanguageSupported(language)) {
1007
1025
  return;
1008
1026
  }