mahal_map 2.2.3 → 2.4.0

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/dist/index.mjs CHANGED
@@ -1,4 +1,4 @@
1
- var Se=Object.defineProperty;var B=(i,e)=>{for(var t in e)Se(i,t,{get:e[t],enumerable:!0})};var v=class{constructor(e){this.map=e}setZoom(e,t=!0){t?this.map.easeTo({zoom:e}):this.map.setZoom(e)}setBearing(e,t=!0){t?this.map.easeTo({bearing:e}):this.map.setBearing(e)}setPitch(e,t=!0){t?this.map.easeTo({pitch:e}):this.map.setPitch(e)}toggle3D(e){this.map.easeTo({pitch:e?60:0,bearing:e?this.map.getBearing():0,duration:800})}resetNorth(){this.map.easeTo({bearing:0,pitch:0,duration:600})}flyTo(e){this.map.flyTo({speed:1.2,curve:1.42,essential:!0,...e})}getPitch(){return this.map.getPitch()}};var Z="https://geocode.mahal.tj/api/",H=/^([-+]?(?:[1-8]?\d(?:\.\d+)?|90(?:\.0+)?)),\s*([-+]?(?:180(?:\.0+)?|(?:(?:1[0-7]\d)|(?:[1-9]?\d))(?:\.\d+)?))$/,A=/^([-+]?(?:180(?:\.0+)?|(?:(?:1[0-7]\d)|(?:[1-9]?\d))(?:\.\d+)?)),\s*([-+]?(?:[1-8]?\d(?:\.\d+)?|90(?:\.0+)?))$/;var _="https://mtile.gram.tj/custom-styles/style_maptiler_basic_hn.json",R="https://navi.gram.tj";function T(i,e){return i==="default"?e:`${i}-${e}`}function Ce(i,e,t){let r=new URL(i);return r.searchParams.set(e,t),r.toString()}function Y(i,e){return e?Ce(i,"token",e):i}var F="";function Ie(i){i!==""&&(F=i)}function ke(){F=""}var M=()=>F;import we from"axios";var y=we.create({baseURL:Z});var X=async i=>{try{return(await y.post("services/geocoder",null,{params:i})).data}catch(e){throw console.error("Error while searching address:",e),e}},Q=async i=>{try{return(await y.post("services/geoorg",null,{params:i})).data}catch(e){throw console.error("Error while searching poi:",e),e}},ee=async i=>{try{return(await y.post("services/gercoderByLocation",null,{params:i})).data}catch(e){throw console.error("Error while searching address by location:",e),e}},te=async i=>{try{return(await y.post("services/checkJSApi",null,{params:i})).data}catch(e){let t=e?.response?.data;if(t&&typeof t.success=="boolean")return t;throw console.error("Error while checking JSApi subscription:",e),e}};var ae={};B(ae,{checkCoordinates:()=>Pe,debounce:()=>S,geojsonPolyline:()=>O,geometryPolyline:()=>ie,trimValue:()=>Ee});function Pe(i){let e,t;if(H.test(i)){let r=i.match(H);r&&([,e,t]=r)}else if(A.test(i)){let r=i.match(A);r&&([,t,e]=r)}else return console.log("\u041D\u0435\u0432\u0435\u0440\u043D\u044B\u0439 \u0444\u043E\u0440\u043C\u0430\u0442 \u043A\u043E\u043E\u0440\u0434\u0438\u043D\u0430\u0442"),null;return{lat:e,lng:t}}function S(i,e){let t;return(...r)=>(t&&clearTimeout(t),new Promise(a=>{t=setTimeout(async()=>{let s=await i(...r);a(s)},e)}))}function O(i){let e=[],t=0,r=i.length,a=0,s=0;for(;t<r;){let n,p=0,o=0;do n=i.charCodeAt(t++)-63,o|=(n&31)<<p,p+=5;while(n>=32);let h=o&1?~(o>>1):o>>1;a+=h,p=0,o=0;do n=i.charCodeAt(t++)-63,o|=(n&31)<<p,p+=5;while(n>=32);let d=o&1?~(o>>1):o>>1;s+=d,e.push([s*1e-5,a*1e-5])}return e}function xe(i){let e="",t=0,r=0;for(let a=0;a<i.length;a++){let[s,n]=i[a],p=Math.round(n*1e5),o=Math.round(s*1e5),h=p-t,d=o-r;t=p,r=o,e+=re(h)+re(d)}return e}function re(i){let e=i<<1;return i<0&&(e=~e),De(e)}function De(i){let e="";for(;i>=32;)e+=String.fromCharCode((32|i&31)+63),i>>=5;return e+=String.fromCharCode(i+63),e}var ie=xe;function Ee(i,e){if(e<=0)return"";let t=i.trim();return e>=t.length?t:t.slice(0,e)}async function Be(i,e,t){let r={text:i,token:e,...t};try{return(await X(r)).data}catch(a){throw a}}async function He(i,e,t){let r={text:i,token:e,...t};try{return(await Q(r)).data}catch(a){throw a}}var Ae=S(Be,500),Re=S(He,500);async function se(i,e,t){if(!e)throw new Error("[MahalMap SDK] Search token is required");return await Ae(i,e,t)}async function ne(i,e,t){if(!e)throw new Error("[MahalMap SDK] SearchPoi token is required");return await Re(i,e,t)}async function oe(i){if(!i.token)throw new Error("[MahalMap SDK] SearchByLocation token is required");let e={...i};try{return await ee(e)}catch(t){throw t}}async function C(i){if(!i)throw new Error("[MahalMap SDK] CheckJSApi token is required");return await te({token:i})}var Te=/<svg[\s>]/i,Fe=/<(svg|path|g|circle|rect|polygon|line|polyline|ellipse|use)\b/i,I=(i,e,t)=>{let r=new RegExp(`\\s${e}="[^"]*"`,"i");return r.test(i)?i.replace(r,` ${e}="${t}"`):i.replace(/<svg\b/i,`<svg ${e}="${t}"`)},Oe=i=>i.replace(/&/g,"&amp;").replace(/"/g,"&quot;"),le=i=>`<image href="${Oe(i)}" x="14" y="12" width="22" height="22" style="filter: brightness(0) invert(1);" />`,Ge=i=>{let e=i.trim();if(Te.test(e)){let t=I(e,"x","14");return t=I(t,"y","12"),t=I(t,"width","22"),t=I(t,"height","22"),/\spreserveAspectRatio="/i.test(t)||(t=t.replace(/<svg\b/i,'<svg preserveAspectRatio="xMidYMid meet"')),t}return`<g transform="translate(14 12)">${e}</g>`},$e=({innerSvg:i,innerUrl:e})=>{let t=i?.trim(),r=e?.trim();return t?Fe.test(t)?Ge(t):le(t):r?le(r):""},pe=(i,e={})=>`<svg
1
+ var Pe=Object.defineProperty;var B=(a,e)=>{for(var t in e)Pe(a,t,{get:e[t],enumerable:!0})};var v=class{constructor(e){this.map=e}setZoom(e,t=!0){t?this.map.easeTo({zoom:e}):this.map.setZoom(e)}setBearing(e,t=!0){t?this.map.easeTo({bearing:e}):this.map.setBearing(e)}setPitch(e,t=!0){t?this.map.easeTo({pitch:e}):this.map.setPitch(e)}toggle3D(e){this.map.easeTo({pitch:e?60:0,bearing:e?this.map.getBearing():0,duration:800})}resetNorth(){this.map.easeTo({bearing:0,pitch:0,duration:600})}flyTo(e){this.map.flyTo({speed:1.2,curve:1.42,essential:!0,...e})}getPitch(){return this.map.getPitch()}};var X="https://geocode.mahal.tj/api/",H=/^([-+]?(?:[1-8]?\d(?:\.\d+)?|90(?:\.0+)?)),\s*([-+]?(?:180(?:\.0+)?|(?:(?:1[0-7]\d)|(?:[1-9]?\d))(?:\.\d+)?))$/,A=/^([-+]?(?:180(?:\.0+)?|(?:(?:1[0-7]\d)|(?:[1-9]?\d))(?:\.\d+)?)),\s*([-+]?(?:[1-8]?\d(?:\.\d+)?|90(?:\.0+)?))$/;var Q="https://mtile.gram.tj/custom-styles/style_maptiler_basic_hn.json",T="https://navi.gram.tj";function R(a,e){return a==="default"?e:`${a}-${e}`}function De(a,e,t){let r=new URL(a);return r.searchParams.set(e,t),r.toString()}function ee(a,e){return e?De(a,"token",e):a}var F="";function xe(a){a!==""&&(F=a)}function Ee(){F=""}var M=()=>F;import Be from"axios";var y=Be.create({baseURL:X});var te=async a=>{try{return(await y.post("services/geocoder",null,{params:a})).data}catch(e){throw console.error("Error while searching address:",e),e}},re=async a=>{try{return(await y.post("services/geoorg",null,{params:a})).data}catch(e){throw console.error("Error while searching poi:",e),e}},ae=async a=>{try{return(await y.post("services/gercoderByLocation",null,{params:a})).data}catch(e){throw console.error("Error while searching address by location:",e),e}},ie=async a=>{try{return(await y.post("services/checkJSApi",null,{params:a})).data}catch(e){let t=e?.response?.data;if(t&&typeof t.success=="boolean")return t;throw console.error("Error while checking JSApi subscription:",e),e}};var oe={};B(oe,{DebounceCancelledError:()=>b,checkCoordinates:()=>He,debounce:()=>O,geojsonPolyline:()=>G,geometryPolyline:()=>ne,trimValue:()=>Re});function He(a){let e,t;if(H.test(a)){let r=a.match(H);r&&([,e,t]=r)}else if(A.test(a)){let r=a.match(A);r&&([,t,e]=r)}else return console.log("\u041D\u0435\u0432\u0435\u0440\u043D\u044B\u0439 \u0444\u043E\u0440\u043C\u0430\u0442 \u043A\u043E\u043E\u0440\u0434\u0438\u043D\u0430\u0442"),null;return{lat:e,lng:t}}var b=class extends Error{constructor(){super("[MahalMap SDK] The call was superseded by a newer one"),this.name="DebounceCancelledError"}};function O(a,e,t={}){let r,i=[];return(...s)=>new Promise((n,p)=>{t.rejectSuperseded&&i.splice(0).forEach(o=>o.reject(new b)),i.push({resolve:n,reject:p}),r&&clearTimeout(r),r=setTimeout(async()=>{r=void 0;let o=i;i=[];try{let h=await a(...s);o.forEach(u=>u.resolve(h))}catch(h){o.forEach(u=>u.reject(h))}},e)})}function G(a){let e=[],t=0,r=a.length,i=0,s=0;for(;t<r;){let n,p=0,o=0;do n=a.charCodeAt(t++)-63,o|=(n&31)<<p,p+=5;while(n>=32);let h=o&1?~(o>>1):o>>1;i+=h,p=0,o=0;do n=a.charCodeAt(t++)-63,o|=(n&31)<<p,p+=5;while(n>=32);let u=o&1?~(o>>1):o>>1;s+=u,e.push([s*1e-5,i*1e-5])}return e}function Ae(a){let e="",t=0,r=0;for(let i=0;i<a.length;i++){let[s,n]=a[i],p=Math.round(n*1e5),o=Math.round(s*1e5),h=p-t,u=o-r;t=p,r=o,e+=se(h)+se(u)}return e}function se(a){let e=a<<1;return a<0&&(e=~e),Te(e)}function Te(a){let e="";for(;a>=32;)e+=String.fromCharCode((32|a&31)+63),a>>=5;return e+=String.fromCharCode(a+63),e}var ne=Ae;function Re(a,e){if(e<=0)return"";let t=a.trim();return e>=t.length?t:t.slice(0,e)}async function Fe(a,e,t){let r={text:a,token:e,...t};try{return(await te(r)).data}catch(i){throw i}}async function Oe(a,e,t){let r={text:a,token:e,...t};try{return(await re(r)).data}catch(i){throw i}}var le=500;async function K(a,e,t){if(!e)throw new Error("[MahalMap SDK] Search token is required");return await Fe(a,e,t)}async function $(a,e,t){if(!e)throw new Error("[MahalMap SDK] SearchPoi token is required");return await Oe(a,e,t)}function pe(a,e){let t=O(a,e,{rejectSuperseded:!0});return async(r,i,s)=>await t(r,i,s)}function he(a=le){return pe(K,a)}function ue(a=le){return pe($,a)}async function de(a){if(!a.token)throw new Error("[MahalMap SDK] SearchByLocation token is required");let e={...a};try{return await ae(e)}catch(t){throw t}}async function C(a){if(!a)throw new Error("[MahalMap SDK] CheckJSApi token is required");return await ie({token:a})}var Ge=/<svg[\s>]/i,Ke=/<(svg|path|g|circle|rect|polygon|line|polyline|ellipse|use)\b/i,I=(a,e,t)=>{let r=new RegExp(`\\s${e}="[^"]*"`,"i");return r.test(a)?a.replace(r,` ${e}="${t}"`):a.replace(/<svg\b/i,`<svg ${e}="${t}"`)},$e=a=>a.replace(/&/g,"&amp;").replace(/"/g,"&quot;"),ce=a=>`<image href="${$e(a)}" x="14" y="12" width="22" height="22" style="filter: brightness(0) invert(1);" />`,je=a=>{let e=a.trim();if(Ge.test(e)){let t=I(e,"x","14");return t=I(t,"y","12"),t=I(t,"width","22"),t=I(t,"height","22"),/\spreserveAspectRatio="/i.test(t)||(t=t.replace(/<svg\b/i,'<svg preserveAspectRatio="xMidYMid meet"')),t}return`<g transform="translate(14 12)">${e}</g>`},Je=({innerSvg:a,innerUrl:e})=>{let t=a?.trim(),r=e?.trim();return t?Ke.test(t)?je(t):ce(t):r?ce(r):""},ge=(a,e={})=>`<svg
2
2
  width="50"
3
3
  height="62"
4
4
  viewBox="0 0 50 62"
@@ -10,17 +10,17 @@ var Se=Object.defineProperty;var B=(i,e)=>{for(var t in e)Se(i,t,{get:e[t],enume
10
10
  fill-rule="evenodd"
11
11
  clip-rule="evenodd"
12
12
  d="M25 2C36.598 2 46 11.402 46 23C46 33.1603 38.7844 41.6353 29.198 43.5803L25.6524 48.6575C25.5788 48.7633 25.4812 48.8497 25.3676 48.9093C25.254 48.9689 25.128 49 25 49C24.872 49 24.746 48.9689 24.6324 48.9093C24.5188 48.8497 24.4212 48.7633 24.3476 48.6575L20.802 43.5803C11.2156 41.6353 4 33.1603 4 23C4 11.402 13.402 2 25 2Z"
13
- fill="${i||"#278960"}"
13
+ fill="${a||"#278960"}"
14
14
  />
15
15
  </g>
16
16
  <path
17
17
  d="M25 51C27.7614 51 30 53.2386 30 56C30 58.7614 27.7614 61 25 61C22.2386 61 20 58.7614 20 56C20 53.2386 22.2386 51 25 51Z"
18
- fill="${i||"#278960"}"
18
+ fill="${a||"#278960"}"
19
19
  stroke="white"
20
20
  stroke-width="2"
21
21
  />
22
22
  <g clip-path="url(#clip0_367_31358)">
23
- ${$e(e)}
23
+ ${Je(e)}
24
24
  </g>
25
25
  <defs>
26
26
  <filter
@@ -67,12 +67,12 @@ var Se=Object.defineProperty;var B=(i,e)=>{for(var t in e)Se(i,t,{get:e[t],enume
67
67
  />
68
68
  </clipPath>
69
69
  </defs>
70
- </svg>`;var G=class{constructor(e){this.props=e;this.element=this.createElement()}createElement(){let e=document.createElement("div");e.style.cursor="pointer";let t=this.props.svg?this.applyColorToCustomSvg(this.props.svg):pe(this.props.color??"#278960",{innerSvg:this.props.innerSvg,innerUrl:this.props.innerUrl});return e.innerHTML=t,e}applyColorToCustomSvg(e){return this.props.color?e.replace(/fill="[^"]*"/g,`fill="${this.props.color}"`):e}getElement(){return this.element}getCoordinates(){return this.props.coordinates}isDraggable(){return!!this.props.draggable}getAnchor(){return this.props.anchor||"center"}};function he(i,e,t){return new i.Marker({element:t.getElement(),draggable:t.isDraggable?.()??!1,anchor:t.getAnchor?.()??"center"}).setLngLat(t.getCoordinates()).addTo(e)}var Je={dark:"#ffffff",light:"#19191a"},de="buildings",l=class l{constructor(){this.isReady=!1;this.readyCallbacks=[];this.language="tj";this.instanceKey="";this.gramBase=R;this.styleFamily="default";this.presetIsExplicit=!1;this.buildingsEnabled=!1;this.pendingLayerSubscribers=new Set}static getInstanceKey(e){return typeof e.container=="string"&&e.container?e.container:"map"}static normalizeLanguage(e){return e==="ru"?"ru":"tj"}static setDefaultLanguage(e){l.defaultLanguage=l.normalizeLanguage(e)}static getFallbackStyle(){return Y(_,l.getMapToken())}static getMapToken(){let e=M();if(!e)throw new Error("[MahalMap SDK] Map API key is required. Call keyUtils.saveKey() before creating the map or pass apikey in the SDK script URL.");return e}static getMaps3DCtor(e){if(e)return e;if(typeof window>"u")return;let t=window.Maps3D;return typeof t=="function"?t:t?.Maps3D}static async ensureJSApiSubscription(e){if(e)return;let t=M();if(!t)return;let r;try{r=await C(t)}catch(a){console.warn("[MahalMap SDK] JSApi subscription check failed, continuing without it:",a);return}if(!r.success)throw new Error(`[MahalMap SDK] JSApi subscription is not active for this key: ${r.message}`)}static async createAsync(e,t,r){return await l.ensureJSApiSubscription(l.getMaps3DCtor(r)),l.create(e,t,r)}static resolveStyleName(e,t,r){return e.style||e.preset||T(t,r)}static buildPlatformMapOptions(e,t,r,a,s){try{return e.mapOptions?e.mapOptions({base:t,apiKey:r,style:a,antialias:s}):{style:e.styleUrl?e.styleUrl(a,t):l.requireAbsoluteStyle(a),transformRequest:e.transformRequest({base:t,apiKey:r}),...s?{canvasContextAttributes:{antialias:!0}}:{}}}catch(n){throw new Error(`[MahalMap SDK] Maps3D rejected the style "${a}": ${n instanceof Error?n.message:String(n)}`)}}static requireAbsoluteStyle(e){if(/^https?:/i.test(e))return e;throw new Error("this Maps3D build has no styleUrl() \u2014 pass options.style as a full URL or upgrade @grammaps/maps3d-web to >=0.5.0")}static create(e,t,r){let a=typeof window<"u"?window.maplibregl:void 0,s=t||a;if(!s)throw new Error("[MahalMap SDK] MapLibre GL was not found. Pass it as the second argument or include it through a script.");let n=l.normalizeLanguage(e.lang||l.defaultLanguage),p=e.theme==="dark"?"dark":"light",o=new l,h=l.getInstanceKey(e);o.options=e,o.language=n,o.instanceKey=h,o.maplibre=s;let d=l.getMapToken(),u=l.getMaps3DCtor(r);o.gramBase=(e.base||R).replace(/\/+$/,""),o.styleFamily=e.family||"default",o.presetIsExplicit=!!(e.style||e.preset),o.maps3dCtor=u;let c=e.enable3D!==!1&&!!u;o.buildingsEnabled=c&&e.maps3d?.buildings!==!1,e.enable3D!==!1&&!u&&console.warn("[MahalMap SDK] Maps3D was not found \u2014 falling back to the plain vector style without 3D. Pass Maps3D as the third argument to create() or include it through a script (window.Maps3D).");let m=e.antialias!==void 0?e.antialias:c,g=u?l.buildPlatformMapOptions(u,o.gramBase,d,l.resolveStyleName(e,o.styleFamily,p),m):void 0,b=c?58:0;return o.map=new s.Map({container:e.container||"map",style:g?g.style:e.style||l.getFallbackStyle(),center:e.center||[69.624024,40.279687],zoom:e.zoom!==void 0?e.zoom:5,attributionControl:!1,pitch:e.pitch!==void 0?e.pitch:b,...e.bearing!==void 0?{bearing:e.bearing}:{},...g?{transformRequest:g.transformRequest,...g.canvasContextAttributes?{canvasContextAttributes:g.canvasContextAttributes}:{}}:{}}),c&&(o.maps3dLayer=o.createMaps3DLayer(d),o.attachMaps3DLayer(o.maps3dLayer)),o.watchWorkerHealth(),o.addLogo(p),o.map.on("load",()=>{o.isReady=!0,o.camera=new v(o.map),o.readyCallbacks.forEach(be=>be(o.map)),o.readyCallbacks=[]}),l.instances.set(h,o),o}static onReady(e,t){if(!l.instances.has(e)){let a=setInterval(()=>{l.instances.has(e)&&(clearInterval(a),l.onReady(e,t))},50);return}let r=l.getInstance(e);r.isReady?t(r.map):r.readyCallbacks.push(t)}static getInstance(e){let t=l.instances.get(e);if(!t)throw new Error("[MahalMap SDK] Map instance is not created");return t}static hasInstance(e){return l.instances.has(e)}static removeInstance(e){return l.instances.delete(e)}static addMarker(e,t){return e.addMarker(t)}static getCamera(e){return e.getCamera()}static getMap(e){return e.getMap()}static setStyle(e,t){e.setStyle(t)}static getMaps3DLayer(e){return e.getMaps3DLayer()}static whenMaps3DReady(e){return e.whenMaps3DReady()}static toggle3DBuildings(e,t){e.toggle3DBuildings(t)}static setLayer(e,t,r,a){return e.setLayer(t,r,a)}static getLayerState(e,t){return e.getLayerState(t)}static getLayers(e){return e.getLayers()}static onLayers(e,t){return e.onLayers(t)}static refreshLayers(e){e.refreshLayers()}static getIndoorLevels(e){return e.getIndoorLevels()}static setIndoorLevel(e,t){e.setIndoorLevel(t)}static refreshIndoor(e){e.refreshIndoor()}static showPlace(e,t,r,a,s){e.showPlace(t,r,a,s)}static onBuildingClick(e,t){e.onBuildingClick(t)}static selectBuilding(e,t,r){return e.selectBuilding(t,r)}static clearSelection(e){e.clearSelection()}static selectedBuilding(e){return e.selectedBuilding()}static setSelectionStyle(e,t){e.setSelectionStyle(t)}static onRoadClick(e,t){e.onRoadClick(t)}static roadAt(e,t,r){return e.roadAt(t,r)}static onParkingHover(e,t){e.onParkingHover(t)}static setParkingHoverStyle(e,t){e.setParkingHoverStyle(t)}static setParkingHoverEnabled(e,t){e.setParkingHoverEnabled(t)}static hoverParking(e,t){return e.hoverParking(t)}static hoveredParking(e){return e.hoveredParking()}static onParkingClick(e,t){e.onParkingClick(t)}static parkingAt(e,t,r){return e.parkingAt(t,r)}static onBuildingHover(e,t){e.onBuildingHover(t)}static setHoverEnabled(e,t){e.setHoverEnabled(t)}static setHoverStyle(e,t){e.setHoverStyle(t)}static hoverBuilding(e,t){return e.hoverBuilding(t)}static hoveredBuilding(e){return e.hoveredBuilding()}static setLanguage(e,t){e.setLanguage(t)}static setCenter(e,t){e.setCenter(t)}static setZoom(e,t){e.setZoom(t)}static destroy(e){e.destroy()}addMarker(e){return he(this.maplibre,this.map,e)}init(e){this.map=e,this.camera=new v(e)}getCamera(){return this.camera}getMap(){return this.map}setStyle(e){if(this.options.theme=e,this.presetIsExplicit)return;let t=this.resolvePlatformStyle(T(this.styleFamily,e));t&&(this.refreshLayersOnStyleChange(),this.map.setStyle(t),this.updateLogoColor(e))}resolvePlatformStyle(e){let t=this.maps3dCtor;if(t)try{return t.mapOptions?t.mapOptions({base:this.gramBase,apiKey:M(),style:e}).style:t.styleUrl?.(e,this.gramBase)}catch(r){console.error(`[MahalMap SDK] Maps3D rejected the style "${e}"`,r);return}}refreshLayersOnStyleChange(){let e=this.map;if(typeof e.on!="function"||typeof e.off!="function")return;this.styleChangeHandler&&e.off("styledata",this.styleChangeHandler);let t=()=>{typeof e.isStyleLoaded=="function"&&!e.isStyleLoaded()||(e.off?.("styledata",t),this.styleChangeHandler=void 0,this.maps3dLayer?.refreshLayers?.())};this.styleChangeHandler=t,e.on("styledata",t)}setLanguage(e){this.language=l.normalizeLanguage(e),this.options.lang=this.language}getMaps3DLayer(){return this.maps3dLayer}toggle3DBuildings(e){if(!(!this.maps3dLayer&&e&&(this.maps3dCtor=this.maps3dCtor||l.getMaps3DCtor(),!this.maps3dCtor))){if(this.buildingsEnabled=e,!this.maps3dLayer){if(!e)return;this.maps3dLayer=this.createMaps3DLayer(M()||void 0),this.attachMaps3DLayer(this.maps3dLayer);return}this.applyMaps3DBuildingMode(e)}}whenMaps3DReady(){return this.maps3dReady||Promise.resolve(void 0)}setLayer(e,t,r){return e===de&&(this.buildingsEnabled=t),this.maps3dLayer?.setLayer?.(e,t,r)??!1}getLayerState(e){return this.maps3dLayer?.layer?.(e)??null}getLayers(){return this.maps3dLayer?.layers?.()??[]}onLayers(e){let t={callback:e,unsubscribe:this.maps3dLayer?.onLayers?.(e)};return this.pendingLayerSubscribers.add(t),()=>{this.pendingLayerSubscribers.delete(t)&&t.unsubscribe?.()}}refreshLayers(){this.maps3dLayer?.refreshLayers?.()}getIndoorLevels(){return this.maps3dLayer?.indoorLevels??[]}setIndoorLevel(e){this.maps3dLayer?.setIndoorLevel?.(e)}refreshIndoor(){this.maps3dLayer?.refreshIndoor?.()}showPlace(e,t,r,a){this.maps3dLayer?.showPlace?.(e,t,r,a)}onBuildingClick(e){this.pendingBuildingClick=e,this.maps3dLayer?.onBuildingClick?.(e)}selectBuilding(e,t){return this.maps3dLayer?.selectBuilding?.(e,t)??!1}clearSelection(){this.maps3dLayer?.clearSelection?.()}selectedBuilding(){return this.maps3dLayer?.selectedBuilding?.()??null}setSelectionStyle(e){this.pendingSelectionStyle=e,this.maps3dLayer?.setSelectionStyle?.(e)}onRoadClick(e){this.pendingRoadClick=e,this.maps3dLayer?.onRoadClick?.(e)}roadAt(e,t){return this.maps3dLayer?.roadAt?.(e,t)??null}get roadsNamed(){return this.maps3dLayer?.roadsNamed??!1}onParkingHover(e){this.maps3dLayer?.onParkingHover?.(e)}setParkingHoverStyle(e){this.maps3dLayer?.setParkingHoverStyle?.(e)}setParkingHoverEnabled(e){this.maps3dLayer?.setParkingHoverEnabled?.(e)}get parkingHoverEnabled(){return this.maps3dLayer?.parkingHoverEnabled??!1}hoverParking(e){return this.maps3dLayer?.hoverParking?.(e)??!1}hoveredParking(){return this.maps3dLayer?.hoveredParking?.()??null}onParkingClick(e){this.maps3dLayer?.onParkingClick?.(e)}parkingAt(e,t){return this.maps3dLayer?.parkingAt?.(e,t)??null}onBuildingHover(e){this.pendingBuildingHover=e,this.maps3dLayer?.onBuildingHover?.(e)}setHoverEnabled(e){this.pendingHoverEnabled=e,this.maps3dLayer?.setHoverEnabled?.(e)}get hoverEnabled(){return this.maps3dLayer?.hoverEnabled??!1}setHoverStyle(e){this.pendingHoverStyle=e,this.maps3dLayer?.setHoverStyle?.(e)}hoverBuilding(e){return this.maps3dLayer?.hoverBuilding?.(e)??!1}hoveredBuilding(){return this.maps3dLayer?.hoveredBuilding?.()??null}createMaps3DLayer(e){let t={...this.options.maps3d,apiKey:e,base:this.gramBase};return this.maps3dCtor.enhance?this.maps3dCtor.enhance(this.map,t):new this.maps3dCtor(t)}applyPendingSubscriptions(e){this.pendingBuildingClick&&e.onBuildingClick?.(this.pendingBuildingClick),this.pendingRoadClick&&e.onRoadClick?.(this.pendingRoadClick),this.pendingSelectionStyle&&e.setSelectionStyle?.(this.pendingSelectionStyle),this.pendingBuildingHover!==void 0&&e.onBuildingHover?.(this.pendingBuildingHover),this.pendingHoverStyle&&e.setHoverStyle?.(this.pendingHoverStyle),this.pendingHoverEnabled!==void 0&&e.setHoverEnabled?.(this.pendingHoverEnabled);for(let t of this.pendingLayerSubscribers)t.unsubscribe=e.onLayers?.(t.callback)}attachMaps3DLayer(e){this.applyPendingSubscriptions(e);let t;try{t=e.ready??e.attach(this.map)}catch(r){t=Promise.reject(r)}this.maps3dReady=Promise.resolve(t).then(()=>{if(this.maps3dLayer!==e){l.teardownMaps3DLayer(e);return}return this.applyMaps3DBuildingMode(this.buildingsEnabled),e}).catch(r=>{l.teardownMaps3DLayer(e),this.maps3dLayer===e&&(this.maps3dLayer=void 0,this.buildingsEnabled=!1,console.error("[MahalMap SDK] Failed to attach Maps3D layer",r))})}static teardownMaps3DLayer(e){l.disposedMaps3DLayers.has(e)||(l.disposedMaps3DLayers.add(e),e.destroy?e.destroy():e.remove?.())}watchWorkerHealth(){let e=this.options.workerCheck;if(e===!1||typeof setTimeout!="function")return;let t=typeof e=="number"?e:l.WORKER_CHECK_DELAY;this.workerCheckTimer=setTimeout(()=>{this.workerCheckTimer=void 0,this.reportBrokenWorker()},t)}reportBrokenWorker(){if(typeof document<"u"&&document.hidden)return;let e=this.map;if(!(!e||typeof e.getStyle!="function"||typeof e.isStyleLoaded!="function"||typeof e.queryRenderedFeatures!="function")){try{let t=e.getStyle()?.sources??{};if(!Object.values(t).some(a=>a?.type==="vector"||a?.type==="geojson")||e.isStyleLoaded()||e.queryRenderedFeatures().length>0)return}catch{return}console.warn(`[MahalMap SDK] \u041A\u0430\u0440\u0442\u0430 \u043F\u0443\u0441\u0442\u0430: \u043D\u0438 \u043E\u0434\u0438\u043D \u0432\u0435\u043A\u0442\u043E\u0440\u043D\u044B\u0439 \u0442\u0430\u0439\u043B \u043D\u0435 \u0440\u0430\u0437\u043E\u0431\u0440\u0430\u043D \u2014 \u043F\u043E\u0445\u043E\u0436\u0435, \u043D\u0435 \u0437\u0430\u043F\u0443\u0441\u0442\u0438\u043B\u0441\u044F \u0432\u0435\u0431-\u0432\u043E\u0440\u043A\u0435\u0440 MapLibre.
70
+ </svg>`;var j=class{constructor(e){this.props=e;this.element=this.createElement()}createElement(){let e=document.createElement("div");e.style.cursor="pointer";let t=this.props.svg?this.applyColorToCustomSvg(this.props.svg):ge(this.props.color??"#278960",{innerSvg:this.props.innerSvg,innerUrl:this.props.innerUrl});return e.innerHTML=t,e}applyColorToCustomSvg(e){return this.props.color?e.replace(/fill="[^"]*"/g,`fill="${this.props.color}"`):e}getElement(){return this.element}getCoordinates(){return this.props.coordinates}isDraggable(){return!!this.props.draggable}getAnchor(){return this.props.anchor||"center"}};function me(a,e,t){return new a.Marker({element:t.getElement(),draggable:t.isDraggable?.()??!1,anchor:t.getAnchor?.()??"center"}).setLngLat(t.getCoordinates()).addTo(e)}var Ue={dark:"#ffffff",light:"#19191a"},ye="buildings",Ve=16,We=new Set(["onBuildingHover","onParkingHover","onParkingClick"]),l=class l{constructor(){this.isReady=!1;this.readyCallbacks=[];this.language="tj";this.instanceKey="";this.gramBase=T;this.styleFamily="default";this.presetIsExplicit=!1;this.platformStyle=!1;this.buildingsEnabled=!1;this.subscriptions=new Map;this.pendingLayerSubscribers=new Set}static getInstanceKey(e){return typeof e.container=="string"&&e.container?e.container:"map"}static normalizeLanguage(e){return e==="ru"?"ru":"tj"}static setDefaultLanguage(e){l.defaultLanguage=l.normalizeLanguage(e)}static getFallbackStyle(){return ee(Q,l.getMapToken())}static getMapToken(){let e=M();if(!e)throw new Error("[MahalMap SDK] Map API key is required. Call keyUtils.saveKey() before creating the map or pass apikey in the SDK script URL.");return e}static getMaps3DCtor(e){if(e)return e;if(typeof window>"u")return;let t=window.Maps3D;return typeof t=="function"?t:t?.Maps3D}static async ensureJSApiSubscription(e){if(e)return;let t=M();if(!t)return;let r;try{r=await C(t)}catch(i){console.warn("[MahalMap SDK] JSApi subscription check failed, continuing without it:",i);return}if(!r.success)throw new Error(`[MahalMap SDK] JSApi subscription is not active for this key: ${r.message}`)}static async createAsync(e,t,r){return await l.ensureJSApiSubscription(l.getMaps3DCtor(r)),l.create(e,t,r)}static resolveStyleName(e,t,r){return e.style||e.preset||R(t,r)}static buildPlatformMapOptions(e,t,r,i,s){try{return e.mapOptions?e.mapOptions({base:t,apiKey:r,style:i,antialias:s}):{style:e.styleUrl?e.styleUrl(i,t):l.requireAbsoluteStyle(i),transformRequest:e.transformRequest({base:t,apiKey:r}),...s?{canvasContextAttributes:{antialias:!0}}:{}}}catch(n){throw new Error(`[MahalMap SDK] Maps3D rejected the style "${i}": ${n instanceof Error?n.message:String(n)}`)}}static requireAbsoluteStyle(e){if(/^https?:/i.test(e))return e;throw new Error("this Maps3D build has no styleUrl() \u2014 pass options.style as a full URL or upgrade @grammaps/maps3d-web to >=0.5.0")}static create(e,t,r){let i=typeof window<"u"?window.maplibregl:void 0,s=t||i;if(!s)throw new Error("[MahalMap SDK] MapLibre GL was not found. Pass it as the second argument or include it through a script.");let n=l.normalizeLanguage(e.lang||l.defaultLanguage),p=e.theme==="dark"?"dark":"light",o=new l,h=l.getInstanceKey(e);o.options=e,o.language=n,o.instanceKey=h,o.maplibre=s;let u=l.getMapToken(),d=l.getMaps3DCtor(r);o.gramBase=(e.base||T).replace(/\/+$/,""),o.styleFamily=e.family||"default",o.presetIsExplicit=!!(e.style||e.preset),o.maps3dCtor=d;let c=e.enable3D!==!1&&!!d;o.buildingsEnabled=c&&e.maps3d?.buildings!==!1,e.enable3D!==!1&&!d&&console.warn("[MahalMap SDK] Maps3D was not found \u2014 falling back to the plain vector style without 3D. Pass Maps3D as the third argument to create() or include it through a script (window.Maps3D).");let m=e.antialias!==void 0?e.antialias:c,g=d?l.buildPlatformMapOptions(d,o.gramBase,u,l.resolveStyleName(e,o.styleFamily,p),m):void 0,S=c?58:0;return o.platformStyle=!!g,o.map=new s.Map({container:e.container||"map",style:g?g.style:e.style||l.getFallbackStyle(),center:e.center||[69.624024,40.279687],zoom:e.zoom!==void 0?e.zoom:5,attributionControl:!1,pitch:e.pitch!==void 0?e.pitch:S,...e.bearing!==void 0?{bearing:e.bearing}:{},...g?{transformRequest:g.transformRequest,...g.canvasContextAttributes?{canvasContextAttributes:g.canvasContextAttributes}:{}}:{}}),c&&(o.maps3dLayer=o.createMaps3DLayer(u),o.attachMaps3DLayer(o.maps3dLayer)),o.watchWorkerHealth(),o.addLogo(p),o.map.on("load",()=>{o.isReady=!0,o.camera=new v(o.map),o.readyCallbacks.forEach(ke=>ke(o.map)),o.readyCallbacks=[]}),l.instances.set(h,o),o}static onReady(e,t){if(!l.instances.has(e)){let i=setInterval(()=>{l.instances.has(e)&&(clearInterval(i),l.onReady(e,t))},50);return}let r=l.getInstance(e);r.isReady?t(r.map):r.readyCallbacks.push(t)}static getInstance(e){let t=l.instances.get(e);if(!t)throw new Error("[MahalMap SDK] Map instance is not created");return t}static hasInstance(e){return l.instances.has(e)}static removeInstance(e){return l.instances.delete(e)}static addMarker(e,t){return e.addMarker(t)}static getCamera(e){return e.getCamera()}static getMap(e){return e.getMap()}static setStyle(e,t){e.setStyle(t)}static getMaps3DLayer(e){return e.getMaps3DLayer()}static whenMaps3DReady(e){return e.whenMaps3DReady()}static toggle3DBuildings(e,t){e.toggle3DBuildings(t)}static setLayer(e,t,r,i){return e.setLayer(t,r,i)}static getLayerState(e,t){return e.getLayerState(t)}static getLayers(e){return e.getLayers()}static onLayers(e,t){return e.onLayers(t)}static refreshLayers(e){e.refreshLayers()}static getIndoorLevels(e){return e.getIndoorLevels()}static setIndoorLevel(e,t){e.setIndoorLevel(t)}static refreshIndoor(e){e.refreshIndoor()}static showPlace(e,t,r,i,s){e.showPlace(t,r,i,s)}static onBuildingClick(e,t){return e.onBuildingClick(t)}static selectBuilding(e,t,r){return e.selectBuilding(t,r)}static clearSelection(e){e.clearSelection()}static selectedBuilding(e){return e.selectedBuilding()}static selectedBuildingKind(e){return e.selectedBuildingKind()}static getBuildingsMinZoom(e){return e.getBuildingsMinZoom()}static setSelectionStyle(e,t){e.setSelectionStyle(t)}static onRoadClick(e,t){return e.onRoadClick(t)}static roadAt(e,t,r){return e.roadAt(t,r)}static onParkingHover(e,t){return e.onParkingHover(t)}static setParkingHoverStyle(e,t){e.setParkingHoverStyle(t)}static setParkingHoverEnabled(e,t){e.setParkingHoverEnabled(t)}static hoverParking(e,t){return e.hoverParking(t)}static hoveredParking(e){return e.hoveredParking()}static onParkingClick(e,t){return e.onParkingClick(t)}static parkingAt(e,t,r){return e.parkingAt(t,r)}static onBuildingHover(e,t){return e.onBuildingHover(t)}static setHoverEnabled(e,t){e.setHoverEnabled(t)}static setHoverStyle(e,t){e.setHoverStyle(t)}static hoverBuilding(e,t){return e.hoverBuilding(t)}static hoveredBuilding(e){return e.hoveredBuilding()}static setLanguage(e,t){e.setLanguage(t)}static setCenter(e,t){e.setCenter(t)}static setZoom(e,t){e.setZoom(t)}static destroy(e){e.destroy()}addMarker(e){return me(this.maplibre,this.map,e)}init(e){this.map=e,this.camera=new v(e)}getCamera(){return this.camera}getMap(){return this.map}setStyle(e){if(this.options.theme=e,this.presetIsExplicit)return;let t=this.resolvePlatformStyle(R(this.styleFamily,e));t&&(this.refreshLayersOnStyleChange(),this.map.setStyle(t),this.updateLogoColor(e))}resolvePlatformStyle(e){let t=this.maps3dCtor;if(t)try{return t.mapOptions?t.mapOptions({base:this.gramBase,apiKey:M(),style:e}).style:t.styleUrl?.(e,this.gramBase)}catch(r){console.error(`[MahalMap SDK] Maps3D rejected the style "${e}"`,r);return}}refreshLayersOnStyleChange(){let e=this.map;if(typeof e.on!="function"||typeof e.off!="function")return;this.styleChangeHandler&&e.off("styledata",this.styleChangeHandler);let t=()=>{typeof e.isStyleLoaded=="function"&&!e.isStyleLoaded()||(e.off?.("styledata",t),this.styleChangeHandler=void 0,this.maps3dLayer?.refreshLayers?.())};this.styleChangeHandler=t,e.on("styledata",t)}setLanguage(e){this.language=l.normalizeLanguage(e),this.options.lang=this.language}getMaps3DLayer(){return this.maps3dLayer}toggle3DBuildings(e){if(!this.maps3dLayer&&e&&!this.platformStyle){console.warn("[MahalMap SDK] The map was created without Maps3D \u2014 recreate it with Maps3D to enable 3D.");return}if(this.buildingsEnabled=e,!this.maps3dLayer){if(!e)return;this.maps3dLayer=this.createMaps3DLayer(M()||void 0),this.attachMaps3DLayer(this.maps3dLayer);return}this.applyMaps3DBuildingMode(e)}whenMaps3DReady(){return this.maps3dReady||Promise.resolve(void 0)}setLayer(e,t,r){return e===ye&&(this.buildingsEnabled=t),this.maps3dLayer?.setLayer?.(e,t,r)??!1}getLayerState(e){return this.maps3dLayer?.layer?.(e)??null}getLayers(){return this.maps3dLayer?.layers?.()??[]}onLayers(e){let t={callback:e,unsubscribe:this.maps3dLayer?.onLayers?.(e)};return this.pendingLayerSubscribers.add(t),()=>{this.pendingLayerSubscribers.delete(t)&&t.unsubscribe?.()}}refreshLayers(){this.maps3dLayer?.refreshLayers?.()}getIndoorLevels(){let e=this.maps3dLayer?.layer?.("indoor")?.params.levels;return Array.isArray(e)?e:this.maps3dLayer?.indoorLevels??[]}setIndoorLevel(e){this.maps3dLayer?.setIndoorLevel?.(e)}refreshIndoor(){this.maps3dLayer?.refreshIndoor?.()}showPlace(e,t,r,i){this.maps3dLayer?.showPlace?.(e,t,r,i)}onBuildingClick(e){return this.subscribe("onBuildingClick",e)}selectBuilding(e,t){return this.maps3dLayer?.selectBuilding?.(e,t)??!1}clearSelection(){this.maps3dLayer?.clearSelection?.()}selectedBuilding(){return this.maps3dLayer?.selectedBuilding?.()??null}selectedBuildingKind(){return this.maps3dLayer?.selectedBuildingKind?.()??null}setSelectionStyle(e){this.pendingSelectionStyle=e,this.maps3dLayer?.setSelectionStyle?.(e)}onRoadClick(e){return this.subscribe("onRoadClick",e)}roadAt(e,t){return this.maps3dLayer?.roadAt?.(e,t)??null}get roadsNamed(){return this.maps3dLayer?.roadsNamed??!1}onParkingHover(e){return this.subscribe("onParkingHover",e)}setParkingHoverStyle(e){this.maps3dLayer?.setParkingHoverStyle?.(e)}setParkingHoverEnabled(e){this.maps3dLayer?.setParkingHoverEnabled?.(e)}get parkingHoverEnabled(){return this.maps3dLayer?.parkingHoverEnabled??!1}hoverParking(e){return this.maps3dLayer?.hoverParking?.(e)??!1}hoveredParking(){return this.maps3dLayer?.hoveredParking?.()??null}onParkingClick(e){return this.subscribe("onParkingClick",e)}parkingAt(e,t){return this.maps3dLayer?.parkingAt?.(e,t)??null}onBuildingHover(e){return this.subscribe("onBuildingHover",e)}setHoverEnabled(e){this.pendingHoverEnabled=e,this.maps3dLayer?.setHoverEnabled?.(e)}get hoverEnabled(){return this.maps3dLayer?.hoverEnabled??!1}setHoverStyle(e){this.pendingHoverStyle=e,this.maps3dLayer?.setHoverStyle?.(e)}hoverBuilding(e){return this.maps3dLayer?.hoverBuilding?.(e)??!1}hoveredBuilding(){return this.maps3dLayer?.hoveredBuilding?.()??null}getBuildingsMinZoom(){return this.options.maps3d?.minZoom??Ve}subscribe(e,t){let r=this.subscriptions.get(e),i=this.maps3dLayer;if(!t)return this.subscriptions.delete(e),i&&this.unbindSubscription(i,e,r),()=>{};let s={callback:t};return this.subscriptions.set(e,s),i&&this.bindSubscription(i,e,s),()=>{this.subscriptions.get(e)===s&&(this.subscriptions.delete(e),this.maps3dLayer&&this.unbindSubscription(this.maps3dLayer,e,s))}}bindSubscription(e,t,r){let s=e[t]?.call(e,r.callback);r.unsubscribe=typeof s=="function"?s:void 0}unbindSubscription(e,t,r){if(r?.unsubscribe){let n=r.unsubscribe;r.unsubscribe=void 0,n();return}let i=e[t],s=We.has(t)||typeof e.selectedBuildingKind=="function";i?.call(e,s?null:()=>{})}createMaps3DLayer(e){let t={...this.options.maps3d,apiKey:e,base:this.gramBase};return this.maps3dCtor.enhance?this.maps3dCtor.enhance(this.map,t):new this.maps3dCtor(t)}applyPendingSubscriptions(e){for(let[t,r]of this.subscriptions)this.bindSubscription(e,t,r);this.pendingSelectionStyle&&e.setSelectionStyle?.(this.pendingSelectionStyle),this.pendingHoverStyle&&e.setHoverStyle?.(this.pendingHoverStyle),this.pendingHoverEnabled!==void 0&&e.setHoverEnabled?.(this.pendingHoverEnabled);for(let t of this.pendingLayerSubscribers)t.unsubscribe=e.onLayers?.(t.callback)}attachMaps3DLayer(e){this.applyPendingSubscriptions(e);let t;try{t=e.ready??e.attach(this.map)}catch(r){t=Promise.reject(r)}this.maps3dReady=Promise.resolve(t).then(()=>{if(this.maps3dLayer!==e){l.teardownMaps3DLayer(e);return}return this.applyMaps3DBuildingMode(this.buildingsEnabled),e}).catch(r=>{l.teardownMaps3DLayer(e),this.maps3dLayer===e&&(this.maps3dLayer=void 0,this.buildingsEnabled=!1,console.error("[MahalMap SDK] Failed to attach Maps3D layer",r))})}static teardownMaps3DLayer(e){l.disposedMaps3DLayers.has(e)||(l.disposedMaps3DLayers.add(e),e.destroy?e.destroy():e.remove?.())}watchWorkerHealth(){let e=this.options.workerCheck;if(e===!1||typeof setTimeout!="function")return;let t=typeof e=="number"?e:l.WORKER_CHECK_DELAY;this.workerCheckTimer=setTimeout(()=>{this.workerCheckTimer=void 0,this.reportBrokenWorker()},t)}reportBrokenWorker(){if(typeof document<"u"&&document.hidden)return;let e=this.map;if(!(!e||typeof e.getStyle!="function"||typeof e.isStyleLoaded!="function"||typeof e.queryRenderedFeatures!="function")){try{let t=e.getStyle()?.sources??{};if(!Object.values(t).some(i=>i?.type==="vector"||i?.type==="geojson")||e.isStyleLoaded()||e.queryRenderedFeatures().length>0)return}catch{return}console.warn(`[MahalMap SDK] \u041A\u0430\u0440\u0442\u0430 \u043F\u0443\u0441\u0442\u0430: \u043D\u0438 \u043E\u0434\u0438\u043D \u0432\u0435\u043A\u0442\u043E\u0440\u043D\u044B\u0439 \u0442\u0430\u0439\u043B \u043D\u0435 \u0440\u0430\u0437\u043E\u0431\u0440\u0430\u043D \u2014 \u043F\u043E\u0445\u043E\u0436\u0435, \u043D\u0435 \u0437\u0430\u043F\u0443\u0441\u0442\u0438\u043B\u0441\u044F \u0432\u0435\u0431-\u0432\u043E\u0440\u043A\u0435\u0440 MapLibre.
71
71
  \u041E\u0431\u044B\u0447\u043D\u043E \u0432\u0438\u043D\u043E\u0432\u0430\u0442 \u0441\u0431\u043E\u0440\u0449\u0438\u043A: \u043E\u043D \u043D\u0435 \u043F\u0435\u0440\u0435\u043D\u043E\u0441\u0438\u0442 \u0444\u0430\u0439\u043B \u0432\u043E\u0440\u043A\u0435\u0440\u0430, \u0438 \u0432\u043C\u0435\u0441\u0442\u043E \u0441\u043A\u0440\u0438\u043F\u0442\u0430 \u0441\u0435\u0440\u0432\u0435\u0440 \u043E\u0442\u0434\u0430\u0451\u0442 HTML.
72
72
  \u0420\u0435\u0448\u0435\u043D\u0438\u044F:
73
73
  1) \u0432\u0437\u044F\u0442\u044C \u0431\u0438\u0431\u043B\u0438\u043E\u0442\u0435\u043A\u0443 \u0443 \u043F\u043B\u0430\u0442\u0444\u043E\u0440\u043C\u044B: const maplibregl = await Maps3D.maplibre({ base });
74
74
  2) \u043E\u0441\u0442\u0430\u0432\u0438\u0442\u044C \u0441\u0432\u043E\u044E \u0441\u0431\u043E\u0440\u043A\u0443, \u043D\u043E \u0438\u0441\u043A\u043B\u044E\u0447\u0438\u0442\u044C maplibre-gl \u0438\u0437 \u043E\u043F\u0442\u0438\u043C\u0438\u0437\u0430\u0446\u0438\u0438 (vite: optimizeDeps.exclude: ["maplibre-gl"]) \u0438 \u0443\u043A\u0430\u0437\u0430\u0442\u044C \u0430\u0434\u0440\u0435\u0441 \u0432\u043E\u0440\u043A\u0435\u0440\u0430: maplibregl.setWorkerUrl('/maplibre-gl-worker.mjs').
75
- \u041F\u0440\u043E\u0432\u0435\u0440\u043A\u0430 \u043E\u0442\u043A\u043B\u044E\u0447\u0430\u0435\u0442\u0441\u044F \u043E\u043F\u0446\u0438\u0435\u0439 workerCheck: false.`)}}applyMaps3DBuildingMode(e){let t=this.maps3dLayer;t&&(t.setLayer?.(de,e)||(t.setBuildingsEnabled?.(e),t.buildings?.setWindows?.(e)))}setCenter(e){this.map.setCenter(e)}setZoom(e){this.map.setZoom(e)}destroy(){this.workerCheckTimer!==void 0&&(clearTimeout(this.workerCheckTimer),this.workerCheckTimer=void 0),this.styleChangeHandler&&(this.map.off?.("styledata",this.styleChangeHandler),this.styleChangeHandler=void 0),this.maps3dLayer&&l.teardownMaps3DLayer(this.maps3dLayer),this.maps3dLayer=void 0,this.maps3dReady=void 0,this.logoObserver?.disconnect(),this.logoObserver=void 0,this.logoHost?.remove(),this.logoHost=void 0,this.logoShadow=void 0,this.map.remove(),l.instances.delete(this.instanceKey)}addLogo(e){let t=this.map.getContainer(),r=document.createElement("div"),a=r.attachShadow({mode:"closed"});r.setAttribute("role","img"),r.setAttribute("aria-label","Mahal"),r.dataset.mahal=Math.random().toString(36).slice(2),this.logoHost=r,this.logoShadow=a,this.applyLogoHostStyles(),this.renderLogo(e),t.appendChild(r),this.observeLogo(t)}updateLogoColor(e){this.logoShadow&&this.renderLogo(e)}renderLogo(e){this.logoShadow&&(this.logoShadow.innerHTML=`
75
+ \u041F\u0440\u043E\u0432\u0435\u0440\u043A\u0430 \u043E\u0442\u043A\u043B\u044E\u0447\u0430\u0435\u0442\u0441\u044F \u043E\u043F\u0446\u0438\u0435\u0439 workerCheck: false.`)}}applyMaps3DBuildingMode(e){let t=this.maps3dLayer;t&&(t.setLayer?.(ye,e)||(t.setBuildingsEnabled?.(e),t.buildings?.setWindows?.(e)))}setCenter(e){this.map.setCenter(e)}setZoom(e){this.map.setZoom(e)}destroy(){this.workerCheckTimer!==void 0&&(clearTimeout(this.workerCheckTimer),this.workerCheckTimer=void 0),this.styleChangeHandler&&(this.map.off?.("styledata",this.styleChangeHandler),this.styleChangeHandler=void 0),this.maps3dLayer&&l.teardownMaps3DLayer(this.maps3dLayer),this.maps3dLayer=void 0,this.maps3dReady=void 0,this.logoObserver?.disconnect(),this.logoObserver=void 0,this.logoHost?.remove(),this.logoHost=void 0,this.logoShadow=void 0,this.map.remove(),l.instances.delete(this.instanceKey)}addLogo(e){let t=this.map.getContainer(),r=document.createElement("div"),i=r.attachShadow({mode:"closed"});r.setAttribute("role","img"),r.setAttribute("aria-label","Mahal"),r.dataset.mahal=Math.random().toString(36).slice(2),this.logoHost=r,this.logoShadow=i,this.applyLogoHostStyles(),this.renderLogo(e),t.appendChild(r),this.observeLogo(t)}updateLogoColor(e){this.logoShadow&&this.renderLogo(e)}renderLogo(e){this.logoShadow&&(this.logoShadow.innerHTML=`
76
76
  <style>
77
77
  :host {
78
78
  all: initial;
@@ -92,7 +92,7 @@ var Se=Object.defineProperty;var B=(i,e)=>{for(var t in e)Se(i,t,{get:e[t],enume
92
92
  }
93
93
  </style>
94
94
  <span class="logo-wrap" aria-hidden="true">
95
- ${this.getLogoSvg(Je[e])}
95
+ ${this.getLogoSvg(Ue[e])}
96
96
  </span>
97
97
  `)}applyLogoHostStyles(){if(!this.logoHost)return;let e=this.logoHost.style;e.setProperty("position","absolute","important"),e.setProperty("right","10px","important"),e.setProperty("bottom","10px","important"),e.setProperty("z-index","1","important"),e.setProperty("display","block","important"),e.setProperty("visibility","visible","important"),e.setProperty("opacity","1","important"),e.setProperty("pointer-events","none","important"),e.setProperty("line-height","0","important"),e.setProperty("width","80px","important"),e.setProperty("height","18.45px","important")}observeLogo(e){this.logoHost&&(this.logoObserver?.disconnect(),this.logoObserver=new MutationObserver(()=>{this.logoHost&&(this.applyLogoHostStyles(),e.contains(this.logoHost)||e.appendChild(this.logoHost))}),this.logoObserver.observe(e,{childList:!0}),this.logoObserver.observe(this.logoHost,{attributes:!0,attributeFilter:["class","style","hidden"]}))}getLogoSvg(e){return`
98
98
  <svg class="logo" width="80" viewBox="0 0 143 33" fill="none" xmlns="http://www.w3.org/2000/svg" style="opacity: 0.95;">
@@ -115,4 +115,4 @@ var Se=Object.defineProperty;var B=(i,e)=>{for(var t in e)Se(i,t,{get:e[t],enume
115
115
  </clipPath>
116
116
  </defs>
117
117
  </svg>
118
- `}};l.instances=new Map,l.defaultLanguage="tj",l.disposedMaps3DLayers=new WeakSet,l.WORKER_CHECK_DELAY=8e3;var $=l;var ge={};B(ge,{CheckJSApi:()=>C,Router:()=>ce,Search:()=>se,SearchByLocation:()=>oe,SearchPoi:()=>ne,clearKey:()=>ke,getApiKey:()=>M,saveKey:()=>Ie});var ue=async(i,e)=>{try{let t=[];return i.forEach(a=>{t.push({lng:a[0],lat:a[1]})}),(await y.post("services/getRoutes",{points:t,token:e})).data}catch(t){throw console.error(t),t}};async function ce(i,e,t){if(!t)throw new Error("[MahalMap SDK] Router token is required");try{let r=await ue(i,t);return r?.data?r.data.map(s=>{let n={...s};return n.route?.routes?.length&&(n.route.routes=n.route.routes.map(p=>({...p,geometry:e==="geojson"&&typeof p.geometry=="string"?O(p.geometry):p.geometry}))),n}):r}catch(r){throw r}}var Le={};B(Le,{MeasureTool:()=>E,haversineDistance:()=>V,lineLength:()=>k,midpoint:()=>q,polygonArea:()=>K,polygonCentroid:()=>W});var J=63710088e-1;function f(i){return i*Math.PI/180}function j(i){return((i+180)%360+360)%360-180}function U(i){return((i+180)%360+360)%360-180}function V(i,e){let[t,r]=i,[a,s]=e,n=f(r),p=f(s),o=f(s-r),h=f(a-t),d=Math.sin(o/2),u=Math.sin(h/2),c=d*d+Math.cos(n)*Math.cos(p)*u*u,m=2*Math.atan2(Math.sqrt(c),Math.sqrt(1-c));return J*m}function k(i){let e=0;for(let t=1;t<i.length;t+=1)e+=V(i[t-1],i[t]);return e}function K(i){if(i.length<3)return 0;let e=0;for(let t=0;t<i.length;t+=1){let r=i[t],a=i[(t+1)%i.length],s=f(j(a[0]-r[0])),n=f(r[1]),p=f(a[1]);e+=s*(2+Math.sin(n)+Math.sin(p))}return Math.abs(e*J*J/2)}function me(i){let e=i.reduce((t,r)=>[t[0]+r[0],t[1]+r[1]],[0,0]);return[U(e[0]/i.length),e[1]/i.length]}function W(i){if(i.length===0)return[0,0];if(i.length<3)return me(i);let e=i[0]?.[0]??0,t=i.map(([h,d])=>[e+j(h-e),d]),r=0,a=0,s=0;for(let h=0;h<t.length;h+=1){let[d,u]=t[h],[c,m]=t[(h+1)%t.length],g=d*m-c*u;r+=g,a+=(d+c)*g,s+=(u+m)*g}let n=r/2;if(Math.abs(n)<1e-12)return me(t);let p=a/(6*n),o=s/(6*n);return[U(p),o]}function q(i){if(i.length===0)return[0,0];if(i.length===1)return i[0];let e=[],t=0;for(let s=1;s<i.length;s+=1){let n=V(i[s-1],i[s]);e.push(n),t+=n}if(t===0)return i[0];let r=t/2,a=0;for(let s=1;s<i.length;s+=1){let n=e[s-1];if(a+n>=r){let p=n===0?0:(r-a)/n,o=i[s-1],h=i[s],d=U(o[0]+j(h[0]-o[0])*p),u=o[1]+(h[1]-o[1])*p;return[d,u]}a+=n}return i[i.length-1]}var je=new Set(["svg","g","path","circle","ellipse","rect","line","polyline","polygon"]),Ue=new Set(["xmlns","viewbox","width","height","fill","fill-rule","fill-opacity","stroke","stroke-width","stroke-linecap","stroke-linejoin","stroke-dasharray","stroke-opacity","opacity","d","cx","cy","r","rx","ry","x","y","x1","y1","x2","y2","points","transform"]),Ve=new Set(["fill","stroke"]);function Ke(i,e){let t=e.trim().toLowerCase();return!(t.includes("javascript:")||t.includes("data:")||t.includes("expression(")||Ve.has(i)&&t.includes("url("))}function ye(i){return je.has(i.tagName.toLowerCase())?(Array.from(i.attributes).forEach(e=>{let t=e.name.toLowerCase();(!Ue.has(t)||!Ke(t,e.value))&&i.removeAttribute(e.name)}),Array.from(i.children).forEach(e=>{ye(e)||e.remove()}),!0):!1}function We(i){if(typeof DOMParser>"u")return null;try{let e=new DOMParser().parseFromString(i,"image/svg+xml"),t=e.documentElement;return!t||t.tagName.toLowerCase()!=="svg"||e.querySelector("parsererror")||!ye(t)?null:new XMLSerializer().serializeToString(t)}catch{return null}}function L(i,e){return i?We(i)??e:e}var fe='<svg width="16" height="16" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg"><path d="M4 7h16M9 7V4h6v3M6 7l1 13h10l1-13" stroke="currentColor" stroke-width="1.6" stroke-linecap="round" stroke-linejoin="round"/></svg>',qe='<svg width="14" height="14" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg"><path d="M4 4l16 16M20 4L4 20" stroke="currentColor" stroke-width="1.8" stroke-linecap="round"/></svg>',ze='<svg width="16" height="16" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg"><path d="M4 12l6 6 10-12" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/></svg>',w=class{constructor(e,t,r,a){this.wrapper=document.createElement("div"),this.valueEl=document.createElement("span"),this.trashButton=document.createElement("button"),this.closeButton=document.createElement("button"),this.checkButton=document.createElement("button"),this.applyWrapperStyles(t),this.applyValueStyles(t),this.applyButtonStyles(this.trashButton,t),this.applyButtonStyles(this.closeButton,t),this.applyButtonStyles(this.checkButton,t),this.trashButton.type="button",this.closeButton.type="button",this.checkButton.type="button",this.trashButton.innerHTML=L(r.trash,fe),this.closeButton.innerHTML=L(r.close,qe),this.checkButton.innerHTML=L(r.check,ze);let s=n=>{n.preventDefault(),n.stopPropagation()};this.wrapper.addEventListener("mousedown",s),this.wrapper.addEventListener("dblclick",s),this.wrapper.addEventListener("contextmenu",s),this.trashButton.addEventListener("click",n=>{s(n),a.onRemove()}),this.closeButton.addEventListener("click",n=>{s(n),a.onClose()}),this.checkButton.addEventListener("click",n=>{s(n),a.onCheck()}),this.wrapper.appendChild(this.valueEl),this.wrapper.appendChild(this.checkButton),this.wrapper.appendChild(this.trashButton),this.wrapper.appendChild(this.closeButton),this.wrapper.style.display="none",e.appendChild(this.wrapper)}applyStyle(e){let t=this.wrapper.style.display;this.applyWrapperStyles(e),this.applyValueStyles(e),this.applyButtonStyles(this.trashButton,e),this.applyButtonStyles(this.closeButton,e),this.applyButtonStyles(this.checkButton,e),this.wrapper.style.display=t}applyWrapperStyles(e){let t=this.wrapper.style;t.position="absolute",t.zIndex="5",t.display="flex",t.alignItems="center",t.gap=e.badgeGap??"8px",t.padding="6px 8px",t.background=e.badgeBackground??"#FFFFFF",t.borderRadius=e.badgeBorderRadius??"12px",t.boxShadow=e.badgeBoxShadow??"0 2px 10px rgba(15, 23, 42, 0.18)",t.border=e.badgeBorder??"1px solid rgba(0,0,0,0.06)",t.transform="translate(-50%, -140%)",t.pointerEvents="auto",t.userSelect="none",t.whiteSpace="nowrap"}applyValueStyles(e){let t=this.valueEl.style;t.color=e.badgeTextColor??"#19191A",t.fontSize=e.badgeFontSize??"14px",t.fontWeight=e.badgeFontWeight??"600",t.lineHeight="18px"}applyButtonStyles(e,t){let r=e.style,a=t.iconButtonSize??"24px";r.display="inline-flex",r.alignItems="center",r.justifyContent="center",r.width=a,r.height=a,r.border="none",r.background="transparent",r.cursor="pointer",r.color=t.badgeTextColor??"#535969",r.padding="0"}setValue(e){this.valueEl.textContent=e}setCheckEnabled(e){this.checkButton.style.opacity=e?"1":"0.35",this.checkButton.style.pointerEvents=e?"auto":"none"}setPosition(e,t){this.wrapper.style.left=`${e}px`,this.wrapper.style.top=`${t}px`}show(){this.wrapper.style.display="flex"}hide(){this.wrapper.style.display="none"}destroy(){this.wrapper.remove()}},P=class{constructor(e,t,r,a){this.wrapper=document.createElement("div"),this.valueEl=document.createElement("span"),this.trashButton=document.createElement("button"),this.applyStyle(t),this.trashButton.type="button",this.trashButton.innerHTML=L(r.trash,fe);let s=n=>{n.preventDefault(),n.stopPropagation()};this.wrapper.addEventListener("mousedown",s),this.wrapper.addEventListener("dblclick",s),this.wrapper.addEventListener("contextmenu",s),this.trashButton.addEventListener("click",n=>{s(n),a()}),this.wrapper.appendChild(this.valueEl),this.wrapper.appendChild(this.trashButton),e.appendChild(this.wrapper)}applyStyle(e){let t=this.wrapper.style;t.position="absolute",t.zIndex="4",t.display="flex",t.alignItems="center",t.gap=e.badgeGap??"6px",t.padding="5px 7px",t.background=e.badgeBackground??"#FFFFFF",t.borderRadius=e.badgeBorderRadius??"12px",t.boxShadow=e.badgeBoxShadow??"0 2px 10px rgba(15, 23, 42, 0.18)",t.border=e.badgeBorder??"1px solid rgba(0,0,0,0.06)",t.transform="translate(-50%, -50%)",t.pointerEvents="auto",t.userSelect="none",t.whiteSpace="nowrap";let r=this.valueEl.style;r.color=e.badgeTextColor??"#19191A",r.fontSize=e.badgeFontSize??"13px",r.fontWeight=e.badgeFontWeight??"600",r.lineHeight="16px";let a=e.iconButtonSize??"20px",s=this.trashButton.style;s.display="inline-flex",s.alignItems="center",s.justifyContent="center",s.width=a,s.height=a,s.border="none",s.background="transparent",s.cursor="pointer",s.color=e.badgeTextColor??"#535969",s.padding="0"}setValue(e){this.valueEl.textContent=e}setPosition(e,t){this.wrapper.style.left=`${e}px`,this.wrapper.style.top=`${t}px`}destroy(){this.wrapper.remove()}};var Ne=0,z=i=>`${i}-${Date.now().toString(36)}-${Ne+=1}`,Ze=0,_e=()=>`mahal-measure-${Ze+=1}`,Me={pointColor:"#FFFFFF",pointStrokeColor:"#278960",pointStrokeWidth:2,pointRadius:5,lineColor:"#278960",lineWidth:3,fillColor:"#278960",fillOpacity:.15};function N(i,e){return i>=1e3?`${(i/1e3).toFixed(2)} ${e.kilometers??"\u043A\u043C"}`:`${Math.round(i)} ${e.meters??"\u043C"}`}function ve(i,e){return i>=1e5?`${(i/1e6).toFixed(2)} ${e.squareKilometers??"\u043A\u043C\xB2"}`:`${Math.round(i)} ${e.squareMeters??"\u043C\xB2"}`}function x(i){return i==="area"?3:2}function D(){return{type:"FeatureCollection",features:[]}}var E=class{constructor(e,t={}){this.layerHandlersBound=!1;this.destroyed=!1;this.ensuringLayers=!1;this.isActive=!1;this.draft=null;this.shapes=[];this.badge=null;this.shapeBadges=new Map;this.draggingPointId=null;this.draggingShapeId=null;this.dragPanWasEnabled=!0;this.suppressNextClick=!1;this.hoverInsert=null;this.handleClick=e=>this.onMapClick(e);this.handlePointMouseDown=e=>this.onPointMouseDown(e);this.handlePointMouseEnter=()=>{this.isActive&&this.setCursor("pointer")};this.handlePointMouseLeave=()=>{this.isActive&&this.setCursor("")};this.handlePointContextMenu=e=>this.onPointContextMenu(e);this.handleLineMouseMove=e=>this.onLineMouseMove(e);this.handleLineMouseLeave=()=>this.clearHoverInsert();this.handleLineMouseDown=e=>this.onLineMouseDown(e);this.handleStyleLoad=()=>this.onStyleLoad();this.handleStyleData=()=>{this.destroyed||this.map.getLayer(this.pointsLayerId)||this.refresh()};this.handleViewportChange=()=>{this.updateBadgePosition(),this.updateShapeBadgePositions()};this.onPointDragMove=e=>{if(!this.draggingShapeId||!this.draggingPointId)return;let t=this.findShape(this.draggingShapeId),r=t?.points.find(a=>a.id===this.draggingPointId);!t||!r||(r.lngLat=[+e.lngLat.lng.toFixed(6),+e.lngLat.lat.toFixed(6)],this.recomputeShape(t),this.render(),this.emitChange())};this.onPointDragUp=()=>{this.draggingPointId&&(this.stopDragListeners(),this.dragPanWasEnabled&&this.map.dragPan.enable(),this.setCursor("pointer"),this.suppressNextClick=!0,window.setTimeout(()=>{this.suppressNextClick=!1},0))};this.map=e,this.originalCursor=e.getCanvas().style.cursor,this.prefix=t.sourceIdPrefix??_e(),this.style=t.style??{},this.labels=t.labels??{},this.icons=t.icons??{},this.mode=t.mode??"distance",this.onChange=t.onChange,this.onCloseRequest=t.onCloseRequest,this.pointsSourceId=`${this.prefix}-points`,this.linesSourceId=`${this.prefix}-lines`,this.fillsSourceId=`${this.prefix}-fills`,this.hoverPointSourceId=`${this.prefix}-hover-point`,this.pointsLayerId=`${this.prefix}-points-layer`,this.linesCasingLayerId=`${this.prefix}-lines-casing-layer`,this.linesLayerId=`${this.prefix}-lines-layer`,this.fillsLayerId=`${this.prefix}-fills-layer`,this.hoverPointLayerId=`${this.prefix}-hover-point-layer`,this.badge=new w(e.getContainer(),this.style,this.icons,{onRemove:()=>this.removeShape((this.draft??this.getLastShape())?.id??""),onClose:()=>this.onCloseRequest?.(),onCheck:()=>this.finishDraft()}),this.ensureLayers(),this.map.on("click",this.handleClick),this.map.on("style.load",this.handleStyleLoad),this.map.on("styledata",this.handleStyleData),this.map.on("move",this.handleViewportChange)}bindLayerHandlers(){this.layerHandlersBound||(this.layerHandlersBound=!0,this.map.on("mousedown",this.pointsLayerId,this.handlePointMouseDown),this.map.on("mouseenter",this.pointsLayerId,this.handlePointMouseEnter),this.map.on("mouseleave",this.pointsLayerId,this.handlePointMouseLeave),this.map.on("contextmenu",this.pointsLayerId,this.handlePointContextMenu),this.map.on("mousemove",this.linesCasingLayerId,this.handleLineMouseMove),this.map.on("mouseleave",this.linesCasingLayerId,this.handleLineMouseLeave),this.map.on("mousedown",this.linesCasingLayerId,this.handleLineMouseDown))}unbindLayerHandlers(){this.layerHandlersBound&&(this.layerHandlersBound=!1,this.map.off("mousedown",this.pointsLayerId,this.handlePointMouseDown),this.map.off("mouseenter",this.pointsLayerId,this.handlePointMouseEnter),this.map.off("mouseleave",this.pointsLayerId,this.handlePointMouseLeave),this.map.off("contextmenu",this.pointsLayerId,this.handlePointContextMenu),this.map.off("mousemove",this.linesCasingLayerId,this.handleLineMouseMove),this.map.off("mouseleave",this.linesCasingLayerId,this.handleLineMouseLeave),this.map.off("mousedown",this.linesCasingLayerId,this.handleLineMouseDown))}start(e=this.mode){this.isActive=!0;let t=e!==this.mode;this.setMode(e),t||(this.render(),this.emitChange())}stop(){this.isActive=!1,this.onPointDragUp(),this.badge?.hide(),this.clearHoverInsert(),this.setCursor(this.originalCursor),this.emitChange()}setMode(e){this.mode!==e&&(this.mode=e,this.draft&&(this.draft.mode=e,this.recomputeShape(this.draft)),this.render(),this.emitChange())}finishDraft(){this.commitOrDiscardDraft(),this.render(),this.emitChange()}removeShape(e){e&&(this.draft?.id===e?this.draft=null:this.shapes=this.shapes.filter(t=>t.id!==e),this.hoverInsert?.shapeId===e&&this.clearHoverInsert(),this.render(),this.emitChange())}removePoint(e,t){let r=this.findShape(e);if(!r)return;if(r.points=r.points.filter(s=>s.id!==t),r.points.length===0){this.removeShape(e);return}if(!(this.draft?.id===e)&&r.points.length<x(r.mode)){this.removeShape(e);return}this.recomputeShape(r),this.render(),this.emitChange()}clearAll(){this.draft=null,this.shapes=[],this.clearHoverInsert(),this.render(),this.emitChange()}refresh(){this.destroyed||(this.ensureLayers(),this.render(),this.renderHoverPoint())}setStyleOptions(e){let t=this.style.lineDasharray!==void 0;this.style={...this.style,...e},this.applyPaintStyle(t),this.badge?.applyStyle(this.style),this.shapeBadges.forEach(r=>r.applyStyle(this.style))}getState(){return{active:this.isActive,mode:this.mode,draft:this.draft?this.cloneShape(this.draft):null,shapes:this.shapes.map(e=>this.cloneShape(e))}}destroy(){this.destroyed||(this.destroyed=!0,this.map.off("click",this.handleClick),this.unbindLayerHandlers(),this.map.off("style.load",this.handleStyleLoad),this.map.off("styledata",this.handleStyleData),this.map.off("move",this.handleViewportChange),this.onPointDragUp(),this.setCursor(this.originalCursor),this.badge?.destroy(),this.badge=null,this.shapeBadges.forEach(e=>e.destroy()),this.shapeBadges.clear(),this.removeLayers())}cloneShape(e){return{...e,points:e.points.map(t=>({...t,lngLat:[...t.lngLat]}))}}findShape(e){return this.draft?.id===e?this.draft:this.shapes.find(t=>t.id===e)??null}getLastShape(){return this.shapes[this.shapes.length-1]??null}commitOrDiscardDraft(){this.draft&&(this.draft.points.length>=x(this.draft.mode)&&this.shapes.push(this.draft),this.draft=null)}ensureDraft(){return this.draft||(this.draft={id:z("measure-shape"),mode:this.mode,points:[],closed:!1,distance:0,area:0}),this.draft}recomputeShape(e){let t=e.points.map(r=>r.lngLat);if(e.mode==="area"&&t.length>=3){e.closed=!0,e.area=K(t),e.distance=k([...t,t[0]]);return}e.closed=!1,e.area=0,e.distance=k(t)}onMapClick(e){if(!this.isActive)return;if(this.suppressNextClick){this.suppressNextClick=!1;return}if(this.queryPointsLayer(e.point).length>0)return;let r=this.ensureDraft();r.points.push({id:z("measure-point"),lngLat:[+e.lngLat.lng.toFixed(6),+e.lngLat.lat.toFixed(6)]}),this.recomputeShape(r),this.render(),this.emitChange()}onPointMouseDown(e){if(!this.isActive)return;let t=e.features?.[0],r=t?.properties?.shapeId,a=t?.properties?.pointId;!r||!a||(e.preventDefault(),this.beginPointDrag(r,a))}beginPointDrag(e,t){this.draggingShapeId=e,this.draggingPointId=t,this.dragPanWasEnabled=this.map.dragPan.isEnabled(),this.map.dragPan.disable(),this.setCursor("grabbing"),this.map.on("mousemove",this.onPointDragMove),this.map.on("mouseup",this.onPointDragUp),window.addEventListener("mouseup",this.onPointDragUp)}stopDragListeners(){this.map.off("mousemove",this.onPointDragMove),this.map.off("mouseup",this.onPointDragUp),window.removeEventListener("mouseup",this.onPointDragUp),this.draggingShapeId=null,this.draggingPointId=null}projectPoint(e){let t=this.map.project(e);return{x:t.x,y:t.y}}closestPointOnSegment(e,t,r){let a=r.x-t.x,s=r.y-t.y,n=a*a+s*s;if(n===0)return t;let p=Math.max(0,Math.min(1,((e.x-t.x)*a+(e.y-t.y)*s)/n));return{x:t.x+a*p,y:t.y+s*p}}findClosestPointOnShape(e,t){let r=e.points.map(h=>this.projectPoint(h.lngLat)),a=e.closed?r.length:r.length-1,s=-1,n=null,p=1/0;for(let h=0;h<a;h+=1){let d=r[h],u=r[(h+1)%r.length];if(!d||!u)continue;let c=this.closestPointOnSegment(t,d,u),m=c.x-t.x,g=c.y-t.y,b=Math.sqrt(m*m+g*g);b<p&&(p=b,s=h,n=c)}if(s===-1||!n)return null;let o=this.map.unproject([n.x,n.y]);return{index:s,lngLat:[+o.lng.toFixed(6),+o.lat.toFixed(6)]}}queryPointsLayer(e){return this.map.getLayer(this.pointsLayerId)?this.map.queryRenderedFeatures(e,{layers:[this.pointsLayerId]}):[]}isOverExistingPoint(e){return this.queryPointsLayer(e).length>0}onLineMouseMove(e){if(!this.isActive||this.draggingPointId||this.isOverExistingPoint(e.point)){this.clearHoverInsert();return}let r=e.features?.[0]?.properties?.shapeId,a=r?this.findShape(r):null;if(!r||!a)return;let s=this.findClosestPointOnShape(a,e.point);s&&(this.hoverInsert={shapeId:r,index:s.index,lngLat:s.lngLat},this.renderHoverPoint(),this.setCursor("copy"))}clearHoverInsert(){this.hoverInsert&&(this.hoverInsert=null,this.renderHoverPoint(),this.setCursor(""))}onLineMouseDown(e){if(!this.isActive||!this.hoverInsert)return;let r=e.features?.[0]?.properties?.shapeId;if(!r||r!==this.hoverInsert.shapeId)return;let a=this.findShape(r);if(!a)return;e.preventDefault();let s={id:z("measure-point"),lngLat:this.hoverInsert.lngLat};a.points.splice(this.hoverInsert.index+1,0,s),this.recomputeShape(a),this.hoverInsert=null,this.renderHoverPoint(),this.render(),this.emitChange(),this.beginPointDrag(r,s.id)}renderHoverPoint(){let e=this.hoverInsert?[{type:"Feature",properties:{},geometry:{type:"Point",coordinates:this.hoverInsert.lngLat}}]:[];this.setSourceData(this.hoverPointSourceId,{type:"FeatureCollection",features:e})}onPointContextMenu(e){if(!this.isActive)return;let t=e.features?.[0],r=t?.properties?.shapeId,a=t?.properties?.pointId;!r||!a||(e.preventDefault(),this.removePoint(r,a))}setCursor(e){this.map.getCanvas().style.cursor=e}onStyleLoad(){this.refresh()}isMapUsable(){return!this.destroyed&&!!this.map.style}emitChange(){this.onChange?.(this.getState())}ensureLayers(){if(!(!this.isMapUsable()||this.ensuringLayers)){this.ensuringLayers=!0;try{this.createMissingLayers()}catch{}finally{this.ensuringLayers=!1}}}createMissingLayers(){let e={...Me,...this.style};this.map.getSource(this.linesSourceId)||this.map.addSource(this.linesSourceId,{type:"geojson",data:D()}),this.map.getSource(this.fillsSourceId)||this.map.addSource(this.fillsSourceId,{type:"geojson",data:D()}),this.map.getSource(this.pointsSourceId)||this.map.addSource(this.pointsSourceId,{type:"geojson",data:D()}),this.map.getSource(this.hoverPointSourceId)||this.map.addSource(this.hoverPointSourceId,{type:"geojson",data:D()}),this.map.getLayer(this.fillsLayerId)||this.map.addLayer({id:this.fillsLayerId,type:"fill",source:this.fillsSourceId,paint:{"fill-color":e.fillColor,"fill-opacity":e.fillOpacity}}),this.map.getLayer(this.linesCasingLayerId)||this.map.addLayer({id:this.linesCasingLayerId,type:"line",source:this.linesSourceId,layout:{"line-cap":"round","line-join":"round"},paint:{"line-color":"#FFFFFF","line-width":e.lineWidth+3,"line-opacity":.9}}),this.map.getLayer(this.linesLayerId)||this.map.addLayer({id:this.linesLayerId,type:"line",source:this.linesSourceId,layout:{"line-cap":"round","line-join":"round"},paint:{"line-color":e.lineColor,"line-width":e.lineWidth,...this.style.lineDasharray?{"line-dasharray":this.style.lineDasharray}:{}}}),this.map.getLayer(this.hoverPointLayerId)||this.map.addLayer({id:this.hoverPointLayerId,type:"circle",source:this.hoverPointSourceId,paint:{"circle-radius":Math.max(3,e.pointRadius-1),"circle-color":e.pointColor,"circle-stroke-color":e.pointStrokeColor,"circle-stroke-width":e.pointStrokeWidth,"circle-opacity":.8,"circle-stroke-opacity":.8}}),this.map.getLayer(this.pointsLayerId)||this.map.addLayer({id:this.pointsLayerId,type:"circle",source:this.pointsSourceId,paint:{"circle-radius":e.pointRadius,"circle-color":e.pointColor,"circle-stroke-color":e.pointStrokeColor,"circle-stroke-width":e.pointStrokeWidth}}),this.bindLayerHandlers()}applyPaintStyle(e=!1){if(!this.isMapUsable())return;let t={...Me,...this.style},r=(a,s,n)=>{this.map.getLayer(a)&&this.map.setPaintProperty(a,s,n)};r(this.fillsLayerId,"fill-color",t.fillColor),r(this.fillsLayerId,"fill-opacity",t.fillOpacity),r(this.linesCasingLayerId,"line-width",t.lineWidth+3),r(this.linesLayerId,"line-color",t.lineColor),r(this.linesLayerId,"line-width",t.lineWidth),this.style.lineDasharray!==void 0?r(this.linesLayerId,"line-dasharray",this.style.lineDasharray):e&&r(this.linesLayerId,"line-dasharray",null),r(this.hoverPointLayerId,"circle-radius",Math.max(3,t.pointRadius-1)),r(this.hoverPointLayerId,"circle-color",t.pointColor),r(this.hoverPointLayerId,"circle-stroke-color",t.pointStrokeColor),r(this.hoverPointLayerId,"circle-stroke-width",t.pointStrokeWidth),r(this.pointsLayerId,"circle-radius",t.pointRadius),r(this.pointsLayerId,"circle-color",t.pointColor),r(this.pointsLayerId,"circle-stroke-color",t.pointStrokeColor),r(this.pointsLayerId,"circle-stroke-width",t.pointStrokeWidth)}removeLayers(){[this.pointsLayerId,this.hoverPointLayerId,this.linesLayerId,this.linesCasingLayerId,this.fillsLayerId].forEach(e=>{this.map.getLayer(e)&&this.map.removeLayer(e)}),[this.pointsSourceId,this.hoverPointSourceId,this.linesSourceId,this.fillsSourceId].forEach(e=>{this.map.getSource(e)&&this.map.removeSource(e)})}setSourceData(e,t){this.map.getSource(e)?.setData(t)}buildLineFeature(e){if(e.points.length<2)return null;let t=e.points.map(r=>r.lngLat);return{type:"Feature",id:e.id,properties:{shapeId:e.id},geometry:{type:"LineString",coordinates:e.closed?[...t,t[0]]:t}}}buildFillFeature(e){if(e.mode!=="area"||e.points.length<3)return null;let t=e.points.map(r=>r.lngLat);return{type:"Feature",id:e.id,properties:{shapeId:e.id},geometry:{type:"Polygon",coordinates:[[...t,t[0]]]}}}buildPointFeatures(e){return e.points.map(t=>({type:"Feature",id:t.id,properties:{shapeId:e.id,pointId:t.id},geometry:{type:"Point",coordinates:t.lngLat}}))}getShapeAnchor(e){let t=e.points.map(r=>r.lngLat);return e.mode==="area"?W(t):q(t)}render(){this.ensureLayers();let e=this.shapes,t=e.map(s=>this.buildLineFeature(s)).filter(s=>!!s),r=e.map(s=>this.buildFillFeature(s)).filter(s=>!!s),a=e.flatMap(s=>this.buildPointFeatures(s));if(this.draft){let s=this.buildLineFeature(this.draft),n=this.buildFillFeature(this.draft);s&&t.push(s),n&&r.push(n),a.push(...this.buildPointFeatures(this.draft))}this.setSourceData(this.linesSourceId,{type:"FeatureCollection",features:t}),this.setSourceData(this.fillsSourceId,{type:"FeatureCollection",features:r}),this.setSourceData(this.pointsSourceId,{type:"FeatureCollection",features:a}),this.updateBadge(),this.syncShapeBadges()}syncShapeBadges(){let e=new Set(this.shapes.map(t=>t.id));Array.from(this.shapeBadges.keys()).forEach(t=>{e.has(t)||(this.shapeBadges.get(t)?.destroy(),this.shapeBadges.delete(t))}),this.shapes.forEach(t=>{if(t.points.length<x(t.mode)){this.shapeBadges.get(t.id)?.destroy(),this.shapeBadges.delete(t.id);return}let r=t.mode==="area"?ve(t.area,this.labels):N(t.distance,this.labels),a=this.shapeBadges.get(t.id);a||(a=new P(this.map.getContainer(),this.style,this.icons,()=>this.removeShape(t.id)),this.shapeBadges.set(t.id,a)),a.setValue(r);let s=this.map.project(this.getShapeAnchor(t));a.setPosition(s.x,s.y)})}updateShapeBadgePositions(){this.shapes.forEach(e=>{let t=this.shapeBadges.get(e.id);if(!t)return;let r=this.map.project(this.getShapeAnchor(e));t.setPosition(r.x,r.y)})}updateBadge(){if(!this.badge)return;if(!this.isActive||!this.draft||this.draft.points.length===0){this.badge.hide();return}let e=this.draft.points.length>=x(this.draft.mode),t=this.draft.mode==="area"?ve(this.draft.area,this.labels):N(this.draft.distance,this.labels);this.badge.setValue(e?t:N(this.draft.distance,this.labels)),this.badge.setCheckEnabled(e),this.badge.show(),this.updateBadgePosition()}updateBadgePosition(){if(!this.badge||!this.draft||this.draft.points.length===0||!this.isActive)return;let e=this.draft.points[this.draft.points.length-1];if(!e)return;let t=this.map.project(e.lngLat);this.badge.setPosition(t.x,t.y)}};export{C as CheckJSApi,$ as MahalMap,G as MahalMapDefaultMarker,E as MeasureTool,ce as Router,se as Search,oe as SearchByLocation,ne as SearchPoi,ge as keyUtils,Le as measureUtils,ae as utils};
118
+ `}};l.instances=new Map,l.defaultLanguage="tj",l.disposedMaps3DLayers=new WeakSet,l.WORKER_CHECK_DELAY=8e3;var J=l;var ve={};B(ve,{CheckJSApi:()=>C,Router:()=>Me,Search:()=>K,SearchByLocation:()=>de,SearchPoi:()=>$,clearKey:()=>Ee,createSearch:()=>he,createSearchPoi:()=>ue,getApiKey:()=>M,saveKey:()=>xe});var fe=async(a,e)=>{try{let t=[];return a.forEach(i=>{t.push({lng:i[0],lat:i[1]})}),(await y.post("services/getRoutes",{points:t,token:e})).data}catch(t){throw console.error(t),t}};async function Me(a,e,t){if(!t)throw new Error("[MahalMap SDK] Router token is required");try{let r=await fe(a,t);return r?.data?r.data.map(s=>{let n={...s};return n.route?.routes?.length&&(n.route.routes=n.route.routes.map(p=>({...p,geometry:e==="geojson"&&typeof p.geometry=="string"?G(p.geometry):p.geometry}))),n}):r}catch(r){throw r}}var we={};B(we,{MeasureTool:()=>E,haversineDistance:()=>q,lineLength:()=>w,midpoint:()=>Z,polygonArea:()=>N,polygonCentroid:()=>z});var U=63710088e-1;function f(a){return a*Math.PI/180}function V(a){return((a+180)%360+360)%360-180}function W(a){return((a+180)%360+360)%360-180}function q(a,e){let[t,r]=a,[i,s]=e,n=f(r),p=f(s),o=f(s-r),h=f(i-t),u=Math.sin(o/2),d=Math.sin(h/2),c=u*u+Math.cos(n)*Math.cos(p)*d*d,m=2*Math.atan2(Math.sqrt(c),Math.sqrt(1-c));return U*m}function w(a){let e=0;for(let t=1;t<a.length;t+=1)e+=q(a[t-1],a[t]);return e}function N(a){if(a.length<3)return 0;let e=0;for(let t=0;t<a.length;t+=1){let r=a[t],i=a[(t+1)%a.length],s=f(V(i[0]-r[0])),n=f(r[1]),p=f(i[1]);e+=s*(2+Math.sin(n)+Math.sin(p))}return Math.abs(e*U*U/2)}function be(a){let e=a.reduce((t,r)=>[t[0]+r[0],t[1]+r[1]],[0,0]);return[W(e[0]/a.length),e[1]/a.length]}function z(a){if(a.length===0)return[0,0];if(a.length<3)return be(a);let e=a[0]?.[0]??0,t=a.map(([h,u])=>[e+V(h-e),u]),r=0,i=0,s=0;for(let h=0;h<t.length;h+=1){let[u,d]=t[h],[c,m]=t[(h+1)%t.length],g=u*m-c*d;r+=g,i+=(u+c)*g,s+=(d+m)*g}let n=r/2;if(Math.abs(n)<1e-12)return be(t);let p=i/(6*n),o=s/(6*n);return[W(p),o]}function Z(a){if(a.length===0)return[0,0];if(a.length===1)return a[0];let e=[],t=0;for(let s=1;s<a.length;s+=1){let n=q(a[s-1],a[s]);e.push(n),t+=n}if(t===0)return a[0];let r=t/2,i=0;for(let s=1;s<a.length;s+=1){let n=e[s-1];if(i+n>=r){let p=n===0?0:(r-i)/n,o=a[s-1],h=a[s],u=W(o[0]+V(h[0]-o[0])*p),d=o[1]+(h[1]-o[1])*p;return[u,d]}i+=n}return a[a.length-1]}var qe=new Set(["svg","g","path","circle","ellipse","rect","line","polyline","polygon"]),Ne=new Set(["xmlns","viewbox","width","height","fill","fill-rule","fill-opacity","stroke","stroke-width","stroke-linecap","stroke-linejoin","stroke-dasharray","stroke-opacity","opacity","d","cx","cy","r","rx","ry","x","y","x1","y1","x2","y2","points","transform"]),ze=new Set(["fill","stroke"]);function Ze(a,e){let t=e.trim().toLowerCase();return!(t.includes("javascript:")||t.includes("data:")||t.includes("expression(")||ze.has(a)&&t.includes("url("))}function Le(a){return qe.has(a.tagName.toLowerCase())?(Array.from(a.attributes).forEach(e=>{let t=e.name.toLowerCase();(!Ne.has(t)||!Ze(t,e.value))&&a.removeAttribute(e.name)}),Array.from(a.children).forEach(e=>{Le(e)||e.remove()}),!0):!1}function _e(a){if(typeof DOMParser>"u")return null;try{let e=new DOMParser().parseFromString(a,"image/svg+xml"),t=e.documentElement;return!t||t.tagName.toLowerCase()!=="svg"||e.querySelector("parsererror")||!Le(t)?null:new XMLSerializer().serializeToString(t)}catch{return null}}function L(a,e){return a?_e(a)??e:e}var Se='<svg width="16" height="16" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg"><path d="M4 7h16M9 7V4h6v3M6 7l1 13h10l1-13" stroke="currentColor" stroke-width="1.6" stroke-linecap="round" stroke-linejoin="round"/></svg>',Ye='<svg width="14" height="14" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg"><path d="M4 4l16 16M20 4L4 20" stroke="currentColor" stroke-width="1.8" stroke-linecap="round"/></svg>',Xe='<svg width="16" height="16" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg"><path d="M4 12l6 6 10-12" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/></svg>',k=class{constructor(e,t,r,i){this.wrapper=document.createElement("div"),this.valueEl=document.createElement("span"),this.trashButton=document.createElement("button"),this.closeButton=document.createElement("button"),this.checkButton=document.createElement("button"),this.applyWrapperStyles(t),this.applyValueStyles(t),this.applyButtonStyles(this.trashButton,t),this.applyButtonStyles(this.closeButton,t),this.applyButtonStyles(this.checkButton,t),this.trashButton.type="button",this.closeButton.type="button",this.checkButton.type="button",this.trashButton.innerHTML=L(r.trash,Se),this.closeButton.innerHTML=L(r.close,Ye),this.checkButton.innerHTML=L(r.check,Xe);let s=n=>{n.preventDefault(),n.stopPropagation()};this.wrapper.addEventListener("mousedown",s),this.wrapper.addEventListener("dblclick",s),this.wrapper.addEventListener("contextmenu",s),this.trashButton.addEventListener("click",n=>{s(n),i.onRemove()}),this.closeButton.addEventListener("click",n=>{s(n),i.onClose()}),this.checkButton.addEventListener("click",n=>{s(n),i.onCheck()}),this.wrapper.appendChild(this.valueEl),this.wrapper.appendChild(this.checkButton),this.wrapper.appendChild(this.trashButton),this.wrapper.appendChild(this.closeButton),this.wrapper.style.display="none",e.appendChild(this.wrapper)}applyStyle(e){let t=this.wrapper.style.display;this.applyWrapperStyles(e),this.applyValueStyles(e),this.applyButtonStyles(this.trashButton,e),this.applyButtonStyles(this.closeButton,e),this.applyButtonStyles(this.checkButton,e),this.wrapper.style.display=t}applyWrapperStyles(e){let t=this.wrapper.style;t.position="absolute",t.zIndex="5",t.display="flex",t.alignItems="center",t.gap=e.badgeGap??"8px",t.padding="6px 8px",t.background=e.badgeBackground??"#FFFFFF",t.borderRadius=e.badgeBorderRadius??"12px",t.boxShadow=e.badgeBoxShadow??"0 2px 10px rgba(15, 23, 42, 0.18)",t.border=e.badgeBorder??"1px solid rgba(0,0,0,0.06)",t.transform="translate(-50%, -140%)",t.pointerEvents="auto",t.userSelect="none",t.whiteSpace="nowrap"}applyValueStyles(e){let t=this.valueEl.style;t.color=e.badgeTextColor??"#19191A",t.fontSize=e.badgeFontSize??"14px",t.fontWeight=e.badgeFontWeight??"600",t.lineHeight="18px"}applyButtonStyles(e,t){let r=e.style,i=t.iconButtonSize??"24px";r.display="inline-flex",r.alignItems="center",r.justifyContent="center",r.width=i,r.height=i,r.border="none",r.background="transparent",r.cursor="pointer",r.color=t.badgeTextColor??"#535969",r.padding="0"}setValue(e){this.valueEl.textContent=e}setCheckEnabled(e){this.checkButton.style.opacity=e?"1":"0.35",this.checkButton.style.pointerEvents=e?"auto":"none"}setPosition(e,t){this.wrapper.style.left=`${e}px`,this.wrapper.style.top=`${t}px`}show(){this.wrapper.style.display="flex"}hide(){this.wrapper.style.display="none"}destroy(){this.wrapper.remove()}},P=class{constructor(e,t,r,i){this.wrapper=document.createElement("div"),this.valueEl=document.createElement("span"),this.trashButton=document.createElement("button"),this.applyStyle(t),this.trashButton.type="button",this.trashButton.innerHTML=L(r.trash,Se);let s=n=>{n.preventDefault(),n.stopPropagation()};this.wrapper.addEventListener("mousedown",s),this.wrapper.addEventListener("dblclick",s),this.wrapper.addEventListener("contextmenu",s),this.trashButton.addEventListener("click",n=>{s(n),i()}),this.wrapper.appendChild(this.valueEl),this.wrapper.appendChild(this.trashButton),e.appendChild(this.wrapper)}applyStyle(e){let t=this.wrapper.style;t.position="absolute",t.zIndex="4",t.display="flex",t.alignItems="center",t.gap=e.badgeGap??"6px",t.padding="5px 7px",t.background=e.badgeBackground??"#FFFFFF",t.borderRadius=e.badgeBorderRadius??"12px",t.boxShadow=e.badgeBoxShadow??"0 2px 10px rgba(15, 23, 42, 0.18)",t.border=e.badgeBorder??"1px solid rgba(0,0,0,0.06)",t.transform="translate(-50%, -50%)",t.pointerEvents="auto",t.userSelect="none",t.whiteSpace="nowrap";let r=this.valueEl.style;r.color=e.badgeTextColor??"#19191A",r.fontSize=e.badgeFontSize??"13px",r.fontWeight=e.badgeFontWeight??"600",r.lineHeight="16px";let i=e.iconButtonSize??"20px",s=this.trashButton.style;s.display="inline-flex",s.alignItems="center",s.justifyContent="center",s.width=i,s.height=i,s.border="none",s.background="transparent",s.cursor="pointer",s.color=e.badgeTextColor??"#535969",s.padding="0"}setValue(e){this.valueEl.textContent=e}setPosition(e,t){this.wrapper.style.left=`${e}px`,this.wrapper.style.top=`${t}px`}destroy(){this.wrapper.remove()}};var Qe=0,_=a=>`${a}-${Date.now().toString(36)}-${Qe+=1}`,et=0,tt=()=>`mahal-measure-${et+=1}`,Ce={pointColor:"#FFFFFF",pointStrokeColor:"#278960",pointStrokeWidth:2,pointRadius:5,lineColor:"#278960",lineWidth:3,fillColor:"#278960",fillOpacity:.15};function Y(a,e){return a>=1e3?`${(a/1e3).toFixed(2)} ${e.kilometers??"\u043A\u043C"}`:`${Math.round(a)} ${e.meters??"\u043C"}`}function Ie(a,e){return a>=1e5?`${(a/1e6).toFixed(2)} ${e.squareKilometers??"\u043A\u043C\xB2"}`:`${Math.round(a)} ${e.squareMeters??"\u043C\xB2"}`}function D(a){return a==="area"?3:2}function x(){return{type:"FeatureCollection",features:[]}}var E=class{constructor(e,t={}){this.layerHandlersBound=!1;this.destroyed=!1;this.ensuringLayers=!1;this.isActive=!1;this.draft=null;this.shapes=[];this.badge=null;this.shapeBadges=new Map;this.draggingPointId=null;this.draggingShapeId=null;this.dragPanWasEnabled=!0;this.suppressNextClick=!1;this.hoverInsert=null;this.handleClick=e=>this.onMapClick(e);this.handlePointMouseDown=e=>this.onPointMouseDown(e);this.handlePointMouseEnter=()=>{this.isActive&&this.setCursor("pointer")};this.handlePointMouseLeave=()=>{this.isActive&&this.setCursor("")};this.handlePointContextMenu=e=>this.onPointContextMenu(e);this.handleLineMouseMove=e=>this.onLineMouseMove(e);this.handleLineMouseLeave=()=>this.clearHoverInsert();this.handleLineMouseDown=e=>this.onLineMouseDown(e);this.handleStyleLoad=()=>this.onStyleLoad();this.handleStyleData=()=>{this.destroyed||this.map.getLayer(this.pointsLayerId)||this.refresh()};this.handleViewportChange=()=>{this.updateBadgePosition(),this.updateShapeBadgePositions()};this.onPointDragMove=e=>{if(!this.draggingShapeId||!this.draggingPointId)return;let t=this.findShape(this.draggingShapeId),r=t?.points.find(i=>i.id===this.draggingPointId);!t||!r||(r.lngLat=[+e.lngLat.lng.toFixed(6),+e.lngLat.lat.toFixed(6)],this.recomputeShape(t),this.render(),this.emitChange())};this.onPointDragUp=()=>{this.draggingPointId&&(this.stopDragListeners(),this.dragPanWasEnabled&&this.map.dragPan.enable(),this.setCursor("pointer"),this.suppressNextClick=!0,window.setTimeout(()=>{this.suppressNextClick=!1},0))};this.map=e,this.originalCursor=e.getCanvas().style.cursor,this.prefix=t.sourceIdPrefix??tt(),this.style=t.style??{},this.labels=t.labels??{},this.icons=t.icons??{},this.mode=t.mode??"distance",this.onChange=t.onChange,this.onCloseRequest=t.onCloseRequest,this.pointsSourceId=`${this.prefix}-points`,this.linesSourceId=`${this.prefix}-lines`,this.fillsSourceId=`${this.prefix}-fills`,this.hoverPointSourceId=`${this.prefix}-hover-point`,this.pointsLayerId=`${this.prefix}-points-layer`,this.linesCasingLayerId=`${this.prefix}-lines-casing-layer`,this.linesLayerId=`${this.prefix}-lines-layer`,this.fillsLayerId=`${this.prefix}-fills-layer`,this.hoverPointLayerId=`${this.prefix}-hover-point-layer`,this.badge=new k(e.getContainer(),this.style,this.icons,{onRemove:()=>this.removeShape((this.draft??this.getLastShape())?.id??""),onClose:()=>this.onCloseRequest?.(),onCheck:()=>this.finishDraft()}),this.ensureLayers(),this.map.on("click",this.handleClick),this.map.on("style.load",this.handleStyleLoad),this.map.on("styledata",this.handleStyleData),this.map.on("move",this.handleViewportChange)}bindLayerHandlers(){this.layerHandlersBound||(this.layerHandlersBound=!0,this.map.on("mousedown",this.pointsLayerId,this.handlePointMouseDown),this.map.on("mouseenter",this.pointsLayerId,this.handlePointMouseEnter),this.map.on("mouseleave",this.pointsLayerId,this.handlePointMouseLeave),this.map.on("contextmenu",this.pointsLayerId,this.handlePointContextMenu),this.map.on("mousemove",this.linesCasingLayerId,this.handleLineMouseMove),this.map.on("mouseleave",this.linesCasingLayerId,this.handleLineMouseLeave),this.map.on("mousedown",this.linesCasingLayerId,this.handleLineMouseDown))}unbindLayerHandlers(){this.layerHandlersBound&&(this.layerHandlersBound=!1,this.map.off("mousedown",this.pointsLayerId,this.handlePointMouseDown),this.map.off("mouseenter",this.pointsLayerId,this.handlePointMouseEnter),this.map.off("mouseleave",this.pointsLayerId,this.handlePointMouseLeave),this.map.off("contextmenu",this.pointsLayerId,this.handlePointContextMenu),this.map.off("mousemove",this.linesCasingLayerId,this.handleLineMouseMove),this.map.off("mouseleave",this.linesCasingLayerId,this.handleLineMouseLeave),this.map.off("mousedown",this.linesCasingLayerId,this.handleLineMouseDown))}start(e=this.mode){this.isActive=!0;let t=e!==this.mode;this.setMode(e),t||(this.render(),this.emitChange())}stop(){this.isActive=!1,this.onPointDragUp(),this.badge?.hide(),this.clearHoverInsert(),this.setCursor(this.originalCursor),this.emitChange()}setMode(e){this.mode!==e&&(this.mode=e,this.draft&&(this.draft.mode=e,this.recomputeShape(this.draft)),this.render(),this.emitChange())}finishDraft(){this.commitOrDiscardDraft(),this.render(),this.emitChange()}removeShape(e){e&&(this.draft?.id===e?this.draft=null:this.shapes=this.shapes.filter(t=>t.id!==e),this.hoverInsert?.shapeId===e&&this.clearHoverInsert(),this.render(),this.emitChange())}removePoint(e,t){let r=this.findShape(e);if(!r)return;if(r.points=r.points.filter(s=>s.id!==t),r.points.length===0){this.removeShape(e);return}if(!(this.draft?.id===e)&&r.points.length<D(r.mode)){this.removeShape(e);return}this.recomputeShape(r),this.render(),this.emitChange()}clearAll(){this.draft=null,this.shapes=[],this.clearHoverInsert(),this.render(),this.emitChange()}refresh(){this.destroyed||(this.ensureLayers(),this.render(),this.renderHoverPoint())}setStyleOptions(e){let t=this.style.lineDasharray!==void 0;this.style={...this.style,...e},this.applyPaintStyle(t),this.badge?.applyStyle(this.style),this.shapeBadges.forEach(r=>r.applyStyle(this.style))}getState(){return{active:this.isActive,mode:this.mode,draft:this.draft?this.cloneShape(this.draft):null,shapes:this.shapes.map(e=>this.cloneShape(e))}}destroy(){this.destroyed||(this.destroyed=!0,this.map.off("click",this.handleClick),this.unbindLayerHandlers(),this.map.off("style.load",this.handleStyleLoad),this.map.off("styledata",this.handleStyleData),this.map.off("move",this.handleViewportChange),this.onPointDragUp(),this.setCursor(this.originalCursor),this.badge?.destroy(),this.badge=null,this.shapeBadges.forEach(e=>e.destroy()),this.shapeBadges.clear(),this.removeLayers())}cloneShape(e){return{...e,points:e.points.map(t=>({...t,lngLat:[...t.lngLat]}))}}findShape(e){return this.draft?.id===e?this.draft:this.shapes.find(t=>t.id===e)??null}getLastShape(){return this.shapes[this.shapes.length-1]??null}commitOrDiscardDraft(){this.draft&&(this.draft.points.length>=D(this.draft.mode)&&this.shapes.push(this.draft),this.draft=null)}ensureDraft(){return this.draft||(this.draft={id:_("measure-shape"),mode:this.mode,points:[],closed:!1,distance:0,area:0}),this.draft}recomputeShape(e){let t=e.points.map(r=>r.lngLat);if(e.mode==="area"&&t.length>=3){e.closed=!0,e.area=N(t),e.distance=w([...t,t[0]]);return}e.closed=!1,e.area=0,e.distance=w(t)}onMapClick(e){if(!this.isActive)return;if(this.suppressNextClick){this.suppressNextClick=!1;return}if(this.queryPointsLayer(e.point).length>0)return;let r=this.ensureDraft();r.points.push({id:_("measure-point"),lngLat:[+e.lngLat.lng.toFixed(6),+e.lngLat.lat.toFixed(6)]}),this.recomputeShape(r),this.render(),this.emitChange()}onPointMouseDown(e){if(!this.isActive)return;let t=e.features?.[0],r=t?.properties?.shapeId,i=t?.properties?.pointId;!r||!i||(e.preventDefault(),this.beginPointDrag(r,i))}beginPointDrag(e,t){this.draggingShapeId=e,this.draggingPointId=t,this.dragPanWasEnabled=this.map.dragPan.isEnabled(),this.map.dragPan.disable(),this.setCursor("grabbing"),this.map.on("mousemove",this.onPointDragMove),this.map.on("mouseup",this.onPointDragUp),window.addEventListener("mouseup",this.onPointDragUp)}stopDragListeners(){this.map.off("mousemove",this.onPointDragMove),this.map.off("mouseup",this.onPointDragUp),window.removeEventListener("mouseup",this.onPointDragUp),this.draggingShapeId=null,this.draggingPointId=null}projectPoint(e){let t=this.map.project(e);return{x:t.x,y:t.y}}closestPointOnSegment(e,t,r){let i=r.x-t.x,s=r.y-t.y,n=i*i+s*s;if(n===0)return t;let p=Math.max(0,Math.min(1,((e.x-t.x)*i+(e.y-t.y)*s)/n));return{x:t.x+i*p,y:t.y+s*p}}findClosestPointOnShape(e,t){let r=e.points.map(h=>this.projectPoint(h.lngLat)),i=e.closed?r.length:r.length-1,s=-1,n=null,p=1/0;for(let h=0;h<i;h+=1){let u=r[h],d=r[(h+1)%r.length];if(!u||!d)continue;let c=this.closestPointOnSegment(t,u,d),m=c.x-t.x,g=c.y-t.y,S=Math.sqrt(m*m+g*g);S<p&&(p=S,s=h,n=c)}if(s===-1||!n)return null;let o=this.map.unproject([n.x,n.y]);return{index:s,lngLat:[+o.lng.toFixed(6),+o.lat.toFixed(6)]}}queryPointsLayer(e){return this.map.getLayer(this.pointsLayerId)?this.map.queryRenderedFeatures(e,{layers:[this.pointsLayerId]}):[]}isOverExistingPoint(e){return this.queryPointsLayer(e).length>0}onLineMouseMove(e){if(!this.isActive||this.draggingPointId||this.isOverExistingPoint(e.point)){this.clearHoverInsert();return}let r=e.features?.[0]?.properties?.shapeId,i=r?this.findShape(r):null;if(!r||!i)return;let s=this.findClosestPointOnShape(i,e.point);s&&(this.hoverInsert={shapeId:r,index:s.index,lngLat:s.lngLat},this.renderHoverPoint(),this.setCursor("copy"))}clearHoverInsert(){this.hoverInsert&&(this.hoverInsert=null,this.renderHoverPoint(),this.setCursor(""))}onLineMouseDown(e){if(!this.isActive||!this.hoverInsert)return;let r=e.features?.[0]?.properties?.shapeId;if(!r||r!==this.hoverInsert.shapeId)return;let i=this.findShape(r);if(!i)return;e.preventDefault();let s={id:_("measure-point"),lngLat:this.hoverInsert.lngLat};i.points.splice(this.hoverInsert.index+1,0,s),this.recomputeShape(i),this.hoverInsert=null,this.renderHoverPoint(),this.render(),this.emitChange(),this.beginPointDrag(r,s.id)}renderHoverPoint(){let e=this.hoverInsert?[{type:"Feature",properties:{},geometry:{type:"Point",coordinates:this.hoverInsert.lngLat}}]:[];this.setSourceData(this.hoverPointSourceId,{type:"FeatureCollection",features:e})}onPointContextMenu(e){if(!this.isActive)return;let t=e.features?.[0],r=t?.properties?.shapeId,i=t?.properties?.pointId;!r||!i||(e.preventDefault(),this.removePoint(r,i))}setCursor(e){this.map.getCanvas().style.cursor=e}onStyleLoad(){this.refresh()}isMapUsable(){return!this.destroyed&&!!this.map.style}emitChange(){this.onChange?.(this.getState())}ensureLayers(){if(!(!this.isMapUsable()||this.ensuringLayers)){this.ensuringLayers=!0;try{this.createMissingLayers()}catch{}finally{this.ensuringLayers=!1}}}createMissingLayers(){let e={...Ce,...this.style};this.map.getSource(this.linesSourceId)||this.map.addSource(this.linesSourceId,{type:"geojson",data:x()}),this.map.getSource(this.fillsSourceId)||this.map.addSource(this.fillsSourceId,{type:"geojson",data:x()}),this.map.getSource(this.pointsSourceId)||this.map.addSource(this.pointsSourceId,{type:"geojson",data:x()}),this.map.getSource(this.hoverPointSourceId)||this.map.addSource(this.hoverPointSourceId,{type:"geojson",data:x()}),this.map.getLayer(this.fillsLayerId)||this.map.addLayer({id:this.fillsLayerId,type:"fill",source:this.fillsSourceId,paint:{"fill-color":e.fillColor,"fill-opacity":e.fillOpacity}}),this.map.getLayer(this.linesCasingLayerId)||this.map.addLayer({id:this.linesCasingLayerId,type:"line",source:this.linesSourceId,layout:{"line-cap":"round","line-join":"round"},paint:{"line-color":"#FFFFFF","line-width":e.lineWidth+3,"line-opacity":.9}}),this.map.getLayer(this.linesLayerId)||this.map.addLayer({id:this.linesLayerId,type:"line",source:this.linesSourceId,layout:{"line-cap":"round","line-join":"round"},paint:{"line-color":e.lineColor,"line-width":e.lineWidth,...this.style.lineDasharray?{"line-dasharray":this.style.lineDasharray}:{}}}),this.map.getLayer(this.hoverPointLayerId)||this.map.addLayer({id:this.hoverPointLayerId,type:"circle",source:this.hoverPointSourceId,paint:{"circle-radius":Math.max(3,e.pointRadius-1),"circle-color":e.pointColor,"circle-stroke-color":e.pointStrokeColor,"circle-stroke-width":e.pointStrokeWidth,"circle-opacity":.8,"circle-stroke-opacity":.8}}),this.map.getLayer(this.pointsLayerId)||this.map.addLayer({id:this.pointsLayerId,type:"circle",source:this.pointsSourceId,paint:{"circle-radius":e.pointRadius,"circle-color":e.pointColor,"circle-stroke-color":e.pointStrokeColor,"circle-stroke-width":e.pointStrokeWidth}}),this.bindLayerHandlers()}applyPaintStyle(e=!1){if(!this.isMapUsable())return;let t={...Ce,...this.style},r=(i,s,n)=>{this.map.getLayer(i)&&this.map.setPaintProperty(i,s,n)};r(this.fillsLayerId,"fill-color",t.fillColor),r(this.fillsLayerId,"fill-opacity",t.fillOpacity),r(this.linesCasingLayerId,"line-width",t.lineWidth+3),r(this.linesLayerId,"line-color",t.lineColor),r(this.linesLayerId,"line-width",t.lineWidth),this.style.lineDasharray!==void 0?r(this.linesLayerId,"line-dasharray",this.style.lineDasharray):e&&r(this.linesLayerId,"line-dasharray",null),r(this.hoverPointLayerId,"circle-radius",Math.max(3,t.pointRadius-1)),r(this.hoverPointLayerId,"circle-color",t.pointColor),r(this.hoverPointLayerId,"circle-stroke-color",t.pointStrokeColor),r(this.hoverPointLayerId,"circle-stroke-width",t.pointStrokeWidth),r(this.pointsLayerId,"circle-radius",t.pointRadius),r(this.pointsLayerId,"circle-color",t.pointColor),r(this.pointsLayerId,"circle-stroke-color",t.pointStrokeColor),r(this.pointsLayerId,"circle-stroke-width",t.pointStrokeWidth)}removeLayers(){[this.pointsLayerId,this.hoverPointLayerId,this.linesLayerId,this.linesCasingLayerId,this.fillsLayerId].forEach(e=>{this.map.getLayer(e)&&this.map.removeLayer(e)}),[this.pointsSourceId,this.hoverPointSourceId,this.linesSourceId,this.fillsSourceId].forEach(e=>{this.map.getSource(e)&&this.map.removeSource(e)})}setSourceData(e,t){this.map.getSource(e)?.setData(t)}buildLineFeature(e){if(e.points.length<2)return null;let t=e.points.map(r=>r.lngLat);return{type:"Feature",id:e.id,properties:{shapeId:e.id},geometry:{type:"LineString",coordinates:e.closed?[...t,t[0]]:t}}}buildFillFeature(e){if(e.mode!=="area"||e.points.length<3)return null;let t=e.points.map(r=>r.lngLat);return{type:"Feature",id:e.id,properties:{shapeId:e.id},geometry:{type:"Polygon",coordinates:[[...t,t[0]]]}}}buildPointFeatures(e){return e.points.map(t=>({type:"Feature",id:t.id,properties:{shapeId:e.id,pointId:t.id},geometry:{type:"Point",coordinates:t.lngLat}}))}getShapeAnchor(e){let t=e.points.map(r=>r.lngLat);return e.mode==="area"?z(t):Z(t)}render(){this.ensureLayers();let e=this.shapes,t=e.map(s=>this.buildLineFeature(s)).filter(s=>!!s),r=e.map(s=>this.buildFillFeature(s)).filter(s=>!!s),i=e.flatMap(s=>this.buildPointFeatures(s));if(this.draft){let s=this.buildLineFeature(this.draft),n=this.buildFillFeature(this.draft);s&&t.push(s),n&&r.push(n),i.push(...this.buildPointFeatures(this.draft))}this.setSourceData(this.linesSourceId,{type:"FeatureCollection",features:t}),this.setSourceData(this.fillsSourceId,{type:"FeatureCollection",features:r}),this.setSourceData(this.pointsSourceId,{type:"FeatureCollection",features:i}),this.updateBadge(),this.syncShapeBadges()}syncShapeBadges(){let e=new Set(this.shapes.map(t=>t.id));Array.from(this.shapeBadges.keys()).forEach(t=>{e.has(t)||(this.shapeBadges.get(t)?.destroy(),this.shapeBadges.delete(t))}),this.shapes.forEach(t=>{if(t.points.length<D(t.mode)){this.shapeBadges.get(t.id)?.destroy(),this.shapeBadges.delete(t.id);return}let r=t.mode==="area"?Ie(t.area,this.labels):Y(t.distance,this.labels),i=this.shapeBadges.get(t.id);i||(i=new P(this.map.getContainer(),this.style,this.icons,()=>this.removeShape(t.id)),this.shapeBadges.set(t.id,i)),i.setValue(r);let s=this.map.project(this.getShapeAnchor(t));i.setPosition(s.x,s.y)})}updateShapeBadgePositions(){this.shapes.forEach(e=>{let t=this.shapeBadges.get(e.id);if(!t)return;let r=this.map.project(this.getShapeAnchor(e));t.setPosition(r.x,r.y)})}updateBadge(){if(!this.badge)return;if(!this.isActive||!this.draft||this.draft.points.length===0){this.badge.hide();return}let e=this.draft.points.length>=D(this.draft.mode),t=this.draft.mode==="area"?Ie(this.draft.area,this.labels):Y(this.draft.distance,this.labels);this.badge.setValue(e?t:Y(this.draft.distance,this.labels)),this.badge.setCheckEnabled(e),this.badge.show(),this.updateBadgePosition()}updateBadgePosition(){if(!this.badge||!this.draft||this.draft.points.length===0||!this.isActive)return;let e=this.draft.points[this.draft.points.length-1];if(!e)return;let t=this.map.project(e.lngLat);this.badge.setPosition(t.x,t.y)}};export{C as CheckJSApi,b as DebounceCancelledError,J as MahalMap,j as MahalMapDefaultMarker,E as MeasureTool,Me as Router,K as Search,de as SearchByLocation,$ as SearchPoi,he as createSearch,ue as createSearchPoi,ve as keyUtils,we as measureUtils,oe as utils};