@maptiler/sdk 1.0.5 → 1.0.6

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,5 +1,9 @@
1
1
  # Changelog
2
2
 
3
+ ## [v1.0.6](https://github.com/maptiler/maptiler-sdk-js/releases/tag/v1.0.6)
4
+ - Now exposing `MaptilerGeolocateControl` for external initialization if needed
5
+ - Now exposing `MaptilerTerrain` for external initialization if needed
6
+
3
7
  ## [v1.0.5](https://github.com/maptiler/maptiler-sdk-js/releases/tag/v1.0.5)
4
8
  - Terrain elevation is now using MapTiler's `terrain-rgb-v2`
5
9
 
@@ -2248,7 +2248,7 @@
2248
2248
  };
2249
2249
  Object.freeze(defaults);
2250
2250
 
2251
- class CustomLogoControl extends maplibregl.LogoControl {
2251
+ class MaptilerLogoControl extends maplibregl.LogoControl {
2252
2252
  constructor(options = {}) {
2253
2253
  var _a, _b;
2254
2254
  super(options);
@@ -2341,7 +2341,7 @@
2341
2341
  return style;
2342
2342
  }
2343
2343
 
2344
- class TerrainControl$1 {
2344
+ class MaptilerTerrainControl {
2345
2345
  constructor() {
2346
2346
  bindAll(["_toggleTerrain", "_updateTerrainIcon"], this);
2347
2347
  }
@@ -2455,7 +2455,7 @@
2455
2455
  const GeolocateControl$1 = maplibregl.GeolocateControl;
2456
2456
  const Marker$1 = maplibregl.Marker;
2457
2457
  const LngLat$1 = maplibregl.LngLat;
2458
- class CustomGeolocateControl extends GeolocateControl$1 {
2458
+ class MaptilerGeolocateControl extends GeolocateControl$1 {
2459
2459
  constructor() {
2460
2460
  super(...arguments);
2461
2461
  this.lastUpdatedCenter = new LngLat$1(0, 0);
@@ -2771,14 +2771,14 @@
2771
2771
  if ("logo" in tileJsonContent && tileJsonContent.logo) {
2772
2772
  const logoURL = tileJsonContent.logo;
2773
2773
  this.addControl(
2774
- new CustomLogoControl({ logoURL }),
2774
+ new MaptilerLogoControl({ logoURL }),
2775
2775
  options.logoPosition
2776
2776
  );
2777
2777
  if (options.attributionControl === false) {
2778
2778
  this.addControl(new maplibregl.AttributionControl(options));
2779
2779
  }
2780
2780
  } else if (options.maptilerLogo) {
2781
- this.addControl(new CustomLogoControl(), options.logoPosition);
2781
+ this.addControl(new MaptilerLogoControl(), options.logoPosition);
2782
2782
  }
2783
2783
  if (options.scaleControl) {
2784
2784
  const position = options.scaleControl === true || options.scaleControl === void 0 ? "bottom-right" : options.scaleControl;
@@ -2795,7 +2795,7 @@
2795
2795
  if (options.geolocateControl !== false) {
2796
2796
  const position = options.geolocateControl === true || options.geolocateControl === void 0 ? "top-right" : options.geolocateControl;
2797
2797
  this.addControl(
2798
- new CustomGeolocateControl({
2798
+ new MaptilerGeolocateControl({
2799
2799
  positionOptions: {
2800
2800
  enableHighAccuracy: true,
2801
2801
  maximumAge: 0,
@@ -2813,7 +2813,7 @@
2813
2813
  }
2814
2814
  if (options.terrainControl) {
2815
2815
  const position = options.terrainControl === true || options.terrainControl === void 0 ? "top-right" : options.terrainControl;
2816
- this.addControl(new TerrainControl$1(), position);
2816
+ this.addControl(new MaptilerTerrainControl(), position);
2817
2817
  }
2818
2818
  if (options.fullscreenControl) {
2819
2819
  const position = options.fullscreenControl === true || options.fullscreenControl === void 0 ? "top-right" : options.fullscreenControl;
@@ -3269,6 +3269,9 @@
3269
3269
  exports.Map = Map$1;
3270
3270
  exports.MapStyle = MapStyle;
3271
3271
  exports.MapStyleVariant = MapStyleVariant;
3272
+ exports.MaptilerGeolocateControl = MaptilerGeolocateControl;
3273
+ exports.MaptilerLogoControl = MaptilerLogoControl;
3274
+ exports.MaptilerTerrainControl = MaptilerTerrainControl;
3272
3275
  exports.Marker = Marker;
3273
3276
  exports.MercatorCoordinate = MercatorCoordinate;
3274
3277
  exports.NavigationControl = NavigationControl;
@@ -1,5 +1,5 @@
1
1
  import * as maplibre_gl from 'maplibre-gl';
2
- import maplibre_gl__default, { MapOptions as MapOptions$1, StyleSpecification, ControlPosition, StyleOptions } from 'maplibre-gl';
2
+ import maplibre_gl__default, { MapOptions as MapOptions$1, StyleSpecification, ControlPosition, StyleOptions, LogoOptions as LogoOptions$1 } from 'maplibre-gl';
3
3
  export * from 'maplibre-gl';
4
4
  import * as _mapbox_mapbox_gl_supported from '@mapbox/mapbox-gl-supported';
5
5
  import { ReferenceMapStyle, MapStyleVariant, FetchFunction } from '@maptiler/client';
@@ -254,6 +254,57 @@ declare class Map extends maplibre_gl__default.Map {
254
254
  getCameraHash(): string;
255
255
  }
256
256
 
257
+ declare const GeolocateControl$1: typeof maplibre_gl.GeolocateControl;
258
+ /**
259
+ * The MaptilerGeolocateControl is an extension of the original GeolocateControl
260
+ * with a few changes. In this version, the active mode persists as long as the
261
+ * location is still centered. This means it's robust to rotation, pitch and zoom.
262
+ *
263
+ */
264
+ declare class MaptilerGeolocateControl extends GeolocateControl$1 {
265
+ private lastUpdatedCenter;
266
+ /**
267
+ * Update the camera location to center on the current position
268
+ *
269
+ * @param {Position} position the Geolocation API Position
270
+ * @private
271
+ */
272
+ _updateCamera(position: GeolocationPosition): void;
273
+ _setupUI(supported: boolean): void;
274
+ _updateCircleRadius(): void;
275
+ _onZoom(): void;
276
+ }
277
+
278
+ declare type LogoOptions = LogoOptions$1 & {
279
+ logoURL?: string;
280
+ linkURL?: string;
281
+ };
282
+ /**
283
+ * This LogoControl extends the MapLibre LogoControl but instead can use any image URL and
284
+ * any link URL. By default this is using MapTiler logo and URL.
285
+ */
286
+ declare class MaptilerLogoControl extends maplibre_gl__default.LogoControl {
287
+ private logoURL;
288
+ private linkURL;
289
+ constructor(options?: LogoOptions);
290
+ onAdd(map: Map): HTMLElement;
291
+ }
292
+
293
+ /**
294
+ * A `MaptilerTerrainControl` control adds a button to turn terrain on and off
295
+ * by triggering the terrain logic that is already deployed in the Map object.
296
+ */
297
+ declare class MaptilerTerrainControl implements maplibregl.IControl {
298
+ _map: Map;
299
+ _container: HTMLElement;
300
+ _terrainButton: HTMLButtonElement;
301
+ constructor();
302
+ onAdd(map: Map): HTMLElement;
303
+ onRemove(): void;
304
+ _toggleTerrain(): void;
305
+ _updateTerrainIcon(): void;
306
+ }
307
+
257
308
  /**
258
309
  * This is TypeScript rewrite of the Point class to use instead of the version imported in MapLibre.
259
310
  * It also uses a class instead of prototypes.
@@ -528,4 +579,4 @@ declare const workerUrl: string;
528
579
  declare const addProtocol: (customProtocol: string, loadFn: (requestParameters: maplibre_gl.RequestParameters, callback: maplibre_gl.ResponseCallback<any>) => maplibre_gl.Cancelable) => void;
529
580
  declare const removeProtocol: (customProtocol: string) => void;
530
581
 
531
- export { AJAXError, AttributionControl, CanvasSource, Evented, FullscreenControl, GeoJSONSource, GeolocateControl, GeolocationType, ImageSource, Language, LanguageKey, LanguageString, LngLat, LngLatBounds, LogoControl, Map, MapOptions, Marker, Matrix2, MercatorCoordinate, NavigationControl, Point, Popup, RasterDEMTileSource, RasterTileSource, ScaleControl, SdkConfig, Style, TerrainControl, Unit, VectorTileSource, VideoSource, addProtocol, clearPrewarmedResources, clearStorage, config, getRTLTextPluginStatus, maxParallelImageRequests, prewarm, removeProtocol, setRTLTextPlugin, supported, version, workerCount, workerUrl };
582
+ export { AJAXError, AttributionControl, CanvasSource, Evented, FullscreenControl, GeoJSONSource, GeolocateControl, GeolocationType, ImageSource, Language, LanguageKey, LanguageString, LngLat, LngLatBounds, LogoControl, Map, MapOptions, MaptilerGeolocateControl, MaptilerLogoControl, MaptilerTerrainControl, Marker, Matrix2, MercatorCoordinate, NavigationControl, Point, Popup, RasterDEMTileSource, RasterTileSource, ScaleControl, SdkConfig, Style, TerrainControl, Unit, VectorTileSource, VideoSource, addProtocol, clearPrewarmedResources, clearStorage, config, getRTLTextPluginStatus, maxParallelImageRequests, prewarm, removeProtocol, setRTLTextPlugin, supported, version, workerCount, workerUrl };
@@ -1 +1 @@
1
- import m from"maplibre-gl";export*from"maplibre-gl";import{Base64 as j}from"js-base64";import{v4 as K}from"uuid";import G from"events";import{config as x,expandMapStyle as D,MapStyleVariant as z,ReferenceMapStyle as V,MapStyle as F,mapStylePresetList as Z,geolocation as I}from"@maptiler/client";import{LanguageGeocoding as oe,MapStyle as ne,MapStyleVariant as se,ReferenceMapStyle as le,ServiceError as ce,coordinates as he,data as ue,geocoding as ge,geolocation as de,staticMaps as pe}from"@maptiler/client";const S={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"},q=new Set(Object.values(S));function v(r){return q.has(r)}const J=new Set(Object.values(S));function T(){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]:S.LATIN}class E extends G{constructor(){super(),this.primaryLanguage=S.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,x.apiKey=t,this.emit("apiKey",t)}get apiKey(){return this._apiKey}set fetch(t){x.fetch=t}get fetch(){return x.fetch}}const g=new E,d={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:S.AUTO,secondaryLanguage:S.LOCAL,terrainSourceURL:"https://api.maptiler.com/tiles/terrain-rgb-v2/tiles.json",terrainSourceId:"maptiler-terrain"};Object.freeze(d);class N extends m.LogoControl{constructor(t={}){var e,o;super(t),this.logoURL="",this.linkURL="",this.logoURL=(e=t.logoURL)!=null?e:d.maptilerLogoURL,this.linkURL=(o=t.linkURL)!=null?o:d.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 W(){m.getRTLTextPluginStatus()==="unavailable"&&m.setRTLTextPlugin(d.rtlPluginURL,null,!0)}function Y(r,t){r.forEach(e=>{!t[e]||(t[e]=t[e].bind(t))})}function A(r,t,e){const o=window.document.createElement(r);return t!==void 0&&(o.className=t),e&&e.appendChild(o),o}function X(r){r.parentNode&&r.parentNode.removeChild(r)}function w(r){return r?typeof r=="string"||r instanceof String?!r.startsWith("http")&&r.toLowerCase().includes(".json")?r:D(r):r instanceof z?r.getExpandedStyleURL():r instanceof V?r.getDefaultVariant().getExpandedStyleURL():r:F[Z[0].referenceStyleID].getDefaultVariant().getExpandedStyleURL()}class Q{constructor(){Y(["_toggleTerrain","_updateTerrainIcon"],this)}onAdd(t){return this._map=t,this._container=A("div","maplibregl-ctrl maplibregl-ctrl-group"),this._terrainButton=A("button","maplibregl-ctrl-terrain",this._container),A("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(){X(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 tt extends m.NavigationControl{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 o=super._createButton(t,e);return o.clickFunction=e,o}_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}}var et=Object.defineProperty,rt=Object.defineProperties,it=Object.getOwnPropertyDescriptors,R=Object.getOwnPropertySymbols,at=Object.prototype.hasOwnProperty,ot=Object.prototype.propertyIsEnumerable,P=(r,t,e)=>t in r?et(r,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):r[t]=e,nt=(r,t)=>{for(var e in t||(t={}))at.call(t,e)&&P(r,e,t[e]);if(R)for(var e of R(t))ot.call(t,e)&&P(r,e,t[e]);return r},st=(r,t)=>rt(r,it(t));const lt=m.GeolocateControl,O=m.Marker,U=m.LngLat;class ct extends lt{constructor(){super(...arguments),this.lastUpdatedCenter=new U(0,0)}_updateCamera(t){const e=new U(t.coords.longitude,t.coords.latitude),o=t.coords.accuracy,h=this._map.getBearing(),s=st(nt({bearing:h},this.options.fitBoundsOptions),{linear:!0}),i=this._map.getZoom();i>this.options.fitBoundsOptions.maxZoom&&(s.zoom=i),this._map.fitBounds(e.toBounds(o),s,{geolocateSource:!0});let c=!1;const a=()=>{c=!0};this._map.once("click",a),this._map.once("dblclick",a),this._map.once("dragstart",a),this._map.once("mousedown",a),this._map.once("touchstart",a),this._map.once("wheel",a),this._map.once("moveend",()=>{this._map.off("click",a),this._map.off("dblclick",a),this._map.off("dragstart",a),this._map.off("mousedown",a),this._map.off("touchstart",a),this._map.off("wheel",a),!c&&(this.lastUpdatedCenter=this._map.getCenter())})}_setupUI(t){if(this.lastUpdatedCenter=this._map.getCenter(),this._container.addEventListener("contextmenu",e=>e.preventDefault()),this._geolocateButton=A("button","maplibregl-ctrl-geolocate",this._container),A("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=A("div","maplibregl-user-location-dot"),this._userLocationDotMarker=new O(this._dotElement),this._circleElement=A("div","maplibregl-user-location-accuracy-circle"),this._accuracyCircleMarker=new O({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 o=e.originalEvent&&e.originalEvent.type==="resize",h=this.lastUpdatedCenter.distanceTo(this._map.getCenter());!e.geolocateSource&&this._watchState==="ACTIVE_LOCK"&&!o&&h>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),o=this._map.unproject([e.x,e.y]),h=this._map.unproject([e.x+20,e.y]),s=o.distanceTo(h)/20,i=Math.ceil(2*this._accuracy/s);this._circleElement.style.width=`${i}px`,this._circleElement.style.height=`${i}px`}_onZoom(){this.options.showUserLocation&&this.options.showAccuracyCircle&&this._updateCircleRadius()}}var ht=Object.defineProperty,ut=Object.defineProperties,gt=Object.getOwnPropertyDescriptors,k=Object.getOwnPropertySymbols,dt=Object.prototype.hasOwnProperty,pt=Object.prototype.propertyIsEnumerable,M=(r,t,e)=>t in r?ht(r,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):r[t]=e,B=(r,t)=>{for(var e in t||(t={}))dt.call(t,e)&&M(r,e,t[e]);if(k)for(var e of k(t))pt.call(t,e)&&M(r,e,t[e]);return r},$=(r,t)=>ut(r,gt(t)),C=(r,t,e)=>new Promise((o,h)=>{var s=a=>{try{c(e.next(a))}catch(y){h(y)}},i=a=>{try{c(e.throw(a))}catch(y){h(y)}},c=a=>a.done?o(a.value):Promise.resolve(a.value).then(s,i);c((e=e.apply(r,t)).next())});const mt=K(),H={POINT:"POINT",COUNTRY:"COUNTRY"};class yt extends m.Map{constructor(t){var e;const o=w(t.style),h=location.hash;g.apiKey||console.warn("MapTiler Cloud API key is not set. Visit https://maptiler.com and try Cloud for free!"),super($(B({},t),{style:o,maplibreLogo:!1,transformRequest:s=>{let i=null;try{i=new URL(s)}catch{return{url:s,headers:{}}}return i.host===d.maptilerApiHost&&(i.searchParams.has("key")||i.searchParams.append("key",g.apiKey),g.session&&i.searchParams.append("mtsid",mt)),{url:i.href,headers:{}}}})),this.languageShouldUpdate=!1,this.isStyleInitialized=!1,this.isTerrainEnabled=!1,this.terrainExaggeration=1,this.once("styledata",()=>C(this,null,function*(){if(t.geolocate===!1||t.center||t.hash&&!!h)return;try{if(t.geolocate===H.COUNTRY){yield this.fitToIpBounds();return}}catch(i){console.warn(i.message)}let s=null;try{yield this.centerOnIpPoint(t.zoom),s=this.getCameraHash()}catch(i){console.warn(i.message)}(yield navigator.permissions.query({name:"geolocation"})).state==="granted"&&navigator.geolocation.getCurrentPosition(i=>{s===this.getCameraHash()&&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("styledataloading",()=>{this.languageShouldUpdate=!!g.primaryLanguage||!!g.secondaryLanguage}),this.on("styledata",()=>{g.primaryLanguage&&(this.languageShouldUpdate||!this.isStyleInitialized)&&this.setPrimaryLanguage(g.primaryLanguage),g.secondaryLanguage&&(this.languageShouldUpdate||!this.isStyleInitialized)&&this.setSecondaryLanguage(g.secondaryLanguage),this.languageShouldUpdate=!1,this.isStyleInitialized=!0}),this.on("styledata",()=>{this.getTerrain()===null&&this.isTerrainEnabled&&this.enableTerrain(this.terrainExaggeration)}),this.once("load",()=>C(this,null,function*(){W()})),this.once("load",()=>C(this,null,function*(){let s={logo:null};try{const i=Object.keys(this.style.sourceCaches).map(a=>this.getSource(a)).filter(a=>typeof a.url=="string"&&a.url.includes("tiles.json")),c=new URL(i[0].url);c.searchParams.has("key")||c.searchParams.append("key",g.apiKey),s=yield(yield fetch(c.href)).json()}catch{}if("logo"in s&&s.logo){const i=s.logo;this.addControl(new N({logoURL:i}),t.logoPosition),t.attributionControl===!1&&this.addControl(new m.AttributionControl(t))}else t.maptilerLogo&&this.addControl(new N,t.logoPosition);if(t.scaleControl){const i=t.scaleControl===!0||t.scaleControl===void 0?"bottom-right":t.scaleControl,c=new m.ScaleControl({unit:g.unit});this.addControl(c,i),g.on("unit",a=>{c.setUnit(a)})}if(t.navigationControl!==!1){const i=t.navigationControl===!0||t.navigationControl===void 0?"top-right":t.navigationControl;this.addControl(new tt,i)}if(t.geolocateControl!==!1){const i=t.geolocateControl===!0||t.geolocateControl===void 0?"top-right":t.geolocateControl;this.addControl(new ct({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 Q,i)}if(t.fullscreenControl){const i=t.fullscreenControl===!0||t.fullscreenControl===void 0?"top-right":t.fullscreenControl;this.addControl(new m.FullscreenControl({}),i)}})),t.terrain&&this.enableTerrain((e=t.terrainExaggeration)!=null?e:this.terrainExaggeration)}setStyle(t,e){return super.setStyle(w(t),e)}setLanguage(t=d.primaryLanguage){if(t===S.AUTO)return this.setLanguage(T());this.setPrimaryLanguage(t)}setPrimaryLanguage(t=d.primaryLanguage){!v(t)||this.onStyleReady(()=>{if(t===S.AUTO)return this.setPrimaryLanguage(T());g.primaryLanguage=t;const e=this.getStyle().layers,o=/^\s*{\s*name\s*(:\s*(\S*))?\s*}$/,h=/^\s*name\s*(:\s*(\S*))?\s*$/,s=/^\s*{\s*name\s*(:\s*(\S*))?\s*}(\s*){\s*name\s*(:\s*(\S*))?\s*}$/,i=/^(.*)({\s*name\s*(:\s*(\S*))?\s*})(.*)$/,c=t?`name:${t}`:"name",a=["case",["has",c],["get",c],["get","name:latin"]];for(let y=0;y<e.length;y+=1){const u=e[y],f=u.layout;if(!f||!f["text-field"])continue;const n=this.getLayoutProperty(u.id,"text-field");let p;if(Array.isArray(n)&&n.length>=2&&n[0].trim().toLowerCase()==="concat"){const l=n.slice();for(let L=0;L<n.length;L+=1){const _=n[L];if((typeof _=="string"||_ instanceof String)&&o.exec(_.toString())){l[L]=a;break}else if(Array.isArray(_)&&_.length>=2&&_[0].trim().toLowerCase()==="get"&&h.exec(_[1].toString())){l[L]=a;break}else if(Array.isArray(_)&&_.length===4&&_[0].trim().toLowerCase()==="case"){l[L]=a;break}}this.setLayoutProperty(u.id,"text-field",l)}else if(Array.isArray(n)&&n.length>=2&&n[0].trim().toLowerCase()==="get"&&h.exec(n[1].toString())){const l=a;this.setLayoutProperty(u.id,"text-field",l)}else if((typeof n=="string"||n instanceof String)&&o.exec(n.toString())){const l=a;this.setLayoutProperty(u.id,"text-field",l)}else if(Array.isArray(n)&&n.length===4&&n[0].trim().toLowerCase()==="case"){const l=a;this.setLayoutProperty(u.id,"text-field",l)}else if((typeof n=="string"||n instanceof String)&&(p=s.exec(n.toString()))!==null){const l=`{${c}}${p[3]}{name${p[4]||""}}`;this.setLayoutProperty(u.id,"text-field",l)}else if((typeof n=="string"||n instanceof String)&&(p=i.exec(n.toString()))!==null){const l=`${p[1]}{${c}}${p[5]}`;this.setLayoutProperty(u.id,"text-field",l)}}})}setSecondaryLanguage(t=d.secondaryLanguage){!v(t)||this.onStyleReady(()=>{if(t===S.AUTO)return this.setSecondaryLanguage(T());g.secondaryLanguage=t;const e=this.getStyle().layers,o=/^\s*{\s*name\s*(:\s*(\S*))?\s*}$/,h=/^\s*name\s*(:\s*(\S*))?\s*$/,s=/^\s*{\s*name\s*(:\s*(\S*))?\s*}(\s*){\s*name\s*(:\s*(\S*))?\s*}$/;let i;for(let c=0;c<e.length;c+=1){const a=e[c],y=a.layout;if(!y||!y["text-field"])continue;const u=this.getLayoutProperty(a.id,"text-field");let f;if(Array.isArray(u)&&u.length>=2&&u[0].trim().toLowerCase()==="concat"){f=u.slice();let n=0;for(let p=0;p<u.length;p+=1){const l=u[p];if((typeof l=="string"||l instanceof String)&&o.exec(l.toString())){if(n===1){f[p]=`{name:${t}}`;break}n+=1}else if(Array.isArray(l)&&l.length>=2&&l[0].trim().toLowerCase()==="get"&&h.exec(l[1].toString())){if(n===1){f[p][1]=`name:${t}`;break}n+=1}else if(Array.isArray(l)&&l.length===4&&l[0].trim().toLowerCase()==="case"){if(n===1){f[p]=["get",`name:${t}`];break}n+=1}}this.setLayoutProperty(a.id,"text-field",f)}else if((typeof u=="string"||u instanceof String)&&(i=s.exec(u.toString()))!==null){const n=t?`name:${t}`:"name";f=`{name${i[1]||""}}${i[3]}{${n}}`,this.setLayoutProperty(a.id,"text-field",f)}}})}getTerrainExaggeration(){return this.terrainExaggeration}hasTerrain(){return this.isTerrainEnabled}enableTerrain(t=this.terrainExaggeration){if(t<0){console.warn("Terrain exaggeration cannot be negative.");return}const e=this.getTerrain(),o=()=>{this.isTerrainEnabled=!0,this.terrainExaggeration=t,this.addSource(d.terrainSourceId,{type:"raster-dem",url:d.terrainSourceURL}),this.setTerrain({source:d.terrainSourceId,exaggeration:t})};if(e){this.setTerrain($(B({},e),{exaggeration:t}));return}this.loaded()||this.isTerrainEnabled?o():this.once("load",()=>{this.getTerrain()&&this.getSource(d.terrainSourceId)||o()})}disableTerrain(){this.isTerrainEnabled=!1,this.setTerrain(null),this.getSource(d.terrainSourceId)&&this.removeSource(d.terrainSourceId)}setTerrainExaggeration(t){this.enableTerrain(t)}onStyleReady(t){this.isStyleLoaded()?t():this.once("styledata",()=>{t()})}fitToIpBounds(){return C(this,null,function*(){const t=yield I.info();this.fitBounds(t.country_bounds,{duration:0,padding:100})})}centerOnIpPoint(t){return C(this,null,function*(){const e=yield I.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(),j.fromUint8Array(new Uint8Array(t.buffer))}}class b{constructor(t,e){this.x=t,this.y=e}_matMult(t){const e=t[0]*this.x+t[1]*this.y,o=t[2]*this.x+t[3]*this.y;return this.x=e,this.y=o,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),o=Math.sin(t),h=e*this.x-o*this.y,s=o*this.x+e*this.y;return this.x=h,this.y=s,this}_rotateAround(t,e){const o=Math.cos(t),h=Math.sin(t),s=e.x+o*(this.x-e.x)-h*(this.y-e.y),i=e.y+h*(this.x-e.x)+o*(this.y-e.y);return this.x=s,this.y=i,this}_round(){return this.x=Math.round(this.x),this.y=Math.round(this.y),this}clone(){return new b(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,o=t.y-this.y;return e*e+o*o}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 b?t:Array.isArray(t)?new b(t[0],t[1]):t}}const{supported:ft,setRTLTextPlugin:_t,getRTLTextPluginStatus:St,NavigationControl:At,GeolocateControl:Lt,AttributionControl:Ct,LogoControl:bt,ScaleControl:xt,FullscreenControl:Tt,TerrainControl:It,Popup:vt,Marker:Et,Style:Nt,LngLat:wt,LngLatBounds:Rt,MercatorCoordinate:Pt,Evented:Ot,AJAXError:Ut,CanvasSource:kt,GeoJSONSource:Mt,ImageSource:Bt,RasterDEMTileSource:$t,RasterTileSource:Ht,VectorTileSource:jt,VideoSource:Kt,prewarm:Gt,clearPrewarmedResources:Dt,version:zt,workerCount:Vt,maxParallelImageRequests:Ft,clearStorage:Zt,workerUrl:qt,addProtocol:Jt,removeProtocol:Wt}=m;export{Ut as AJAXError,Ct as AttributionControl,kt as CanvasSource,Ot as Evented,Tt as FullscreenControl,Mt as GeoJSONSource,Lt as GeolocateControl,H as GeolocationType,Bt as ImageSource,S as Language,oe as LanguageGeocoding,wt as LngLat,Rt as LngLatBounds,bt as LogoControl,yt as Map,ne as MapStyle,se as MapStyleVariant,Et as Marker,Pt as MercatorCoordinate,At as NavigationControl,b as Point,vt as Popup,$t as RasterDEMTileSource,Ht as RasterTileSource,le as ReferenceMapStyle,xt as ScaleControl,E as SdkConfig,ce as ServiceError,Nt as Style,It as TerrainControl,jt as VectorTileSource,Kt as VideoSource,Jt as addProtocol,Dt as clearPrewarmedResources,Zt as clearStorage,g as config,he as coordinates,ue as data,ge as geocoding,de as geolocation,St as getRTLTextPluginStatus,Ft as maxParallelImageRequests,Gt as prewarm,Wt as removeProtocol,_t as setRTLTextPlugin,pe as staticMaps,ft as supported,zt as version,Vt as workerCount,qt as workerUrl};
1
+ import m from"maplibre-gl";export*from"maplibre-gl";import{Base64 as G}from"js-base64";import{v4 as D}from"uuid";import z from"events";import{config as x,expandMapStyle as V,MapStyleVariant as F,ReferenceMapStyle as Z,MapStyle as q,mapStylePresetList as J,geolocation as v}from"@maptiler/client";import{LanguageGeocoding as oe,MapStyle as ne,MapStyleVariant as se,ReferenceMapStyle as le,ServiceError as ce,coordinates as he,data as ue,geocoding as ge,geolocation as pe,staticMaps as de}from"@maptiler/client";const S={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"},W=new Set(Object.values(S));function E(r){return W.has(r)}const Y=new Set(Object.values(S));function T(){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=>Y.has(t));return r.length?r[0]:S.LATIN}class N extends z{constructor(){super(),this.primaryLanguage=S.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,x.apiKey=t,this.emit("apiKey",t)}get apiKey(){return this._apiKey}set fetch(t){x.fetch=t}get fetch(){return x.fetch}}const g=new N,p={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:S.AUTO,secondaryLanguage:S.LOCAL,terrainSourceURL:"https://api.maptiler.com/tiles/terrain-rgb-v2/tiles.json",terrainSourceId:"maptiler-terrain"};Object.freeze(p);class I extends m.LogoControl{constructor(t={}){var e,o;super(t),this.logoURL="",this.linkURL="",this.logoURL=(e=t.logoURL)!=null?e:p.maptilerLogoURL,this.linkURL=(o=t.linkURL)!=null?o:p.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 X(){m.getRTLTextPluginStatus()==="unavailable"&&m.setRTLTextPlugin(p.rtlPluginURL,null,!0)}function Q(r,t){r.forEach(e=>{!t[e]||(t[e]=t[e].bind(t))})}function A(r,t,e){const o=window.document.createElement(r);return t!==void 0&&(o.className=t),e&&e.appendChild(o),o}function tt(r){r.parentNode&&r.parentNode.removeChild(r)}function w(r){return r?typeof r=="string"||r instanceof String?!r.startsWith("http")&&r.toLowerCase().includes(".json")?r:V(r):r instanceof F?r.getExpandedStyleURL():r instanceof Z?r.getDefaultVariant().getExpandedStyleURL():r:q[J[0].referenceStyleID].getDefaultVariant().getExpandedStyleURL()}class R{constructor(){Q(["_toggleTerrain","_updateTerrainIcon"],this)}onAdd(t){return this._map=t,this._container=A("div","maplibregl-ctrl maplibregl-ctrl-group"),this._terrainButton=A("button","maplibregl-ctrl-terrain",this._container),A("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(){tt(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 et extends m.NavigationControl{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 o=super._createButton(t,e);return o.clickFunction=e,o}_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}}var rt=Object.defineProperty,it=Object.defineProperties,at=Object.getOwnPropertyDescriptors,P=Object.getOwnPropertySymbols,ot=Object.prototype.hasOwnProperty,nt=Object.prototype.propertyIsEnumerable,O=(r,t,e)=>t in r?rt(r,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):r[t]=e,st=(r,t)=>{for(var e in t||(t={}))ot.call(t,e)&&O(r,e,t[e]);if(P)for(var e of P(t))nt.call(t,e)&&O(r,e,t[e]);return r},lt=(r,t)=>it(r,at(t));const ct=m.GeolocateControl,U=m.Marker,M=m.LngLat;class k extends ct{constructor(){super(...arguments),this.lastUpdatedCenter=new M(0,0)}_updateCamera(t){const e=new M(t.coords.longitude,t.coords.latitude),o=t.coords.accuracy,h=this._map.getBearing(),s=lt(st({bearing:h},this.options.fitBoundsOptions),{linear:!0}),i=this._map.getZoom();i>this.options.fitBoundsOptions.maxZoom&&(s.zoom=i),this._map.fitBounds(e.toBounds(o),s,{geolocateSource:!0});let c=!1;const a=()=>{c=!0};this._map.once("click",a),this._map.once("dblclick",a),this._map.once("dragstart",a),this._map.once("mousedown",a),this._map.once("touchstart",a),this._map.once("wheel",a),this._map.once("moveend",()=>{this._map.off("click",a),this._map.off("dblclick",a),this._map.off("dragstart",a),this._map.off("mousedown",a),this._map.off("touchstart",a),this._map.off("wheel",a),!c&&(this.lastUpdatedCenter=this._map.getCenter())})}_setupUI(t){if(this.lastUpdatedCenter=this._map.getCenter(),this._container.addEventListener("contextmenu",e=>e.preventDefault()),this._geolocateButton=A("button","maplibregl-ctrl-geolocate",this._container),A("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=A("div","maplibregl-user-location-dot"),this._userLocationDotMarker=new U(this._dotElement),this._circleElement=A("div","maplibregl-user-location-accuracy-circle"),this._accuracyCircleMarker=new U({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 o=e.originalEvent&&e.originalEvent.type==="resize",h=this.lastUpdatedCenter.distanceTo(this._map.getCenter());!e.geolocateSource&&this._watchState==="ACTIVE_LOCK"&&!o&&h>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),o=this._map.unproject([e.x,e.y]),h=this._map.unproject([e.x+20,e.y]),s=o.distanceTo(h)/20,i=Math.ceil(2*this._accuracy/s);this._circleElement.style.width=`${i}px`,this._circleElement.style.height=`${i}px`}_onZoom(){this.options.showUserLocation&&this.options.showAccuracyCircle&&this._updateCircleRadius()}}var ht=Object.defineProperty,ut=Object.defineProperties,gt=Object.getOwnPropertyDescriptors,B=Object.getOwnPropertySymbols,pt=Object.prototype.hasOwnProperty,dt=Object.prototype.propertyIsEnumerable,$=(r,t,e)=>t in r?ht(r,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):r[t]=e,H=(r,t)=>{for(var e in t||(t={}))pt.call(t,e)&&$(r,e,t[e]);if(B)for(var e of B(t))dt.call(t,e)&&$(r,e,t[e]);return r},j=(r,t)=>ut(r,gt(t)),C=(r,t,e)=>new Promise((o,h)=>{var s=a=>{try{c(e.next(a))}catch(y){h(y)}},i=a=>{try{c(e.throw(a))}catch(y){h(y)}},c=a=>a.done?o(a.value):Promise.resolve(a.value).then(s,i);c((e=e.apply(r,t)).next())});const mt=D(),K={POINT:"POINT",COUNTRY:"COUNTRY"};class yt extends m.Map{constructor(t){var e;const o=w(t.style),h=location.hash;g.apiKey||console.warn("MapTiler Cloud API key is not set. Visit https://maptiler.com and try Cloud for free!"),super(j(H({},t),{style:o,maplibreLogo:!1,transformRequest:s=>{let i=null;try{i=new URL(s)}catch{return{url:s,headers:{}}}return i.host===p.maptilerApiHost&&(i.searchParams.has("key")||i.searchParams.append("key",g.apiKey),g.session&&i.searchParams.append("mtsid",mt)),{url:i.href,headers:{}}}})),this.languageShouldUpdate=!1,this.isStyleInitialized=!1,this.isTerrainEnabled=!1,this.terrainExaggeration=1,this.once("styledata",()=>C(this,null,function*(){if(t.geolocate===!1||t.center||t.hash&&!!h)return;try{if(t.geolocate===K.COUNTRY){yield this.fitToIpBounds();return}}catch(i){console.warn(i.message)}let s=null;try{yield this.centerOnIpPoint(t.zoom),s=this.getCameraHash()}catch(i){console.warn(i.message)}(yield navigator.permissions.query({name:"geolocation"})).state==="granted"&&navigator.geolocation.getCurrentPosition(i=>{s===this.getCameraHash()&&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("styledataloading",()=>{this.languageShouldUpdate=!!g.primaryLanguage||!!g.secondaryLanguage}),this.on("styledata",()=>{g.primaryLanguage&&(this.languageShouldUpdate||!this.isStyleInitialized)&&this.setPrimaryLanguage(g.primaryLanguage),g.secondaryLanguage&&(this.languageShouldUpdate||!this.isStyleInitialized)&&this.setSecondaryLanguage(g.secondaryLanguage),this.languageShouldUpdate=!1,this.isStyleInitialized=!0}),this.on("styledata",()=>{this.getTerrain()===null&&this.isTerrainEnabled&&this.enableTerrain(this.terrainExaggeration)}),this.once("load",()=>C(this,null,function*(){X()})),this.once("load",()=>C(this,null,function*(){let s={logo:null};try{const i=Object.keys(this.style.sourceCaches).map(a=>this.getSource(a)).filter(a=>typeof a.url=="string"&&a.url.includes("tiles.json")),c=new URL(i[0].url);c.searchParams.has("key")||c.searchParams.append("key",g.apiKey),s=yield(yield fetch(c.href)).json()}catch{}if("logo"in s&&s.logo){const i=s.logo;this.addControl(new I({logoURL:i}),t.logoPosition),t.attributionControl===!1&&this.addControl(new m.AttributionControl(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,c=new m.ScaleControl({unit:g.unit});this.addControl(c,i),g.on("unit",a=>{c.setUnit(a)})}if(t.navigationControl!==!1){const i=t.navigationControl===!0||t.navigationControl===void 0?"top-right":t.navigationControl;this.addControl(new et,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 R,i)}if(t.fullscreenControl){const i=t.fullscreenControl===!0||t.fullscreenControl===void 0?"top-right":t.fullscreenControl;this.addControl(new m.FullscreenControl({}),i)}})),t.terrain&&this.enableTerrain((e=t.terrainExaggeration)!=null?e:this.terrainExaggeration)}setStyle(t,e){return super.setStyle(w(t),e)}setLanguage(t=p.primaryLanguage){if(t===S.AUTO)return this.setLanguage(T());this.setPrimaryLanguage(t)}setPrimaryLanguage(t=p.primaryLanguage){!E(t)||this.onStyleReady(()=>{if(t===S.AUTO)return this.setPrimaryLanguage(T());g.primaryLanguage=t;const e=this.getStyle().layers,o=/^\s*{\s*name\s*(:\s*(\S*))?\s*}$/,h=/^\s*name\s*(:\s*(\S*))?\s*$/,s=/^\s*{\s*name\s*(:\s*(\S*))?\s*}(\s*){\s*name\s*(:\s*(\S*))?\s*}$/,i=/^(.*)({\s*name\s*(:\s*(\S*))?\s*})(.*)$/,c=t?`name:${t}`:"name",a=["case",["has",c],["get",c],["get","name:latin"]];for(let y=0;y<e.length;y+=1){const u=e[y],f=u.layout;if(!f||!f["text-field"])continue;const n=this.getLayoutProperty(u.id,"text-field");let d;if(Array.isArray(n)&&n.length>=2&&n[0].trim().toLowerCase()==="concat"){const l=n.slice();for(let L=0;L<n.length;L+=1){const _=n[L];if((typeof _=="string"||_ instanceof String)&&o.exec(_.toString())){l[L]=a;break}else if(Array.isArray(_)&&_.length>=2&&_[0].trim().toLowerCase()==="get"&&h.exec(_[1].toString())){l[L]=a;break}else if(Array.isArray(_)&&_.length===4&&_[0].trim().toLowerCase()==="case"){l[L]=a;break}}this.setLayoutProperty(u.id,"text-field",l)}else if(Array.isArray(n)&&n.length>=2&&n[0].trim().toLowerCase()==="get"&&h.exec(n[1].toString())){const l=a;this.setLayoutProperty(u.id,"text-field",l)}else if((typeof n=="string"||n instanceof String)&&o.exec(n.toString())){const l=a;this.setLayoutProperty(u.id,"text-field",l)}else if(Array.isArray(n)&&n.length===4&&n[0].trim().toLowerCase()==="case"){const l=a;this.setLayoutProperty(u.id,"text-field",l)}else if((typeof n=="string"||n instanceof String)&&(d=s.exec(n.toString()))!==null){const l=`{${c}}${d[3]}{name${d[4]||""}}`;this.setLayoutProperty(u.id,"text-field",l)}else if((typeof n=="string"||n instanceof String)&&(d=i.exec(n.toString()))!==null){const l=`${d[1]}{${c}}${d[5]}`;this.setLayoutProperty(u.id,"text-field",l)}}})}setSecondaryLanguage(t=p.secondaryLanguage){!E(t)||this.onStyleReady(()=>{if(t===S.AUTO)return this.setSecondaryLanguage(T());g.secondaryLanguage=t;const e=this.getStyle().layers,o=/^\s*{\s*name\s*(:\s*(\S*))?\s*}$/,h=/^\s*name\s*(:\s*(\S*))?\s*$/,s=/^\s*{\s*name\s*(:\s*(\S*))?\s*}(\s*){\s*name\s*(:\s*(\S*))?\s*}$/;let i;for(let c=0;c<e.length;c+=1){const a=e[c],y=a.layout;if(!y||!y["text-field"])continue;const u=this.getLayoutProperty(a.id,"text-field");let f;if(Array.isArray(u)&&u.length>=2&&u[0].trim().toLowerCase()==="concat"){f=u.slice();let n=0;for(let d=0;d<u.length;d+=1){const l=u[d];if((typeof l=="string"||l instanceof String)&&o.exec(l.toString())){if(n===1){f[d]=`{name:${t}}`;break}n+=1}else if(Array.isArray(l)&&l.length>=2&&l[0].trim().toLowerCase()==="get"&&h.exec(l[1].toString())){if(n===1){f[d][1]=`name:${t}`;break}n+=1}else if(Array.isArray(l)&&l.length===4&&l[0].trim().toLowerCase()==="case"){if(n===1){f[d]=["get",`name:${t}`];break}n+=1}}this.setLayoutProperty(a.id,"text-field",f)}else if((typeof u=="string"||u instanceof String)&&(i=s.exec(u.toString()))!==null){const n=t?`name:${t}`:"name";f=`{name${i[1]||""}}${i[3]}{${n}}`,this.setLayoutProperty(a.id,"text-field",f)}}})}getTerrainExaggeration(){return this.terrainExaggeration}hasTerrain(){return this.isTerrainEnabled}enableTerrain(t=this.terrainExaggeration){if(t<0){console.warn("Terrain exaggeration cannot be negative.");return}const e=this.getTerrain(),o=()=>{this.isTerrainEnabled=!0,this.terrainExaggeration=t,this.addSource(p.terrainSourceId,{type:"raster-dem",url:p.terrainSourceURL}),this.setTerrain({source:p.terrainSourceId,exaggeration:t})};if(e){this.setTerrain(j(H({},e),{exaggeration:t}));return}this.loaded()||this.isTerrainEnabled?o():this.once("load",()=>{this.getTerrain()&&this.getSource(p.terrainSourceId)||o()})}disableTerrain(){this.isTerrainEnabled=!1,this.setTerrain(null),this.getSource(p.terrainSourceId)&&this.removeSource(p.terrainSourceId)}setTerrainExaggeration(t){this.enableTerrain(t)}onStyleReady(t){this.isStyleLoaded()?t():this.once("styledata",()=>{t()})}fitToIpBounds(){return C(this,null,function*(){const t=yield v.info();this.fitBounds(t.country_bounds,{duration:0,padding:100})})}centerOnIpPoint(t){return C(this,null,function*(){const e=yield v.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(),G.fromUint8Array(new Uint8Array(t.buffer))}}class b{constructor(t,e){this.x=t,this.y=e}_matMult(t){const e=t[0]*this.x+t[1]*this.y,o=t[2]*this.x+t[3]*this.y;return this.x=e,this.y=o,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),o=Math.sin(t),h=e*this.x-o*this.y,s=o*this.x+e*this.y;return this.x=h,this.y=s,this}_rotateAround(t,e){const o=Math.cos(t),h=Math.sin(t),s=e.x+o*(this.x-e.x)-h*(this.y-e.y),i=e.y+h*(this.x-e.x)+o*(this.y-e.y);return this.x=s,this.y=i,this}_round(){return this.x=Math.round(this.x),this.y=Math.round(this.y),this}clone(){return new b(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,o=t.y-this.y;return e*e+o*o}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 b?t:Array.isArray(t)?new b(t[0],t[1]):t}}const{supported:ft,setRTLTextPlugin:_t,getRTLTextPluginStatus:St,NavigationControl:At,GeolocateControl:Lt,AttributionControl:Ct,LogoControl:bt,ScaleControl:xt,FullscreenControl:Tt,TerrainControl:It,Popup:vt,Marker:Et,Style:Nt,LngLat:wt,LngLatBounds:Rt,MercatorCoordinate:Pt,Evented:Ot,AJAXError:Ut,CanvasSource:Mt,GeoJSONSource:kt,ImageSource:Bt,RasterDEMTileSource:$t,RasterTileSource:Ht,VectorTileSource:jt,VideoSource:Kt,prewarm:Gt,clearPrewarmedResources:Dt,version:zt,workerCount:Vt,maxParallelImageRequests:Ft,clearStorage:Zt,workerUrl:qt,addProtocol:Jt,removeProtocol:Wt}=m;export{Ut as AJAXError,Ct as AttributionControl,Mt as CanvasSource,Ot as Evented,Tt as FullscreenControl,kt as GeoJSONSource,Lt as GeolocateControl,K as GeolocationType,Bt as ImageSource,S as Language,oe as LanguageGeocoding,wt as LngLat,Rt as LngLatBounds,bt as LogoControl,yt as Map,ne as MapStyle,se as MapStyleVariant,k as MaptilerGeolocateControl,I as MaptilerLogoControl,R as MaptilerTerrainControl,Et as Marker,Pt as MercatorCoordinate,At as NavigationControl,b as Point,vt as Popup,$t as RasterDEMTileSource,Ht as RasterTileSource,le as ReferenceMapStyle,xt as ScaleControl,N as SdkConfig,ce as ServiceError,Nt as Style,It as TerrainControl,jt as VectorTileSource,Kt as VideoSource,Jt as addProtocol,Dt as clearPrewarmedResources,Zt as clearStorage,g as config,he as coordinates,ue as data,ge as geocoding,pe as geolocation,St as getRTLTextPluginStatus,Ft as maxParallelImageRequests,Gt as prewarm,Wt as removeProtocol,_t as setRTLTextPlugin,de as staticMaps,ft as supported,zt as version,Vt as workerCount,qt as workerUrl};
@@ -142,7 +142,7 @@ const defaults = {
142
142
  };
143
143
  Object.freeze(defaults);
144
144
 
145
- class CustomLogoControl extends maplibregl__default.LogoControl {
145
+ class MaptilerLogoControl extends maplibregl__default.LogoControl {
146
146
  constructor(options = {}) {
147
147
  var _a, _b;
148
148
  super(options);
@@ -235,7 +235,7 @@ function styleToStyle(style) {
235
235
  return style;
236
236
  }
237
237
 
238
- class TerrainControl$1 {
238
+ class MaptilerTerrainControl {
239
239
  constructor() {
240
240
  bindAll(["_toggleTerrain", "_updateTerrainIcon"], this);
241
241
  }
@@ -349,7 +349,7 @@ var __spreadProps$1 = (a, b) => __defProps$1(a, __getOwnPropDescs$1(b));
349
349
  const GeolocateControl$1 = maplibregl__default.GeolocateControl;
350
350
  const Marker$1 = maplibregl__default.Marker;
351
351
  const LngLat$1 = maplibregl__default.LngLat;
352
- class CustomGeolocateControl extends GeolocateControl$1 {
352
+ class MaptilerGeolocateControl extends GeolocateControl$1 {
353
353
  constructor() {
354
354
  super(...arguments);
355
355
  this.lastUpdatedCenter = new LngLat$1(0, 0);
@@ -665,14 +665,14 @@ class Map extends maplibregl__default.Map {
665
665
  if ("logo" in tileJsonContent && tileJsonContent.logo) {
666
666
  const logoURL = tileJsonContent.logo;
667
667
  this.addControl(
668
- new CustomLogoControl({ logoURL }),
668
+ new MaptilerLogoControl({ logoURL }),
669
669
  options.logoPosition
670
670
  );
671
671
  if (options.attributionControl === false) {
672
672
  this.addControl(new maplibregl__default.AttributionControl(options));
673
673
  }
674
674
  } else if (options.maptilerLogo) {
675
- this.addControl(new CustomLogoControl(), options.logoPosition);
675
+ this.addControl(new MaptilerLogoControl(), options.logoPosition);
676
676
  }
677
677
  if (options.scaleControl) {
678
678
  const position = options.scaleControl === true || options.scaleControl === void 0 ? "bottom-right" : options.scaleControl;
@@ -689,7 +689,7 @@ class Map extends maplibregl__default.Map {
689
689
  if (options.geolocateControl !== false) {
690
690
  const position = options.geolocateControl === true || options.geolocateControl === void 0 ? "top-right" : options.geolocateControl;
691
691
  this.addControl(
692
- new CustomGeolocateControl({
692
+ new MaptilerGeolocateControl({
693
693
  positionOptions: {
694
694
  enableHighAccuracy: true,
695
695
  maximumAge: 0,
@@ -707,7 +707,7 @@ class Map extends maplibregl__default.Map {
707
707
  }
708
708
  if (options.terrainControl) {
709
709
  const position = options.terrainControl === true || options.terrainControl === void 0 ? "top-right" : options.terrainControl;
710
- this.addControl(new TerrainControl$1(), position);
710
+ this.addControl(new MaptilerTerrainControl(), position);
711
711
  }
712
712
  if (options.fullscreenControl) {
713
713
  const position = options.fullscreenControl === true || options.fullscreenControl === void 0 ? "top-right" : options.fullscreenControl;
@@ -1146,5 +1146,5 @@ const {
1146
1146
  removeProtocol
1147
1147
  } = maplibregl__default;
1148
1148
 
1149
- export { AJAXError, AttributionControl, CanvasSource, Evented, FullscreenControl, GeoJSONSource, GeolocateControl, GeolocationType, ImageSource, Language, LngLat, LngLatBounds, LogoControl, Map, Marker, MercatorCoordinate, NavigationControl, Point, Popup, RasterDEMTileSource, RasterTileSource, ScaleControl, SdkConfig, Style, TerrainControl, VectorTileSource, VideoSource, addProtocol, clearPrewarmedResources, clearStorage, config, getRTLTextPluginStatus, maxParallelImageRequests, prewarm, removeProtocol, setRTLTextPlugin, supported, version, workerCount, workerUrl };
1149
+ export { AJAXError, AttributionControl, CanvasSource, Evented, FullscreenControl, GeoJSONSource, GeolocateControl, GeolocationType, ImageSource, Language, LngLat, LngLatBounds, LogoControl, Map, MaptilerGeolocateControl, MaptilerLogoControl, MaptilerTerrainControl, Marker, MercatorCoordinate, NavigationControl, Point, Popup, RasterDEMTileSource, RasterTileSource, ScaleControl, SdkConfig, Style, TerrainControl, VectorTileSource, VideoSource, addProtocol, clearPrewarmedResources, clearStorage, config, getRTLTextPluginStatus, maxParallelImageRequests, prewarm, removeProtocol, setRTLTextPlugin, supported, version, workerCount, workerUrl };
1150
1150
  //# sourceMappingURL=maptiler-sdk.mjs.map