@maptiler/sdk 1.0.1 → 1.0.3
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/demos/maptiler-sdk.umd.js +25 -12
- package/dist/maptiler-sdk.min.mjs +1 -1
- package/dist/maptiler-sdk.mjs +22 -9
- package/dist/maptiler-sdk.mjs.map +1 -1
- package/dist/maptiler-sdk.umd.js +25 -12
- package/dist/maptiler-sdk.umd.js.map +1 -1
- package/dist/maptiler-sdk.umd.min.js +34 -34
- package/package.json +1 -1
- package/readme.md +1 -1
- package/src/CustomGeolocateControl.ts +7 -10
- package/src/Map.ts +13 -3
- package/src/mapstyle.ts +7 -1
|
@@ -2326,7 +2326,11 @@
|
|
|
2326
2326
|
return MapStyle[mapStylePresetList[0].referenceStyleID].getDefaultVariant().getExpandedStyleURL();
|
|
2327
2327
|
}
|
|
2328
2328
|
if (typeof style === "string" || style instanceof String) {
|
|
2329
|
-
|
|
2329
|
+
if (!style.startsWith("http") && style.toLowerCase().includes(".json")) {
|
|
2330
|
+
return style;
|
|
2331
|
+
} else {
|
|
2332
|
+
return expandMapStyle(style);
|
|
2333
|
+
}
|
|
2330
2334
|
}
|
|
2331
2335
|
if (style instanceof MapStyleVariant) {
|
|
2332
2336
|
return style.getExpandedStyleURL();
|
|
@@ -2445,9 +2449,16 @@
|
|
|
2445
2449
|
}
|
|
2446
2450
|
return a;
|
|
2447
2451
|
};
|
|
2448
|
-
|
|
2452
|
+
const GeolocateControl$1 = maplibregl.GeolocateControl;
|
|
2453
|
+
const Marker$1 = maplibregl.Marker;
|
|
2454
|
+
const LngLat$1 = maplibregl.LngLat;
|
|
2455
|
+
class CustomGeolocateControl extends GeolocateControl$1 {
|
|
2456
|
+
constructor() {
|
|
2457
|
+
super(...arguments);
|
|
2458
|
+
this.lastUpdatedCenter = new LngLat$1(0, 0);
|
|
2459
|
+
}
|
|
2449
2460
|
_updateCamera(position) {
|
|
2450
|
-
const center = new
|
|
2461
|
+
const center = new LngLat$1(
|
|
2451
2462
|
position.coords.longitude,
|
|
2452
2463
|
position.coords.latitude
|
|
2453
2464
|
);
|
|
@@ -2456,13 +2467,11 @@
|
|
|
2456
2467
|
const options = __spreadValues$1({
|
|
2457
2468
|
bearing
|
|
2458
2469
|
}, this.options.fitBoundsOptions);
|
|
2459
|
-
console.log("moving camera");
|
|
2460
2470
|
this._map.fitBounds(center.toBounds(radius), options, {
|
|
2461
2471
|
geolocateSource: true
|
|
2462
2472
|
});
|
|
2463
2473
|
let hasFittingBeenDisrupted = false;
|
|
2464
2474
|
const flagFittingDisruption = () => {
|
|
2465
|
-
console.log("DISRUPTED FITTING!");
|
|
2466
2475
|
hasFittingBeenDisrupted = true;
|
|
2467
2476
|
};
|
|
2468
2477
|
this._map.once("click", flagFittingDisruption);
|
|
@@ -2472,7 +2481,6 @@
|
|
|
2472
2481
|
this._map.once("touchstart", flagFittingDisruption);
|
|
2473
2482
|
this._map.once("wheel", flagFittingDisruption);
|
|
2474
2483
|
this._map.once("moveend", () => {
|
|
2475
|
-
console.log("done moving, with disruption:", hasFittingBeenDisrupted);
|
|
2476
2484
|
this._map.off("click", flagFittingDisruption);
|
|
2477
2485
|
this._map.off("dblclick", flagFittingDisruption);
|
|
2478
2486
|
this._map.off("dragstart", flagFittingDisruption);
|
|
@@ -2483,12 +2491,10 @@
|
|
|
2483
2491
|
return;
|
|
2484
2492
|
}
|
|
2485
2493
|
this.lastUpdatedCenter = this._map.getCenter();
|
|
2486
|
-
this.lastUpdatedZoom = this._map.getZoom();
|
|
2487
2494
|
});
|
|
2488
2495
|
}
|
|
2489
2496
|
_setupUI(supported) {
|
|
2490
2497
|
this.lastUpdatedCenter = this._map.getCenter();
|
|
2491
|
-
this.lastUpdatedZoom = this._map.getZoom();
|
|
2492
2498
|
this._container.addEventListener(
|
|
2493
2499
|
"contextmenu",
|
|
2494
2500
|
(e) => e.preventDefault()
|
|
@@ -2522,12 +2528,12 @@
|
|
|
2522
2528
|
}
|
|
2523
2529
|
if (this.options.showUserLocation) {
|
|
2524
2530
|
this._dotElement = DOMcreate("div", "maplibregl-user-location-dot");
|
|
2525
|
-
this._userLocationDotMarker = new
|
|
2531
|
+
this._userLocationDotMarker = new Marker$1(this._dotElement);
|
|
2526
2532
|
this._circleElement = DOMcreate(
|
|
2527
2533
|
"div",
|
|
2528
2534
|
"maplibregl-user-location-accuracy-circle"
|
|
2529
2535
|
);
|
|
2530
|
-
this._accuracyCircleMarker = new
|
|
2536
|
+
this._accuracyCircleMarker = new Marker$1({
|
|
2531
2537
|
element: this._circleElement,
|
|
2532
2538
|
pitchAlignment: "map"
|
|
2533
2539
|
});
|
|
@@ -2630,7 +2636,6 @@
|
|
|
2630
2636
|
constructor(options) {
|
|
2631
2637
|
var _a;
|
|
2632
2638
|
const style = styleToStyle(options.style);
|
|
2633
|
-
console.log(style);
|
|
2634
2639
|
const hashPreConstructor = location.hash;
|
|
2635
2640
|
if (!config.apiKey) {
|
|
2636
2641
|
console.warn(
|
|
@@ -2641,7 +2646,15 @@
|
|
|
2641
2646
|
style,
|
|
2642
2647
|
maplibreLogo: false,
|
|
2643
2648
|
transformRequest: (url) => {
|
|
2644
|
-
|
|
2649
|
+
let reqUrl = null;
|
|
2650
|
+
try {
|
|
2651
|
+
reqUrl = new URL(url);
|
|
2652
|
+
} catch (e) {
|
|
2653
|
+
return {
|
|
2654
|
+
url,
|
|
2655
|
+
headers: {}
|
|
2656
|
+
};
|
|
2657
|
+
}
|
|
2645
2658
|
if (reqUrl.host === defaults.maptilerApiHost) {
|
|
2646
2659
|
if (!reqUrl.searchParams.has("key")) {
|
|
2647
2660
|
reqUrl.searchParams.append("key", config.apiKey);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import S,{GeolocateControl as H,LngLat as j,Marker as I}from"maplibre-gl";export*from"maplibre-gl";import{Base64 as G}from"js-base64";import{v4 as K}from"uuid";import D from"events";import{config as b,expandMapStyle as z,MapStyleVariant as F,ReferenceMapStyle as V,MapStyle as Z,mapStylePresetList as q,geolocation as v}from"@maptiler/client";import{LanguageGeocoding as re,MapStyle as ie,MapStyleVariant as ae,ReferenceMapStyle as oe,ServiceError as ne,coordinates as se,data as le,geocoding as ce,geolocation as he,staticMaps as ue}from"@maptiler/client";const f={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"},J=new Set(Object.values(f));function E(r){return J.has(r)}const W=new Set(Object.values(f));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=>W.has(t));return r.length?r[0]:f.LATIN}class N extends D{constructor(){super(),this.primaryLanguage=f.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,b.apiKey=t,this.emit("apiKey",t)}get apiKey(){return this._apiKey}set fetch(t){b.fetch=t}get fetch(){return b.fetch}}const g=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:f.AUTO,secondaryLanguage:f.LOCAL,terrainSourceURL:"https://api.maptiler.com/tiles/terrain-rgb/tiles.json",terrainSourceId:"maptiler-terrain"};Object.freeze(d);class w extends S.LogoControl{constructor(t={}){var e,a;super(t),this.logoURL="",this.linkURL="",this.logoURL=(e=t.logoURL)!=null?e:d.maptilerLogoURL,this.linkURL=(a=t.linkURL)!=null?a: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 Y(){S.getRTLTextPluginStatus()==="unavailable"&&S.setRTLTextPlugin(d.rtlPluginURL,null,!0)}function X(r,t){r.forEach(e=>{!t[e]||(t[e]=t[e].bind(t))})}function A(r,t,e){const a=window.document.createElement(r);return t!==void 0&&(a.className=t),e&&e.appendChild(a),a}function Q(r){r.parentNode&&r.parentNode.removeChild(r)}function R(r){return r?typeof r=="string"||r instanceof String?z(r):r instanceof F?r.getExpandedStyleURL():r instanceof V?r.getDefaultVariant().getExpandedStyleURL():r:Z[q[0].referenceStyleID].getDefaultVariant().getExpandedStyleURL()}class tt{constructor(){X(["_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(){Q(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 S.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 a=super._createButton(t,e);return a.clickFunction=e,a}_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,P=Object.getOwnPropertySymbols,it=Object.prototype.hasOwnProperty,at=Object.prototype.propertyIsEnumerable,U=(r,t,e)=>t in r?rt(r,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):r[t]=e,ot=(r,t)=>{for(var e in t||(t={}))it.call(t,e)&&U(r,e,t[e]);if(P)for(var e of P(t))at.call(t,e)&&U(r,e,t[e]);return r};class nt extends H{_updateCamera(t){const e=new j(t.coords.longitude,t.coords.latitude),a=t.coords.accuracy,h=this._map.getBearing(),c=ot({bearing:h},this.options.fitBoundsOptions);console.log("moving camera"),this._map.fitBounds(e.toBounds(a),c,{geolocateSource:!0});let i=!1;const o=()=>{console.log("DISRUPTED FITTING!"),i=!0};this._map.once("click",o),this._map.once("dblclick",o),this._map.once("dragstart",o),this._map.once("mousedown",o),this._map.once("touchstart",o),this._map.once("wheel",o),this._map.once("moveend",()=>{console.log("done moving, with disruption:",i),this._map.off("click",o),this._map.off("dblclick",o),this._map.off("dragstart",o),this._map.off("mousedown",o),this._map.off("touchstart",o),this._map.off("wheel",o),!i&&(this.lastUpdatedCenter=this._map.getCenter(),this.lastUpdatedZoom=this._map.getZoom())})}_setupUI(t){if(this.lastUpdatedCenter=this._map.getCenter(),this.lastUpdatedZoom=this._map.getZoom(),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 I(this._dotElement),this._circleElement=A("div","maplibregl-user-location-accuracy-circle"),this._accuracyCircleMarker=new I({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 a=e.originalEvent&&e.originalEvent.type==="resize",h=this.lastUpdatedCenter.distanceTo(this._map.getCenter());!e.geolocateSource&&this._watchState==="ACTIVE_LOCK"&&!a&&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),a=this._map.unproject([e.x,e.y]),h=this._map.unproject([e.x+20,e.y]),c=a.distanceTo(h)/20,i=Math.ceil(2*this._accuracy/c);this._circleElement.style.width=`${i}px`,this._circleElement.style.height=`${i}px`}_onZoom(){this.options.showUserLocation&&this.options.showAccuracyCircle&&this._updateCircleRadius()}}var st=Object.defineProperty,lt=Object.defineProperties,ct=Object.getOwnPropertyDescriptors,O=Object.getOwnPropertySymbols,ht=Object.prototype.hasOwnProperty,ut=Object.prototype.propertyIsEnumerable,k=(r,t,e)=>t in r?st(r,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):r[t]=e,M=(r,t)=>{for(var e in t||(t={}))ht.call(t,e)&&k(r,e,t[e]);if(O)for(var e of O(t))ut.call(t,e)&&k(r,e,t[e]);return r},B=(r,t)=>lt(r,ct(t)),C=(r,t,e)=>new Promise((a,h)=>{var c=s=>{try{o(e.next(s))}catch(m){h(m)}},i=s=>{try{o(e.throw(s))}catch(m){h(m)}},o=s=>s.done?a(s.value):Promise.resolve(s.value).then(c,i);o((e=e.apply(r,t)).next())});const gt=K(),$={POINT:"POINT",COUNTRY:"COUNTRY"};class dt extends S.Map{constructor(t){var e;const a=R(t.style);console.log(a);const 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(M({},t),{style:a,maplibreLogo:!1,transformRequest:c=>{const i=new URL(c);return i.host===d.maptilerApiHost&&(i.searchParams.has("key")||i.searchParams.append("key",g.apiKey),g.session&&i.searchParams.append("mtsid",gt)),{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===$.COUNTRY){yield this.fitToIpBounds();return}}catch(i){console.warn(i.message)}let c=null;try{yield this.centerOnIpPoint(t.zoom),c=this.getCameraHash()}catch(i){console.warn(i.message)}(yield navigator.permissions.query({name:"geolocation"})).state==="granted"&&navigator.geolocation.getCurrentPosition(i=>{c===this.getCameraHash()&&this.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*(){Y()})),this.once("load",()=>C(this,null,function*(){let c={logo:null};try{const i=Object.keys(this.style.sourceCaches).map(s=>this.getSource(s)).filter(s=>typeof s.url=="string"&&s.url.includes("tiles.json")),o=new URL(i[0].url);o.searchParams.has("key")||o.searchParams.append("key",g.apiKey),c=yield(yield fetch(o.href)).json()}catch{}if("logo"in c&&c.logo){const i=c.logo;this.addControl(new w({logoURL:i}),t.logoPosition),t.attributionControl===!1&&this.addControl(new S.AttributionControl(t))}else t.maptilerLogo&&this.addControl(new w,t.logoPosition);if(t.scaleControl){const i=t.scaleControl===!0||t.scaleControl===void 0?"bottom-right":t.scaleControl,o=new S.ScaleControl({unit:g.unit});this.addControl(o,i),g.on("unit",s=>{o.setUnit(s)})}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 nt({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 tt,i)}if(t.fullscreenControl){const i=t.fullscreenControl===!0||t.fullscreenControl===void 0?"top-right":t.fullscreenControl;this.addControl(new S.FullscreenControl({}),i)}})),t.terrain&&this.enableTerrain((e=t.terrainExaggeration)!=null?e:this.terrainExaggeration)}setStyle(t,e){return super.setStyle(R(t),e)}setLanguage(t=d.primaryLanguage){if(t===f.AUTO)return this.setLanguage(T());this.setPrimaryLanguage(t)}setPrimaryLanguage(t=d.primaryLanguage){!E(t)||this.onStyleReady(()=>{if(t===f.AUTO)return this.setPrimaryLanguage(T());g.primaryLanguage=t;const e=this.getStyle().layers,a=/^\s*{\s*name\s*(:\s*(\S*))?\s*}$/,h=/^\s*name\s*(:\s*(\S*))?\s*$/,c=/^\s*{\s*name\s*(:\s*(\S*))?\s*}(\s*){\s*name\s*(:\s*(\S*))?\s*}$/,i=/^(.*)({\s*name\s*(:\s*(\S*))?\s*})(.*)$/,o=t?`name:${t}`:"name",s=["case",["has",o],["get",o],["get","name:latin"]];for(let m=0;m<e.length;m+=1){const u=e[m],y=u.layout;if(!y||!y["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)&&a.exec(_.toString())){l[L]=s;break}else if(Array.isArray(_)&&_.length>=2&&_[0].trim().toLowerCase()==="get"&&h.exec(_[1].toString())){l[L]=s;break}else if(Array.isArray(_)&&_.length===4&&_[0].trim().toLowerCase()==="case"){l[L]=s;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=s;this.setLayoutProperty(u.id,"text-field",l)}else if((typeof n=="string"||n instanceof String)&&a.exec(n.toString())){const l=s;this.setLayoutProperty(u.id,"text-field",l)}else if(Array.isArray(n)&&n.length===4&&n[0].trim().toLowerCase()==="case"){const l=s;this.setLayoutProperty(u.id,"text-field",l)}else if((typeof n=="string"||n instanceof String)&&(p=c.exec(n.toString()))!==null){const l=`{${o}}${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]}{${o}}${p[5]}`;this.setLayoutProperty(u.id,"text-field",l)}}})}setSecondaryLanguage(t=d.secondaryLanguage){!E(t)||this.onStyleReady(()=>{if(t===f.AUTO)return this.setSecondaryLanguage(T());g.secondaryLanguage=t;const e=this.getStyle().layers,a=/^\s*{\s*name\s*(:\s*(\S*))?\s*}$/,h=/^\s*name\s*(:\s*(\S*))?\s*$/,c=/^\s*{\s*name\s*(:\s*(\S*))?\s*}(\s*){\s*name\s*(:\s*(\S*))?\s*}$/;let i;for(let o=0;o<e.length;o+=1){const s=e[o],m=s.layout;if(!m||!m["text-field"])continue;const u=this.getLayoutProperty(s.id,"text-field");let y;if(Array.isArray(u)&&u.length>=2&&u[0].trim().toLowerCase()==="concat"){y=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)&&a.exec(l.toString())){if(n===1){y[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){y[p][1]=`name:${t}`;break}n+=1}else if(Array.isArray(l)&&l.length===4&&l[0].trim().toLowerCase()==="case"){if(n===1){y[p]=["get",`name:${t}`];break}n+=1}}this.setLayoutProperty(s.id,"text-field",y)}else if((typeof u=="string"||u instanceof String)&&(i=c.exec(u.toString()))!==null){const n=t?`name:${t}`:"name";y=`{name${i[1]||""}}${i[3]}{${n}}`,this.setLayoutProperty(s.id,"text-field",y)}}})}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(),a=()=>{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(M({},e),{exaggeration:t}));return}this.loaded()||this.isTerrainEnabled?a():this.once("load",()=>{this.getTerrain()&&this.getSource(d.terrainSourceId)||a()})}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(),G.fromUint8Array(new Uint8Array(t.buffer))}}class x{constructor(t,e){this.x=t,this.y=e}_matMult(t){const e=t[0]*this.x+t[1]*this.y,a=t[2]*this.x+t[3]*this.y;return this.x=e,this.y=a,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),a=Math.sin(t),h=e*this.x-a*this.y,c=a*this.x+e*this.y;return this.x=h,this.y=c,this}_rotateAround(t,e){const a=Math.cos(t),h=Math.sin(t),c=e.x+a*(this.x-e.x)-h*(this.y-e.y),i=e.y+h*(this.x-e.x)+a*(this.y-e.y);return this.x=c,this.y=i,this}_round(){return this.x=Math.round(this.x),this.y=Math.round(this.y),this}clone(){return new x(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,a=t.y-this.y;return e*e+a*a}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 x?t:Array.isArray(t)?new x(t[0],t[1]):t}}const{supported:pt,setRTLTextPlugin:mt,getRTLTextPluginStatus:yt,NavigationControl:_t,GeolocateControl:ft,AttributionControl:St,LogoControl:At,ScaleControl:Lt,FullscreenControl:Ct,TerrainControl:xt,Popup:bt,Marker:Tt,Style:It,LngLat:vt,LngLatBounds:Et,MercatorCoordinate:Nt,Evented:wt,AJAXError:Rt,CanvasSource:Pt,GeoJSONSource:Ut,ImageSource:Ot,RasterDEMTileSource:kt,RasterTileSource:Mt,VectorTileSource:Bt,VideoSource:$t,prewarm:Ht,clearPrewarmedResources:jt,version:Gt,workerCount:Kt,maxParallelImageRequests:Dt,clearStorage:zt,workerUrl:Ft,addProtocol:Vt,removeProtocol:Zt}=S;export{Rt as AJAXError,St as AttributionControl,Pt as CanvasSource,wt as Evented,Ct as FullscreenControl,Ut as GeoJSONSource,ft as GeolocateControl,$ as GeolocationType,Ot as ImageSource,f as Language,re as LanguageGeocoding,vt as LngLat,Et as LngLatBounds,At as LogoControl,dt as Map,ie as MapStyle,ae as MapStyleVariant,Tt as Marker,Nt as MercatorCoordinate,_t as NavigationControl,x as Point,bt as Popup,kt as RasterDEMTileSource,Mt as RasterTileSource,oe as ReferenceMapStyle,Lt as ScaleControl,N as SdkConfig,ne as ServiceError,It as Style,xt as TerrainControl,Bt as VectorTileSource,$t as VideoSource,Vt as addProtocol,jt as clearPrewarmedResources,zt as clearStorage,g as config,se as coordinates,le as data,ce as geocoding,he as geolocation,yt as getRTLTextPluginStatus,Dt as maxParallelImageRequests,Ht as prewarm,Zt as removeProtocol,mt as setRTLTextPlugin,ue as staticMaps,pt as supported,Gt as version,Kt as workerCount,Ft as workerUrl};
|
|
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 b,expandMapStyle as D,MapStyleVariant as z,ReferenceMapStyle as V,MapStyle as F,mapStylePresetList as q,geolocation as I}from"@maptiler/client";import{LanguageGeocoding as re,MapStyle as ie,MapStyleVariant as ae,ReferenceMapStyle as oe,ServiceError as ne,coordinates as se,data as le,geocoding as ce,geolocation as he,staticMaps as ue}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"},J=new Set(Object.values(S));function v(r){return J.has(r)}const Z=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=>Z.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,b.apiKey=t,this.emit("apiKey",t)}get apiKey(){return this._apiKey}set fetch(t){b.fetch=t}get fetch(){return b.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/tiles.json",terrainSourceId:"maptiler-terrain"};Object.freeze(d);class N extends m.LogoControl{constructor(t={}){var e,a;super(t),this.logoURL="",this.linkURL="",this.logoURL=(e=t.logoURL)!=null?e:d.maptilerLogoURL,this.linkURL=(a=t.linkURL)!=null?a: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 a=window.document.createElement(r);return t!==void 0&&(a.className=t),e&&e.appendChild(a),a}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[q[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 a=super._createButton(t,e);return a.clickFunction=e,a}_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,R=Object.getOwnPropertySymbols,rt=Object.prototype.hasOwnProperty,it=Object.prototype.propertyIsEnumerable,P=(r,t,e)=>t in r?et(r,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):r[t]=e,at=(r,t)=>{for(var e in t||(t={}))rt.call(t,e)&&P(r,e,t[e]);if(R)for(var e of R(t))it.call(t,e)&&P(r,e,t[e]);return r};const ot=m.GeolocateControl,U=m.Marker,O=m.LngLat;class nt extends ot{constructor(){super(...arguments),this.lastUpdatedCenter=new O(0,0)}_updateCamera(t){const e=new O(t.coords.longitude,t.coords.latitude),a=t.coords.accuracy,h=this._map.getBearing(),c=at({bearing:h},this.options.fitBoundsOptions);this._map.fitBounds(e.toBounds(a),c,{geolocateSource:!0});let i=!1;const o=()=>{i=!0};this._map.once("click",o),this._map.once("dblclick",o),this._map.once("dragstart",o),this._map.once("mousedown",o),this._map.once("touchstart",o),this._map.once("wheel",o),this._map.once("moveend",()=>{this._map.off("click",o),this._map.off("dblclick",o),this._map.off("dragstart",o),this._map.off("mousedown",o),this._map.off("touchstart",o),this._map.off("wheel",o),!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 a=e.originalEvent&&e.originalEvent.type==="resize",h=this.lastUpdatedCenter.distanceTo(this._map.getCenter());!e.geolocateSource&&this._watchState==="ACTIVE_LOCK"&&!a&&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),a=this._map.unproject([e.x,e.y]),h=this._map.unproject([e.x+20,e.y]),c=a.distanceTo(h)/20,i=Math.ceil(2*this._accuracy/c);this._circleElement.style.width=`${i}px`,this._circleElement.style.height=`${i}px`}_onZoom(){this.options.showUserLocation&&this.options.showAccuracyCircle&&this._updateCircleRadius()}}var st=Object.defineProperty,lt=Object.defineProperties,ct=Object.getOwnPropertyDescriptors,k=Object.getOwnPropertySymbols,ht=Object.prototype.hasOwnProperty,ut=Object.prototype.propertyIsEnumerable,M=(r,t,e)=>t in r?st(r,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):r[t]=e,B=(r,t)=>{for(var e in t||(t={}))ht.call(t,e)&&M(r,e,t[e]);if(k)for(var e of k(t))ut.call(t,e)&&M(r,e,t[e]);return r},$=(r,t)=>lt(r,ct(t)),C=(r,t,e)=>new Promise((a,h)=>{var c=s=>{try{o(e.next(s))}catch(y){h(y)}},i=s=>{try{o(e.throw(s))}catch(y){h(y)}},o=s=>s.done?a(s.value):Promise.resolve(s.value).then(c,i);o((e=e.apply(r,t)).next())});const gt=K(),H={POINT:"POINT",COUNTRY:"COUNTRY"};class dt extends m.Map{constructor(t){var e;const a=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:a,maplibreLogo:!1,transformRequest:c=>{let i=null;try{i=new URL(c)}catch{return{url:c,headers:{}}}return i.host===d.maptilerApiHost&&(i.searchParams.has("key")||i.searchParams.append("key",g.apiKey),g.session&&i.searchParams.append("mtsid",gt)),{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 c=null;try{yield this.centerOnIpPoint(t.zoom),c=this.getCameraHash()}catch(i){console.warn(i.message)}(yield navigator.permissions.query({name:"geolocation"})).state==="granted"&&navigator.geolocation.getCurrentPosition(i=>{c===this.getCameraHash()&&this.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 c={logo:null};try{const i=Object.keys(this.style.sourceCaches).map(s=>this.getSource(s)).filter(s=>typeof s.url=="string"&&s.url.includes("tiles.json")),o=new URL(i[0].url);o.searchParams.has("key")||o.searchParams.append("key",g.apiKey),c=yield(yield fetch(o.href)).json()}catch{}if("logo"in c&&c.logo){const i=c.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,o=new m.ScaleControl({unit:g.unit});this.addControl(o,i),g.on("unit",s=>{o.setUnit(s)})}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 nt({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,a=/^\s*{\s*name\s*(:\s*(\S*))?\s*}$/,h=/^\s*name\s*(:\s*(\S*))?\s*$/,c=/^\s*{\s*name\s*(:\s*(\S*))?\s*}(\s*){\s*name\s*(:\s*(\S*))?\s*}$/,i=/^(.*)({\s*name\s*(:\s*(\S*))?\s*})(.*)$/,o=t?`name:${t}`:"name",s=["case",["has",o],["get",o],["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)&&a.exec(_.toString())){l[L]=s;break}else if(Array.isArray(_)&&_.length>=2&&_[0].trim().toLowerCase()==="get"&&h.exec(_[1].toString())){l[L]=s;break}else if(Array.isArray(_)&&_.length===4&&_[0].trim().toLowerCase()==="case"){l[L]=s;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=s;this.setLayoutProperty(u.id,"text-field",l)}else if((typeof n=="string"||n instanceof String)&&a.exec(n.toString())){const l=s;this.setLayoutProperty(u.id,"text-field",l)}else if(Array.isArray(n)&&n.length===4&&n[0].trim().toLowerCase()==="case"){const l=s;this.setLayoutProperty(u.id,"text-field",l)}else if((typeof n=="string"||n instanceof String)&&(p=c.exec(n.toString()))!==null){const l=`{${o}}${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]}{${o}}${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,a=/^\s*{\s*name\s*(:\s*(\S*))?\s*}$/,h=/^\s*name\s*(:\s*(\S*))?\s*$/,c=/^\s*{\s*name\s*(:\s*(\S*))?\s*}(\s*){\s*name\s*(:\s*(\S*))?\s*}$/;let i;for(let o=0;o<e.length;o+=1){const s=e[o],y=s.layout;if(!y||!y["text-field"])continue;const u=this.getLayoutProperty(s.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)&&a.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(s.id,"text-field",f)}else if((typeof u=="string"||u instanceof String)&&(i=c.exec(u.toString()))!==null){const n=t?`name:${t}`:"name";f=`{name${i[1]||""}}${i[3]}{${n}}`,this.setLayoutProperty(s.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(),a=()=>{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?a():this.once("load",()=>{this.getTerrain()&&this.getSource(d.terrainSourceId)||a()})}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 x{constructor(t,e){this.x=t,this.y=e}_matMult(t){const e=t[0]*this.x+t[1]*this.y,a=t[2]*this.x+t[3]*this.y;return this.x=e,this.y=a,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),a=Math.sin(t),h=e*this.x-a*this.y,c=a*this.x+e*this.y;return this.x=h,this.y=c,this}_rotateAround(t,e){const a=Math.cos(t),h=Math.sin(t),c=e.x+a*(this.x-e.x)-h*(this.y-e.y),i=e.y+h*(this.x-e.x)+a*(this.y-e.y);return this.x=c,this.y=i,this}_round(){return this.x=Math.round(this.x),this.y=Math.round(this.y),this}clone(){return new x(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,a=t.y-this.y;return e*e+a*a}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 x?t:Array.isArray(t)?new x(t[0],t[1]):t}}const{supported:pt,setRTLTextPlugin:mt,getRTLTextPluginStatus:yt,NavigationControl:ft,GeolocateControl:_t,AttributionControl:St,LogoControl:At,ScaleControl:Lt,FullscreenControl:Ct,TerrainControl:xt,Popup:bt,Marker:Tt,Style:It,LngLat:vt,LngLatBounds:Et,MercatorCoordinate:Nt,Evented:wt,AJAXError:Rt,CanvasSource:Pt,GeoJSONSource:Ut,ImageSource:Ot,RasterDEMTileSource:kt,RasterTileSource:Mt,VectorTileSource:Bt,VideoSource:$t,prewarm:Ht,clearPrewarmedResources:jt,version:Kt,workerCount:Gt,maxParallelImageRequests:Dt,clearStorage:zt,workerUrl:Vt,addProtocol:Ft,removeProtocol:qt}=m;export{Rt as AJAXError,St as AttributionControl,Pt as CanvasSource,wt as Evented,Ct as FullscreenControl,Ut as GeoJSONSource,_t as GeolocateControl,H as GeolocationType,Ot as ImageSource,S as Language,re as LanguageGeocoding,vt as LngLat,Et as LngLatBounds,At as LogoControl,dt as Map,ie as MapStyle,ae as MapStyleVariant,Tt as Marker,Nt as MercatorCoordinate,ft as NavigationControl,x as Point,bt as Popup,kt as RasterDEMTileSource,Mt as RasterTileSource,oe as ReferenceMapStyle,Lt as ScaleControl,E as SdkConfig,ne as ServiceError,It as Style,xt as TerrainControl,Bt as VectorTileSource,$t as VideoSource,Ft as addProtocol,jt as clearPrewarmedResources,zt as clearStorage,g as config,se as coordinates,le as data,ce as geocoding,he as geolocation,yt as getRTLTextPluginStatus,Dt as maxParallelImageRequests,Ht as prewarm,qt as removeProtocol,mt as setRTLTextPlugin,ue as staticMaps,pt as supported,Kt as version,Gt as workerCount,Vt as workerUrl};
|
package/dist/maptiler-sdk.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import maplibregl__default
|
|
1
|
+
import maplibregl__default from 'maplibre-gl';
|
|
2
2
|
export * from 'maplibre-gl';
|
|
3
3
|
import { Base64 } from 'js-base64';
|
|
4
4
|
import { v4 } from 'uuid';
|
|
@@ -220,7 +220,11 @@ function styleToStyle(style) {
|
|
|
220
220
|
return MapStyle[mapStylePresetList[0].referenceStyleID].getDefaultVariant().getExpandedStyleURL();
|
|
221
221
|
}
|
|
222
222
|
if (typeof style === "string" || style instanceof String) {
|
|
223
|
-
|
|
223
|
+
if (!style.startsWith("http") && style.toLowerCase().includes(".json")) {
|
|
224
|
+
return style;
|
|
225
|
+
} else {
|
|
226
|
+
return expandMapStyle(style);
|
|
227
|
+
}
|
|
224
228
|
}
|
|
225
229
|
if (style instanceof MapStyleVariant) {
|
|
226
230
|
return style.getExpandedStyleURL();
|
|
@@ -339,7 +343,14 @@ var __spreadValues$1 = (a, b) => {
|
|
|
339
343
|
}
|
|
340
344
|
return a;
|
|
341
345
|
};
|
|
346
|
+
const GeolocateControl$1 = maplibregl__default.GeolocateControl;
|
|
347
|
+
const Marker$1 = maplibregl__default.Marker;
|
|
348
|
+
const LngLat$1 = maplibregl__default.LngLat;
|
|
342
349
|
class CustomGeolocateControl extends GeolocateControl$1 {
|
|
350
|
+
constructor() {
|
|
351
|
+
super(...arguments);
|
|
352
|
+
this.lastUpdatedCenter = new LngLat$1(0, 0);
|
|
353
|
+
}
|
|
343
354
|
_updateCamera(position) {
|
|
344
355
|
const center = new LngLat$1(
|
|
345
356
|
position.coords.longitude,
|
|
@@ -350,13 +361,11 @@ class CustomGeolocateControl extends GeolocateControl$1 {
|
|
|
350
361
|
const options = __spreadValues$1({
|
|
351
362
|
bearing
|
|
352
363
|
}, this.options.fitBoundsOptions);
|
|
353
|
-
console.log("moving camera");
|
|
354
364
|
this._map.fitBounds(center.toBounds(radius), options, {
|
|
355
365
|
geolocateSource: true
|
|
356
366
|
});
|
|
357
367
|
let hasFittingBeenDisrupted = false;
|
|
358
368
|
const flagFittingDisruption = () => {
|
|
359
|
-
console.log("DISRUPTED FITTING!");
|
|
360
369
|
hasFittingBeenDisrupted = true;
|
|
361
370
|
};
|
|
362
371
|
this._map.once("click", flagFittingDisruption);
|
|
@@ -366,7 +375,6 @@ class CustomGeolocateControl extends GeolocateControl$1 {
|
|
|
366
375
|
this._map.once("touchstart", flagFittingDisruption);
|
|
367
376
|
this._map.once("wheel", flagFittingDisruption);
|
|
368
377
|
this._map.once("moveend", () => {
|
|
369
|
-
console.log("done moving, with disruption:", hasFittingBeenDisrupted);
|
|
370
378
|
this._map.off("click", flagFittingDisruption);
|
|
371
379
|
this._map.off("dblclick", flagFittingDisruption);
|
|
372
380
|
this._map.off("dragstart", flagFittingDisruption);
|
|
@@ -377,12 +385,10 @@ class CustomGeolocateControl extends GeolocateControl$1 {
|
|
|
377
385
|
return;
|
|
378
386
|
}
|
|
379
387
|
this.lastUpdatedCenter = this._map.getCenter();
|
|
380
|
-
this.lastUpdatedZoom = this._map.getZoom();
|
|
381
388
|
});
|
|
382
389
|
}
|
|
383
390
|
_setupUI(supported) {
|
|
384
391
|
this.lastUpdatedCenter = this._map.getCenter();
|
|
385
|
-
this.lastUpdatedZoom = this._map.getZoom();
|
|
386
392
|
this._container.addEventListener(
|
|
387
393
|
"contextmenu",
|
|
388
394
|
(e) => e.preventDefault()
|
|
@@ -524,7 +530,6 @@ class Map extends maplibregl__default.Map {
|
|
|
524
530
|
constructor(options) {
|
|
525
531
|
var _a;
|
|
526
532
|
const style = styleToStyle(options.style);
|
|
527
|
-
console.log(style);
|
|
528
533
|
const hashPreConstructor = location.hash;
|
|
529
534
|
if (!config.apiKey) {
|
|
530
535
|
console.warn(
|
|
@@ -535,7 +540,15 @@ class Map extends maplibregl__default.Map {
|
|
|
535
540
|
style,
|
|
536
541
|
maplibreLogo: false,
|
|
537
542
|
transformRequest: (url) => {
|
|
538
|
-
|
|
543
|
+
let reqUrl = null;
|
|
544
|
+
try {
|
|
545
|
+
reqUrl = new URL(url);
|
|
546
|
+
} catch (e) {
|
|
547
|
+
return {
|
|
548
|
+
url,
|
|
549
|
+
headers: {}
|
|
550
|
+
};
|
|
551
|
+
}
|
|
539
552
|
if (reqUrl.host === defaults.maptilerApiHost) {
|
|
540
553
|
if (!reqUrl.searchParams.has("key")) {
|
|
541
554
|
reqUrl.searchParams.append("key", config.apiKey);
|