@maptiler/sdk 1.0.7 → 1.0.8
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 +3 -0
- package/demos/maptiler-sdk.umd.js +16 -17
- package/dist/maptiler-sdk.d.ts +13 -1
- package/dist/maptiler-sdk.min.mjs +1 -1
- package/dist/maptiler-sdk.mjs +16 -17
- package/dist/maptiler-sdk.mjs.map +1 -1
- package/dist/maptiler-sdk.umd.js +16 -17
- package/dist/maptiler-sdk.umd.js.map +1 -1
- package/dist/maptiler-sdk.umd.min.js +4 -4
- package/package.json +1 -1
- package/readme.md +6 -5
- package/src/Map.ts +28 -33
package/CHANGELOG.md
CHANGED
|
@@ -1,4 +1,7 @@
|
|
|
1
1
|
# Changelog
|
|
2
|
+
## [v1.0.8](https://github.com/maptiler/maptiler-sdk-js/releases/tag/v1.0.8)
|
|
3
|
+
- FIX: Since v1.0.7, the `Map` primary language (when custom) was no longer persistant on style update.
|
|
4
|
+
|
|
2
5
|
## [v1.0.7](https://github.com/maptiler/maptiler-sdk-js/releases/tag/v1.0.7)
|
|
3
6
|
- The `apiKey` can now be specified in the `Map` constructor (will propagate to `config`)
|
|
4
7
|
- The `language` can now be speficifed in the `Map` constructo (will **not** propagete to `config` and will apply only to this specific instance)
|
|
@@ -2643,7 +2643,7 @@
|
|
|
2643
2643
|
};
|
|
2644
2644
|
class Map$1 extends maplibregl.Map {
|
|
2645
2645
|
constructor(options) {
|
|
2646
|
-
var _a;
|
|
2646
|
+
var _a, _b;
|
|
2647
2647
|
if (options.apiKey) {
|
|
2648
2648
|
config.apiKey = options.apiKey;
|
|
2649
2649
|
}
|
|
@@ -2685,6 +2685,10 @@
|
|
|
2685
2685
|
this.isStyleInitialized = false;
|
|
2686
2686
|
this.isTerrainEnabled = false;
|
|
2687
2687
|
this.terrainExaggeration = 1;
|
|
2688
|
+
this.primaryLanguage = null;
|
|
2689
|
+
this.secondaryLanguage = null;
|
|
2690
|
+
this.primaryLanguage = (_a = options.language) != null ? _a : config.primaryLanguage;
|
|
2691
|
+
this.secondaryLanguage = config.secondaryLanguage;
|
|
2688
2692
|
this.once("styledata", () => __async(this, null, function* () {
|
|
2689
2693
|
if (options.geolocate === false) {
|
|
2690
2694
|
return;
|
|
@@ -2734,22 +2738,9 @@
|
|
|
2734
2738
|
);
|
|
2735
2739
|
}
|
|
2736
2740
|
}));
|
|
2737
|
-
this.on("styledataloading", () => {
|
|
2738
|
-
this.languageShouldUpdate = !!config.primaryLanguage || !!config.secondaryLanguage;
|
|
2739
|
-
});
|
|
2740
|
-
let initLanguageFromConstructor = true;
|
|
2741
2741
|
this.on("styledata", () => {
|
|
2742
|
-
|
|
2743
|
-
|
|
2744
|
-
} else if (config.primaryLanguage && (this.languageShouldUpdate || !this.isStyleInitialized)) {
|
|
2745
|
-
this.setPrimaryLanguage(config.primaryLanguage);
|
|
2746
|
-
}
|
|
2747
|
-
if (config.secondaryLanguage && (this.languageShouldUpdate || !this.isStyleInitialized)) {
|
|
2748
|
-
this.setSecondaryLanguage(config.secondaryLanguage);
|
|
2749
|
-
}
|
|
2750
|
-
this.languageShouldUpdate = false;
|
|
2751
|
-
this.isStyleInitialized = true;
|
|
2752
|
-
initLanguageFromConstructor = false;
|
|
2742
|
+
this.setPrimaryLanguage(this.primaryLanguage);
|
|
2743
|
+
this.setSecondaryLanguage(this.secondaryLanguage);
|
|
2753
2744
|
});
|
|
2754
2745
|
this.on("styledata", () => {
|
|
2755
2746
|
if (this.getTerrain() === null && this.isTerrainEnabled) {
|
|
@@ -2829,7 +2820,7 @@
|
|
|
2829
2820
|
}));
|
|
2830
2821
|
if (options.terrain) {
|
|
2831
2822
|
this.enableTerrain(
|
|
2832
|
-
(
|
|
2823
|
+
(_b = options.terrainExaggeration) != null ? _b : this.terrainExaggeration
|
|
2833
2824
|
);
|
|
2834
2825
|
}
|
|
2835
2826
|
}
|
|
@@ -2846,6 +2837,7 @@
|
|
|
2846
2837
|
if (!isLanguageSupported(language)) {
|
|
2847
2838
|
return;
|
|
2848
2839
|
}
|
|
2840
|
+
this.primaryLanguage = language;
|
|
2849
2841
|
this.onStyleReady(() => {
|
|
2850
2842
|
if (language === Language.AUTO) {
|
|
2851
2843
|
return this.setPrimaryLanguage(getBrowserLanguage());
|
|
@@ -2919,6 +2911,7 @@
|
|
|
2919
2911
|
if (!isLanguageSupported(language)) {
|
|
2920
2912
|
return;
|
|
2921
2913
|
}
|
|
2914
|
+
this.secondaryLanguage = language;
|
|
2922
2915
|
this.onStyleReady(() => {
|
|
2923
2916
|
if (language === Language.AUTO) {
|
|
2924
2917
|
return this.setSecondaryLanguage(getBrowserLanguage());
|
|
@@ -2978,6 +2971,12 @@
|
|
|
2978
2971
|
}
|
|
2979
2972
|
});
|
|
2980
2973
|
}
|
|
2974
|
+
getPrimaryLanguage() {
|
|
2975
|
+
return this.primaryLanguage;
|
|
2976
|
+
}
|
|
2977
|
+
getSecondaryLanguage() {
|
|
2978
|
+
return this.secondaryLanguage;
|
|
2979
|
+
}
|
|
2981
2980
|
getTerrainExaggeration() {
|
|
2982
2981
|
return this.terrainExaggeration;
|
|
2983
2982
|
}
|
package/dist/maptiler-sdk.d.ts
CHANGED
|
@@ -258,6 +258,8 @@ declare class Map extends maplibre_gl__default.Map {
|
|
|
258
258
|
private isStyleInitialized;
|
|
259
259
|
private isTerrainEnabled;
|
|
260
260
|
private terrainExaggeration;
|
|
261
|
+
private primaryLanguage;
|
|
262
|
+
private secondaryLanguage;
|
|
261
263
|
constructor(options: MapOptions);
|
|
262
264
|
/**
|
|
263
265
|
* Update the style of the map.
|
|
@@ -282,11 +284,21 @@ declare class Map extends maplibre_gl__default.Map {
|
|
|
282
284
|
*/
|
|
283
285
|
setPrimaryLanguage(language?: LanguageString): void;
|
|
284
286
|
/**
|
|
285
|
-
* Define the secondary language of the map.
|
|
287
|
+
* Define the secondary language of the map. Note that this is not supported by all the map styles
|
|
286
288
|
* Note that most styles do not allow a secondary language and this function only works if the style allows (no force adding)
|
|
287
289
|
* @param language
|
|
288
290
|
*/
|
|
289
291
|
setSecondaryLanguage(language?: LanguageString): void;
|
|
292
|
+
/**
|
|
293
|
+
* Get the primary language
|
|
294
|
+
* @returns
|
|
295
|
+
*/
|
|
296
|
+
getPrimaryLanguage(): LanguageString;
|
|
297
|
+
/**
|
|
298
|
+
* Get the secondary language
|
|
299
|
+
* @returns
|
|
300
|
+
*/
|
|
301
|
+
getSecondaryLanguage(): LanguageString;
|
|
290
302
|
/**
|
|
291
303
|
* Get the exaggeration factor applied to the terrain
|
|
292
304
|
* @returns
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import y from"maplibre-gl";export*from"maplibre-gl";import{Base64 as D}from"js-base64";import{v4 as z}from"uuid";import F from"events";import{config as x,expandMapStyle as V,MapStyleVariant as Z,ReferenceMapStyle as q,MapStyle as J,mapStylePresetList as W,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"},Y=new Set(Object.values(S));function E(r){return Y.has(r)}const X=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=>X.has(t));return r.length?r[0]:S.LATIN}class N extends F{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 p=new N,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 I extends y.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 Q(){y.getRTLTextPluginStatus()==="unavailable"&&y.setRTLTextPlugin(d.rtlPluginURL,null,!0)}function tt(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 et(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 Z?r.getExpandedStyleURL():r instanceof q?r.getDefaultVariant().getExpandedStyleURL():r:J[W[0].referenceStyleID].getDefaultVariant().getExpandedStyleURL()}class R{constructor(){tt(["_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(){et(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 rt extends y.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 it=Object.defineProperty,at=Object.defineProperties,ot=Object.getOwnPropertyDescriptors,P=Object.getOwnPropertySymbols,nt=Object.prototype.hasOwnProperty,st=Object.prototype.propertyIsEnumerable,O=(r,t,e)=>t in r?it(r,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):r[t]=e,lt=(r,t)=>{for(var e in t||(t={}))nt.call(t,e)&&O(r,e,t[e]);if(P)for(var e of P(t))st.call(t,e)&&O(r,e,t[e]);return r},ct=(r,t)=>at(r,ot(t));const ht=y.GeolocateControl,U=y.Marker,M=y.LngLat;class k extends ht{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,c=this._map.getBearing(),u=ct(lt({bearing:c},this.options.fitBoundsOptions),{linear:!0}),s=this._map.getZoom();s>this.options.fitBoundsOptions.maxZoom&&(u.zoom=s),this._map.fitBounds(e.toBounds(o),u,{geolocateSource:!0});let i=!1;const a=()=>{i=!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),!i&&(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",c=this.lastUpdatedCenter.distanceTo(this._map.getCenter());!e.geolocateSource&&this._watchState==="ACTIVE_LOCK"&&!o&&c>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]),c=this._map.unproject([e.x+20,e.y]),u=o.distanceTo(c)/20,s=Math.ceil(2*this._accuracy/u);this._circleElement.style.width=`${s}px`,this._circleElement.style.height=`${s}px`}_onZoom(){this.options.showUserLocation&&this.options.showAccuracyCircle&&this._updateCircleRadius()}}var ut=Object.defineProperty,gt=Object.defineProperties,pt=Object.getOwnPropertyDescriptors,B=Object.getOwnPropertySymbols,dt=Object.prototype.hasOwnProperty,mt=Object.prototype.propertyIsEnumerable,$=(r,t,e)=>t in r?ut(r,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):r[t]=e,H=(r,t)=>{for(var e in t||(t={}))dt.call(t,e)&&$(r,e,t[e]);if(B)for(var e of B(t))mt.call(t,e)&&$(r,e,t[e]);return r},j=(r,t)=>gt(r,pt(t)),C=(r,t,e)=>new Promise((o,c)=>{var u=a=>{try{i(e.next(a))}catch(g){c(g)}},s=a=>{try{i(e.throw(a))}catch(g){c(g)}},i=a=>a.done?o(a.value):Promise.resolve(a.value).then(u,s);i((e=e.apply(r,t)).next())});const K=z(),G={POINT:"POINT",COUNTRY:"COUNTRY"};class yt extends y.Map{constructor(t){var e;t.apiKey&&(p.apiKey=t.apiKey);const o=w(t.style),c=location.hash;p.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===d.maptilerApiHost&&(i.searchParams.has("key")||i.searchParams.append("key",p.apiKey),p.session&&i.searchParams.append("mtsid",K)),{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&&!!c)return;try{if(t.geolocate===G.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=!!p.primaryLanguage||!!p.secondaryLanguage});let u=!0;this.on("styledata",()=>{t.language&&u?this.setPrimaryLanguage(t.language):p.primaryLanguage&&(this.languageShouldUpdate||!this.isStyleInitialized)&&this.setPrimaryLanguage(p.primaryLanguage),p.secondaryLanguage&&(this.languageShouldUpdate||!this.isStyleInitialized)&&this.setSecondaryLanguage(p.secondaryLanguage),this.languageShouldUpdate=!1,this.isStyleInitialized=!0,u=!1}),this.on("styledata",()=>{this.getTerrain()===null&&this.isTerrainEnabled&&this.enableTerrain(this.terrainExaggeration)}),this.once("load",()=>C(this,null,function*(){Q()})),this.once("load",()=>C(this,null,function*(){let s={logo:null};try{const i=Object.keys(this.style.sourceCaches).map(g=>this.getSource(g)).filter(g=>typeof g.url=="string"&&g.url.includes("tiles.json")),a=new URL(i[0].url);a.searchParams.has("key")||a.searchParams.append("key",p.apiKey),s=yield(yield fetch(a.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 y.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,a=new y.ScaleControl({unit:p.unit});this.addControl(a,i),p.on("unit",g=>{a.setUnit(g)})}if(t.navigationControl!==!1){const i=t.navigationControl===!0||t.navigationControl===void 0?"top-right":t.navigationControl;this.addControl(new rt,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 y.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){!E(t)||this.onStyleReady(()=>{if(t===S.AUTO)return this.setPrimaryLanguage(T());const e=this.getStyle().layers,o=/^\s*{\s*name\s*(:\s*(\S*))?\s*}$/,c=/^\s*name\s*(:\s*(\S*))?\s*$/,u=/^\s*{\s*name\s*(:\s*(\S*))?\s*}(\s*){\s*name\s*(:\s*(\S*))?\s*}$/,s=/^(.*)({\s*name\s*(:\s*(\S*))?\s*})(.*)$/,i=t?`name:${t}`:"name",a=["case",["has",i],["get",i],["get","name:latin"]];for(let g=0;g<e.length;g+=1){const h=e[g],f=h.layout;if(!f||!f["text-field"])continue;const n=this.getLayoutProperty(h.id,"text-field");let m;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"&&c.exec(_[1].toString())){l[L]=a;break}else if(Array.isArray(_)&&_.length===4&&_[0].trim().toLowerCase()==="case"){l[L]=a;break}}this.setLayoutProperty(h.id,"text-field",l)}else if(Array.isArray(n)&&n.length>=2&&n[0].trim().toLowerCase()==="get"&&c.exec(n[1].toString())){const l=a;this.setLayoutProperty(h.id,"text-field",l)}else if((typeof n=="string"||n instanceof String)&&o.exec(n.toString())){const l=a;this.setLayoutProperty(h.id,"text-field",l)}else if(Array.isArray(n)&&n.length===4&&n[0].trim().toLowerCase()==="case"){const l=a;this.setLayoutProperty(h.id,"text-field",l)}else if((typeof n=="string"||n instanceof String)&&(m=u.exec(n.toString()))!==null){const l=`{${i}}${m[3]}{name${m[4]||""}}`;this.setLayoutProperty(h.id,"text-field",l)}else if((typeof n=="string"||n instanceof String)&&(m=s.exec(n.toString()))!==null){const l=`${m[1]}{${i}}${m[5]}`;this.setLayoutProperty(h.id,"text-field",l)}}})}setSecondaryLanguage(t=d.secondaryLanguage){!E(t)||this.onStyleReady(()=>{if(t===S.AUTO)return this.setSecondaryLanguage(T());const e=this.getStyle().layers,o=/^\s*{\s*name\s*(:\s*(\S*))?\s*}$/,c=/^\s*name\s*(:\s*(\S*))?\s*$/,u=/^\s*{\s*name\s*(:\s*(\S*))?\s*}(\s*){\s*name\s*(:\s*(\S*))?\s*}$/;let s;for(let i=0;i<e.length;i+=1){const a=e[i],g=a.layout;if(!g||!g["text-field"])continue;const h=this.getLayoutProperty(a.id,"text-field");let f;if(Array.isArray(h)&&h.length>=2&&h[0].trim().toLowerCase()==="concat"){f=h.slice();let n=0;for(let m=0;m<h.length;m+=1){const l=h[m];if((typeof l=="string"||l instanceof String)&&o.exec(l.toString())){if(n===1){f[m]=`{name:${t}}`;break}n+=1}else if(Array.isArray(l)&&l.length>=2&&l[0].trim().toLowerCase()==="get"&&c.exec(l[1].toString())){if(n===1){f[m][1]=`name:${t}`;break}n+=1}else if(Array.isArray(l)&&l.length===4&&l[0].trim().toLowerCase()==="case"){if(n===1){f[m]=["get",`name:${t}`];break}n+=1}}this.setLayoutProperty(a.id,"text-field",f)}else if((typeof h=="string"||h instanceof String)&&(s=u.exec(h.toString()))!==null){const n=t?`name:${t}`:"name";f=`{name${s[1]||""}}${s[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(j(H({},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 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(),D.fromUint8Array(new Uint8Array(t.buffer))}getSdkConfig(){return p}getMaptilerSessionId(){return K}}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),c=e*this.x-o*this.y,u=o*this.x+e*this.y;return this.x=c,this.y=u,this}_rotateAround(t,e){const o=Math.cos(t),c=Math.sin(t),u=e.x+o*(this.x-e.x)-c*(this.y-e.y),s=e.y+c*(this.x-e.x)+o*(this.y-e.y);return this.x=u,this.y=s,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:Ft,maxParallelImageRequests:Vt,clearStorage:Zt,workerUrl:qt,addProtocol:Jt,removeProtocol:Wt}=y;export{Ut as AJAXError,Ct as AttributionControl,Mt as CanvasSource,Ot as Evented,Tt as FullscreenControl,kt as GeoJSONSource,Lt as GeolocateControl,G 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,p as config,he as coordinates,ue as data,ge as geocoding,pe as geolocation,St as getRTLTextPluginStatus,Vt as maxParallelImageRequests,Gt as prewarm,Wt as removeProtocol,_t as setRTLTextPlugin,de as staticMaps,ft as supported,zt as version,Ft as workerCount,qt as workerUrl};
|
|
1
|
+
import m from"maplibre-gl";export*from"maplibre-gl";import{Base64 as D}from"js-base64";import{v4 as z}from"uuid";import F from"events";import{config as x,expandMapStyle as V,MapStyleVariant as Z,ReferenceMapStyle as q,MapStyle as J,mapStylePresetList as W,geolocation as v}from"@maptiler/client";import{LanguageGeocoding as ne,MapStyle as oe,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 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"},Y=new Set(Object.values(L));function E(r){return Y.has(r)}const X=new Set(Object.values(L));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=>X.has(t));return r.length?r[0]:L.LATIN}class N extends F{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,x.apiKey=t,this.emit("apiKey",t)}get apiKey(){return this._apiKey}set fetch(t){x.fetch=t}get fetch(){return x.fetch}}const y=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:L.AUTO,secondaryLanguage:L.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,n;super(t),this.logoURL="",this.linkURL="",this.logoURL=(e=t.logoURL)!=null?e:p.maptilerLogoURL,this.linkURL=(n=t.linkURL)!=null?n: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 Q(){m.getRTLTextPluginStatus()==="unavailable"&&m.setRTLTextPlugin(p.rtlPluginURL,null,!0)}function tt(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 et(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 Z?r.getExpandedStyleURL():r instanceof q?r.getDefaultVariant().getExpandedStyleURL():r:J[W[0].referenceStyleID].getDefaultVariant().getExpandedStyleURL()}class R{constructor(){tt(["_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(){et(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 rt 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 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}}var it=Object.defineProperty,at=Object.defineProperties,nt=Object.getOwnPropertyDescriptors,P=Object.getOwnPropertySymbols,ot=Object.prototype.hasOwnProperty,st=Object.prototype.propertyIsEnumerable,O=(r,t,e)=>t in r?it(r,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):r[t]=e,lt=(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))st.call(t,e)&&O(r,e,t[e]);return r},ct=(r,t)=>at(r,nt(t));const ht=m.GeolocateControl,U=m.Marker,M=m.LngLat;class k extends ht{constructor(){super(...arguments),this.lastUpdatedCenter=new M(0,0)}_updateCamera(t){const e=new M(t.coords.longitude,t.coords.latitude),n=t.coords.accuracy,c=this._map.getBearing(),g=ct(lt({bearing:c},this.options.fitBoundsOptions),{linear:!0}),s=this._map.getZoom();s>this.options.fitBoundsOptions.maxZoom&&(g.zoom=s),this._map.fitBounds(e.toBounds(n),g,{geolocateSource:!0});let i=!1;const a=()=>{i=!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),!i&&(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 U(this._dotElement),this._circleElement=S("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 n=e.originalEvent&&e.originalEvent.type==="resize",c=this.lastUpdatedCenter.distanceTo(this._map.getCenter());!e.geolocateSource&&this._watchState==="ACTIVE_LOCK"&&!n&&c>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]),c=this._map.unproject([e.x+20,e.y]),g=n.distanceTo(c)/20,s=Math.ceil(2*this._accuracy/g);this._circleElement.style.width=`${s}px`,this._circleElement.style.height=`${s}px`}_onZoom(){this.options.showUserLocation&&this.options.showAccuracyCircle&&this._updateCircleRadius()}}var ut=Object.defineProperty,gt=Object.defineProperties,pt=Object.getOwnPropertyDescriptors,B=Object.getOwnPropertySymbols,dt=Object.prototype.hasOwnProperty,mt=Object.prototype.propertyIsEnumerable,$=(r,t,e)=>t in r?ut(r,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):r[t]=e,H=(r,t)=>{for(var e in t||(t={}))dt.call(t,e)&&$(r,e,t[e]);if(B)for(var e of B(t))mt.call(t,e)&&$(r,e,t[e]);return r},j=(r,t)=>gt(r,pt(t)),C=(r,t,e)=>new Promise((n,c)=>{var g=a=>{try{i(e.next(a))}catch(u){c(u)}},s=a=>{try{i(e.throw(a))}catch(u){c(u)}},i=a=>a.done?n(a.value):Promise.resolve(a.value).then(g,s);i((e=e.apply(r,t)).next())});const K=z(),G={POINT:"POINT",COUNTRY:"COUNTRY"};class yt extends m.Map{constructor(t){var e,n;t.apiKey&&(y.apiKey=t.apiKey);const c=w(t.style),g=location.hash;y.apiKey||console.warn("MapTiler Cloud API key is not set. Visit https://maptiler.com and try Cloud for free!"),super(j(H({},t),{style:c,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",y.apiKey),y.session&&i.searchParams.append("mtsid",K)),{url:i.href,headers:{}}}})),this.languageShouldUpdate=!1,this.isStyleInitialized=!1,this.isTerrainEnabled=!1,this.terrainExaggeration=1,this.primaryLanguage=null,this.secondaryLanguage=null,this.primaryLanguage=(e=t.language)!=null?e:y.primaryLanguage,this.secondaryLanguage=y.secondaryLanguage,this.once("styledata",()=>C(this,null,function*(){if(t.geolocate===!1||t.center||t.hash&&!!g)return;try{if(t.geolocate===G.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("styledata",()=>{this.setPrimaryLanguage(this.primaryLanguage),this.setSecondaryLanguage(this.secondaryLanguage)}),this.on("styledata",()=>{this.getTerrain()===null&&this.isTerrainEnabled&&this.enableTerrain(this.terrainExaggeration)}),this.once("load",()=>C(this,null,function*(){Q()})),this.once("load",()=>C(this,null,function*(){let s={logo:null};try{const i=Object.keys(this.style.sourceCaches).map(u=>this.getSource(u)).filter(u=>typeof u.url=="string"&&u.url.includes("tiles.json")),a=new URL(i[0].url);a.searchParams.has("key")||a.searchParams.append("key",y.apiKey),s=yield(yield fetch(a.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,a=new m.ScaleControl({unit:y.unit});this.addControl(a,i),y.on("unit",u=>{a.setUnit(u)})}if(t.navigationControl!==!1){const i=t.navigationControl===!0||t.navigationControl===void 0?"top-right":t.navigationControl;this.addControl(new rt,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((n=t.terrainExaggeration)!=null?n:this.terrainExaggeration)}setStyle(t,e){return super.setStyle(w(t),e)}setLanguage(t=p.primaryLanguage){if(t===L.AUTO)return this.setLanguage(T());this.setPrimaryLanguage(t)}setPrimaryLanguage(t=p.primaryLanguage){!E(t)||(this.primaryLanguage=t,this.onStyleReady(()=>{if(t===L.AUTO)return this.setPrimaryLanguage(T());const e=this.getStyle().layers,n=/^\s*{\s*name\s*(:\s*(\S*))?\s*}$/,c=/^\s*name\s*(:\s*(\S*))?\s*$/,g=/^\s*{\s*name\s*(:\s*(\S*))?\s*}(\s*){\s*name\s*(:\s*(\S*))?\s*}$/,s=/^(.*)({\s*name\s*(:\s*(\S*))?\s*})(.*)$/,i=t?`name:${t}`:"name",a=["case",["has",i],["get",i],["get","name:latin"]];for(let u=0;u<e.length;u+=1){const h=e[u],f=h.layout;if(!f||!f["text-field"])continue;const o=this.getLayoutProperty(h.id,"text-field");let d;if(Array.isArray(o)&&o.length>=2&&o[0].trim().toLowerCase()==="concat"){const l=o.slice();for(let A=0;A<o.length;A+=1){const _=o[A];if((typeof _=="string"||_ instanceof String)&&n.exec(_.toString())){l[A]=a;break}else if(Array.isArray(_)&&_.length>=2&&_[0].trim().toLowerCase()==="get"&&c.exec(_[1].toString())){l[A]=a;break}else if(Array.isArray(_)&&_.length===4&&_[0].trim().toLowerCase()==="case"){l[A]=a;break}}this.setLayoutProperty(h.id,"text-field",l)}else if(Array.isArray(o)&&o.length>=2&&o[0].trim().toLowerCase()==="get"&&c.exec(o[1].toString())){const l=a;this.setLayoutProperty(h.id,"text-field",l)}else if((typeof o=="string"||o instanceof String)&&n.exec(o.toString())){const l=a;this.setLayoutProperty(h.id,"text-field",l)}else if(Array.isArray(o)&&o.length===4&&o[0].trim().toLowerCase()==="case"){const l=a;this.setLayoutProperty(h.id,"text-field",l)}else if((typeof o=="string"||o instanceof String)&&(d=g.exec(o.toString()))!==null){const l=`{${i}}${d[3]}{name${d[4]||""}}`;this.setLayoutProperty(h.id,"text-field",l)}else if((typeof o=="string"||o instanceof String)&&(d=s.exec(o.toString()))!==null){const l=`${d[1]}{${i}}${d[5]}`;this.setLayoutProperty(h.id,"text-field",l)}}}))}setSecondaryLanguage(t=p.secondaryLanguage){!E(t)||(this.secondaryLanguage=t,this.onStyleReady(()=>{if(t===L.AUTO)return this.setSecondaryLanguage(T());const e=this.getStyle().layers,n=/^\s*{\s*name\s*(:\s*(\S*))?\s*}$/,c=/^\s*name\s*(:\s*(\S*))?\s*$/,g=/^\s*{\s*name\s*(:\s*(\S*))?\s*}(\s*){\s*name\s*(:\s*(\S*))?\s*}$/;let s;for(let i=0;i<e.length;i+=1){const a=e[i],u=a.layout;if(!u||!u["text-field"])continue;const h=this.getLayoutProperty(a.id,"text-field");let f;if(Array.isArray(h)&&h.length>=2&&h[0].trim().toLowerCase()==="concat"){f=h.slice();let o=0;for(let d=0;d<h.length;d+=1){const l=h[d];if((typeof l=="string"||l instanceof String)&&n.exec(l.toString())){if(o===1){f[d]=`{name:${t}}`;break}o+=1}else if(Array.isArray(l)&&l.length>=2&&l[0].trim().toLowerCase()==="get"&&c.exec(l[1].toString())){if(o===1){f[d][1]=`name:${t}`;break}o+=1}else if(Array.isArray(l)&&l.length===4&&l[0].trim().toLowerCase()==="case"){if(o===1){f[d]=["get",`name:${t}`];break}o+=1}}this.setLayoutProperty(a.id,"text-field",f)}else if((typeof h=="string"||h instanceof String)&&(s=g.exec(h.toString()))!==null){const o=t?`name:${t}`:"name";f=`{name${s[1]||""}}${s[3]}{${o}}`,this.setLayoutProperty(a.id,"text-field",f)}}}))}getPrimaryLanguage(){return this.primaryLanguage}getSecondaryLanguage(){return this.secondaryLanguage}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(),n=()=>{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?n():this.once("load",()=>{this.getTerrain()&&this.getSource(p.terrainSourceId)||n()})}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(),D.fromUint8Array(new Uint8Array(t.buffer))}getSdkConfig(){return y}getMaptilerSessionId(){return K}}class b{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),c=e*this.x-n*this.y,g=n*this.x+e*this.y;return this.x=c,this.y=g,this}_rotateAround(t,e){const n=Math.cos(t),c=Math.sin(t),g=e.x+n*(this.x-e.x)-c*(this.y-e.y),s=e.y+c*(this.x-e.x)+n*(this.y-e.y);return this.x=g,this.y=s,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,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 b?t:Array.isArray(t)?new b(t[0],t[1]):t}}const{supported:ft,setRTLTextPlugin:_t,getRTLTextPluginStatus:Lt,NavigationControl:St,GeolocateControl:At,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:Ft,maxParallelImageRequests:Vt,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,At as GeolocateControl,G as GeolocationType,Bt as ImageSource,L as Language,ne as LanguageGeocoding,wt as LngLat,Rt as LngLatBounds,bt as LogoControl,yt as Map,oe as MapStyle,se as MapStyleVariant,k as MaptilerGeolocateControl,I as MaptilerLogoControl,R as MaptilerTerrainControl,Et as Marker,Pt as MercatorCoordinate,St 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,y as config,he as coordinates,ue as data,ge as geocoding,pe as geolocation,Lt as getRTLTextPluginStatus,Vt as maxParallelImageRequests,Gt as prewarm,Wt as removeProtocol,_t as setRTLTextPlugin,de as staticMaps,ft as supported,zt as version,Ft as workerCount,qt as workerUrl};
|
package/dist/maptiler-sdk.mjs
CHANGED
|
@@ -537,7 +537,7 @@ const GeolocationType = {
|
|
|
537
537
|
};
|
|
538
538
|
class Map extends maplibregl__default.Map {
|
|
539
539
|
constructor(options) {
|
|
540
|
-
var _a;
|
|
540
|
+
var _a, _b;
|
|
541
541
|
if (options.apiKey) {
|
|
542
542
|
config.apiKey = options.apiKey;
|
|
543
543
|
}
|
|
@@ -579,6 +579,10 @@ class Map extends maplibregl__default.Map {
|
|
|
579
579
|
this.isStyleInitialized = false;
|
|
580
580
|
this.isTerrainEnabled = false;
|
|
581
581
|
this.terrainExaggeration = 1;
|
|
582
|
+
this.primaryLanguage = null;
|
|
583
|
+
this.secondaryLanguage = null;
|
|
584
|
+
this.primaryLanguage = (_a = options.language) != null ? _a : config.primaryLanguage;
|
|
585
|
+
this.secondaryLanguage = config.secondaryLanguage;
|
|
582
586
|
this.once("styledata", () => __async(this, null, function* () {
|
|
583
587
|
if (options.geolocate === false) {
|
|
584
588
|
return;
|
|
@@ -628,22 +632,9 @@ class Map extends maplibregl__default.Map {
|
|
|
628
632
|
);
|
|
629
633
|
}
|
|
630
634
|
}));
|
|
631
|
-
this.on("styledataloading", () => {
|
|
632
|
-
this.languageShouldUpdate = !!config.primaryLanguage || !!config.secondaryLanguage;
|
|
633
|
-
});
|
|
634
|
-
let initLanguageFromConstructor = true;
|
|
635
635
|
this.on("styledata", () => {
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
} else if (config.primaryLanguage && (this.languageShouldUpdate || !this.isStyleInitialized)) {
|
|
639
|
-
this.setPrimaryLanguage(config.primaryLanguage);
|
|
640
|
-
}
|
|
641
|
-
if (config.secondaryLanguage && (this.languageShouldUpdate || !this.isStyleInitialized)) {
|
|
642
|
-
this.setSecondaryLanguage(config.secondaryLanguage);
|
|
643
|
-
}
|
|
644
|
-
this.languageShouldUpdate = false;
|
|
645
|
-
this.isStyleInitialized = true;
|
|
646
|
-
initLanguageFromConstructor = false;
|
|
636
|
+
this.setPrimaryLanguage(this.primaryLanguage);
|
|
637
|
+
this.setSecondaryLanguage(this.secondaryLanguage);
|
|
647
638
|
});
|
|
648
639
|
this.on("styledata", () => {
|
|
649
640
|
if (this.getTerrain() === null && this.isTerrainEnabled) {
|
|
@@ -723,7 +714,7 @@ class Map extends maplibregl__default.Map {
|
|
|
723
714
|
}));
|
|
724
715
|
if (options.terrain) {
|
|
725
716
|
this.enableTerrain(
|
|
726
|
-
(
|
|
717
|
+
(_b = options.terrainExaggeration) != null ? _b : this.terrainExaggeration
|
|
727
718
|
);
|
|
728
719
|
}
|
|
729
720
|
}
|
|
@@ -740,6 +731,7 @@ class Map extends maplibregl__default.Map {
|
|
|
740
731
|
if (!isLanguageSupported(language)) {
|
|
741
732
|
return;
|
|
742
733
|
}
|
|
734
|
+
this.primaryLanguage = language;
|
|
743
735
|
this.onStyleReady(() => {
|
|
744
736
|
if (language === Language.AUTO) {
|
|
745
737
|
return this.setPrimaryLanguage(getBrowserLanguage());
|
|
@@ -813,6 +805,7 @@ class Map extends maplibregl__default.Map {
|
|
|
813
805
|
if (!isLanguageSupported(language)) {
|
|
814
806
|
return;
|
|
815
807
|
}
|
|
808
|
+
this.secondaryLanguage = language;
|
|
816
809
|
this.onStyleReady(() => {
|
|
817
810
|
if (language === Language.AUTO) {
|
|
818
811
|
return this.setSecondaryLanguage(getBrowserLanguage());
|
|
@@ -872,6 +865,12 @@ class Map extends maplibregl__default.Map {
|
|
|
872
865
|
}
|
|
873
866
|
});
|
|
874
867
|
}
|
|
868
|
+
getPrimaryLanguage() {
|
|
869
|
+
return this.primaryLanguage;
|
|
870
|
+
}
|
|
871
|
+
getSecondaryLanguage() {
|
|
872
|
+
return this.secondaryLanguage;
|
|
873
|
+
}
|
|
875
874
|
getTerrainExaggeration() {
|
|
876
875
|
return this.terrainExaggeration;
|
|
877
876
|
}
|