@arenarium/maps 1.5.9 → 1.5.10
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/main.d.ts +2 -2
- package/dist/main.js +3 -3
- package/package.json +2 -2
package/dist/main.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ApiJwt, ApiKey, MapConfiguration, MapConfiguration as MapConfiguration$1, MapMarkerProperties, MapMarkerProperties as MapMarkerProperties$1 } from "@arenarium/maps-core/declarations/schemas";
|
|
1
|
+
import { ApiJwt, ApiKey, MapConfiguration, MapConfiguration as MapConfiguration$1, MapMarkerOrientation, MapMarkerProperties, MapMarkerProperties as MapMarkerProperties$1 } from "@arenarium/maps-core/declarations/schemas";
|
|
2
2
|
import { IMapManager, IMapProvider, IMapProvider as MapProvider, IMapProviderMarker as MapProviderMarker } from "@arenarium/maps-core/declarations/interfaces";
|
|
3
3
|
|
|
4
4
|
//#region src/map/manager.d.ts
|
|
@@ -60,4 +60,4 @@ declare class MapManager extends IMapManager {
|
|
|
60
60
|
hidePopup(): void;
|
|
61
61
|
}
|
|
62
62
|
//#endregion
|
|
63
|
-
export { type MapConfiguration, MapManager, type MapMarkerProperties, type MapProvider, type MapProviderMarker };
|
|
63
|
+
export { type MapConfiguration, MapManager, MapMarkerOrientation, type MapMarkerProperties, type MapProvider, type MapProviderMarker };
|
package/dist/main.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import{HEADER_CONTENT_TYPE as e,HEADER_JWT as t,HEADER_KEY as n,HEADER_URL as r,HEADER_VERSION as i}from"@arenarium/maps-core/map/headers";import*as a from"@arenarium/maps-core/http";import{LogLevel as o,LogSource as s,
|
|
2
|
-
`,
|
|
3
|
-
`,P=class e extends D{#e;#t;#n;#r;#i;#a;#o;#s;#c;#l;#u;#d;#f;#p;#m;#h;#g;#_=!1;#v=!1;#y=!0;#b;#x=NaN;#S=!1;#C;constructor(t,n){super();let r=n.dimensions,i=n.style,a=r.width+2*r.padding,o=r.height+2*r.padding,s=r.padding,c=r.width,l=r.height,u=i?.background??`#ffffff`,d=Math.min(i?.radius??8,Math.min(c,l)/2),f=Math.min(1,2*d/Math.min(l,c)),p=r.width,m=r.height,h=i?.radius??0,g=r.padding*2,_=Math.min(3,.5*d),v=i?.background??`#ffffff`,y=o<a?o/a:1,b=a<o?a/o:1,x=Math.min(a,o)/2,S=x*Math.SQRT2,C=15*Math.SQRT2,T=document.createElement(`div`);T.classList.add(`element-${e.uuid}`),T.classList.add(`body-${e.uuid}`),T.style.width=`${p}px`,T.style.height=`${m}px`,T.style.borderRadius=`${h}px`,T.style.opacity=`0`,this.#g=T;let E=document.createElement(`div`);E.classList.add(`element-${e.uuid}`),E.classList.add(`bubble-${e.uuid}`),E.style.width=`${c}px`,E.style.height=`${l}px`,E.style.borderRadius=`${d}px`,E.style.backgroundColor=`rgb(from ${u} r g b / 1)`,E.appendChild(T);let D=document.createElement(`div`);D.classList.add(`element-${e.uuid}`),D.classList.add(`pointer-${e.uuid}`),D.style.width=`${g}px`,D.style.height=`${g}px`,D.style.borderRadius=`${_}px`,D.style.backgroundColor=`rgb(from ${v} r g b / 1)`;let k=document.createElement(`div`);k.classList.add(`element-${e.uuid}`),k.classList.add(`anchor-${e.uuid}`),k.style.filter=i?.filter??`drop-shadow(0px 2px 2px rgba(0, 0, 0, 0.5))`,k.style.scale=`0`,k.style.opacity=`0`,k.appendChild(D),k.appendChild(E),this.#e=t,this.#t=n.content,this.#n=n.initialize,this.#r=a,this.#i=o,this.#a=s,this.#o=k,this.#s=D,this.#c=y,this.#l=b,this.#d=x,this.#u=S,this.#f=15,this.#p=C,this.#m=E,this.#h=f;let A=Math.min(4,1+3*(r.width*r.height)/65536),j=25e-5/A;this.#b=new O({value:0,timespan:125*Math.cbrt(A),easing:this.#w.bind(null),callback:this.#T.bind(this)}),this.#C=new M({stiffness:j,damping:2*Math.sqrt(j),precision:1,x:{value:-a/2,min:-a-a*w,max:a*w},y:{value:-o/2,min:-o-o*w,max:o*w},callback:this.#E.bind(this)})}static getStyle(){return N}getElement(){return this.#o}setDisplayed(e){this.#v!==e&&(this.#v=e,e===!0&&(this.#t&&this.#t.parentElement!==this.#g&&this.#g.appendChild(this.#t),this.#_===!1&&this.#n&&this.#t&&(this.#_=!0,setTimeout(this.#n.bind(this,this.#e,this.#t),0))),this.#o.style.display=e?`initial`:`none`,this.#o.style.contentVisibility=e?`visible`:`hidden`,e===!1&&(this.#b.end(),this.#C.end()))}getDisplayed(){return this.#v}setCollapsed(e){this.#y!==e&&(this.#y=e,this.#b.target(+!e))}getCollapsed(){return this.#v?this.#b.expired():!0}#w(e){return-.5*(Math.cos(Math.PI*e)-1)}#T(e){this.#o.style.opacity=`${e}`,this.#o.style.scale=`${e}`,this.#g.style.opacity=`${e}`}setAngle(e){if(Number.isNaN(e)){this.#x=NaN,this.#S=!1;return}if(this.#S===!1){this.#S=!0,this.#x=e;let t=g.offsets(this.#r,this.#i,e);this.#C.set(Math.round(t.x),Math.round(t.y));return}if(this.#x!==e){this.#x=e;let t=g.offsets(this.#r,this.#i,e);this.#C.target(Math.round(t.x),Math.round(t.y));return}}#E(e,t){let n=e+this.#r/2,r=t+this.#i/2,i=n*this.#c,a=r*this.#l,o=Math.sqrt(i*i+a*a),s=(o-this.#d)/(this.#u-this.#d),c=Math.atan2(a,i)/Math.PI*180-45,l=this.#f+s*(this.#p-this.#f),u=o<this.#d?o/this.#d:1,d=.5*((1+.5*this.#h)*s),f=e+this.#a*(1-d*(i/this.#d)),p=t+this.#a*(1-d*(a/this.#d));this.#s.style.transform=`scale(${u}) rotate(${c}deg) skew(${l}deg, ${l}deg)`,this.#m.style.transform=`translate(${Math.round(f)}px, ${Math.round(p)}px)`}},F=class{id;pin;tooltip;popup;constructor(e,t,n,r,i){this.id=t.id,this.pin=new L(e,t,n),this.tooltip=new R(e,t,r),this.popup=i?new z(e,t,i):void 0}update(e){this.pin.update(e),this.tooltip.update(e)}remove(){this.pin.remove(),this.tooltip.remove(),this.popup?.remove()}static attach(){A.attach(),P.attach()}},I=class{id;lat;lng;rank;shown=!0;displayed=!1;component;marker;constructor(e,t,n){this.id=t.id,this.lat=t.lat,this.lng=t.lng,this.rank=t.rank;let r=n.getElement(),i=document.createElement(`div`);i.appendChild(r),this.component=n,this.marker=e.createMarker({element:i,lat:t.lat,lng:t.lng,z:this.getZIndex()})}remove(){this.component.setDisplayed(!1),this.marker.remove()}setCollapsed(e){this.component.setCollapsed(e)}getCollapsed(){return this.component.getCollapsed()}getDisplayed(){return this.displayed}setDisplayed(e){this.displayed!==e&&(this.displayed=e,e?(this.component.setDisplayed(!0),this.marker.insert()):(this.component.setDisplayed(!1),this.marker.remove()))}},L=class extends I{properties;zoom=NaN;constructor(e,t,n){let r=new A(t.id,n);super(e,t,r),this.properties=n}update(e){e?this.zoom=e.zoom:this.zoom=NaN,this.marker.update(this.getZIndex())}getZIndex(){return this.zoom===void 0||Number.isNaN(this.zoom)?this.rank:Math.round(-this.zoom*h)+1e6}setScale(e,t){this.component.setScale(e,t)}},R=class extends I{properties;zoom=NaN;angle=NaN;directions=[];constructor(e,t,n){let r=new P(t.id,n);super(e,t,r),this.properties=n}update(e){e?(this.zoom=e.zoom,this.directions=e.directions):(this.zoom=NaN,this.directions=[]),this.marker.update(this.getZIndex())}getZIndex(){return this.zoom===void 0||Number.isNaN(this.zoom)?this.rank:Math.round(-this.zoom*h)+2e6}findAngle(e){let t=this.directions.findLast(t=>t.zoom<=e)?.angle;if(t===void 0)throw Error(`Failed to find angle`);return t}setAngle(e){this.angle=e,this.component.setAngle(e)}},z=class extends I{properties;angle=NaN;constructor(e,t,n){let r=new P(t.id,n);super(e,t,r),this.shown=!1,this.properties=n}getZIndex(){return 3e6}setAngle(e){this.angle=e,this.component.setAngle(e)}},B=class{info;properties;element;state;constructor(e,t,n,r,i){this.info=t,this.properties={pin:n,tooltip:r,popup:i},this.element=new F(e,t,n,r,i)}update(e){this.state=e,this.element.update(e)}},V=class{#e;#t;#n;constructor(e,t){if(t<=0)throw Error(`Invalid timeout`);this.#e=e,this.#t=t}start(){this.#n===void 0&&(this.#n=window.setInterval(this.#e,this.#t))}stop(){this.#n!==void 0&&(window.clearInterval(this.#n),this.#n=void 0)}running(){return this.#n!==void 0}},H=class{#e=void 0;#t=`idle`;#n;#r;#i;#a;#o;#s;#c;constructor(e,t,n,r,i,a){this.#n=e,this.#r=new V(this.#l.bind(this),100/Math.max(4,navigator?.hardwareConcurrency??1)),this.#i=t,this.#a=n,this.#o=r,this.#s=i,this.#c=a}#l(){try{if(this.#i()){this.#r.stop();return}let e=this.#n.getViewport(),t=this.#t,n=JSON.stringify(e)===JSON.stringify(this.#e)?`idle`:`move`;n===`move`&&this.#o(),n===`idle`&&t===`move`&&this.#s(),this.#t=n,this.#e=e}catch(e){this.#a(`Failed to process map state interval`,e)}}start(){this.#r.running()===!1&&(this.#r.start(),this.#n.getContainer().addEventListener(`click`,this.#c))}stop(){this.#r.running()===!0&&(this.#r.stop(),this.#n.getContainer().removeEventListener(`click`,this.#c))}idle(){return this.#t===`idle`}},U=class{#e;#t;constructor(e,t,n,r){if(n<e)throw Error(`Invalid bounds: swLat: ${e}, neLat: ${n}`);if(r<t)throw Error(`Invalid bounds: swLng: ${t}, neLng: ${r}`);this.#e={lat:e,lng:t},this.#t={lat:n,lng:r}}contains(e,t){return!(e<this.#e.lat||this.#t.lat<e||t<this.#e.lng||this.#t.lng<t)}intersects(e){return!(e.ne.lat<this.#e.lat||this.#t.lat<e.sw.lat||e.ne.lng<this.#e.lng||this.#t.lng<e.sw.lng)}},W=class e{#e;#t;constructor(e,t,n,r){if(t<180&&180<r){this.#e=new U(e,t,n,180),this.#t=new U(e,-180,n,r-360);return}if(t<-180&&-180<r){this.#e=new U(e,360+t,n,180),this.#t=new U(e,-180,n,r);return}this.#e=new U(e,t,n,r),this.#t=new U(0,0,0,0)}static normalize(e){let t=e.bounds,n=e.center;if(t.ne.lng-t.sw.lng>360)return{sw:{lat:t.sw.lat,lng:-180},ne:{lat:t.ne.lat,lng:180}};if(t.sw.lng>t.ne.lng)return t.sw.lng+t.ne.lng<0?{sw:{lat:t.sw.lat,lng:t.sw.lng},ne:{lat:t.ne.lat,lng:t.ne.lng+360}}:{sw:{lat:t.sw.lat,lng:t.sw.lng-360},ne:{lat:t.ne.lat,lng:t.ne.lng}};if(-180<=n.lng&&n.lng<=180){let e=Math.abs(t.ne.lng-n.lng),r=Math.abs(t.sw.lng-n.lng);if(e+r>360)return{sw:{lat:t.sw.lat,lng:-180},ne:{lat:t.ne.lat,lng:180}};if(t.sw.lng<=n.lng&&t.ne.lng<=n.lng||t.sw.lng>=n.lng&&t.ne.lng>=n.lng)return{sw:{lat:t.sw.lat,lng:n.lng-e},ne:{lat:t.ne.lat,lng:n.lng+r}}}return e.bounds}static create(t){let n=this.normalize(t),r=n.sw,i=n.ne;return new e(r.lat,r.lng,i.lat,i.lng)}static viewport(t,n,r){let i=this.normalize(t),a=n*2**t.zoom,o=v.project(i.sw.lat,i.sw.lng,a),s=v.project(i.ne.lat,i.ne.lng,a),c=Math.min(o.y+r.bottom,a),l=Math.max(s.y-r.top,0),u=o.x-r.left,d=s.x+r.right;d-u>a&&(u=0,d=a),d<u&&(d=u=(s.x-o.x)/2);let f=v.unproject(u,c,a),p=v.unproject(d,l,a);return new e(f.lat,f.lng,p.lat,p.lng)}static max(t,n,r){let i=n*2**t,a=r.left,o=i-r.bottom,s=i-r.right,c=r.top,l=v.unproject(a,o,i),u=v.unproject(s,c,i);return new e(l.lat,l.lng,u.lat,u.lng)}contains(e,t){return this.#e.contains(e,t)||this.#t.contains(e,t)}intersects(e){return this.#e.intersects(e)||this.#t.intersects(e)}},G=class{#e;#t=0;#n=T;#r=T;#i=1;#a=1;#o=3;#s=3;#c=new Set;constructor(e,t){this.#e=e,this.update(t)}update(e){this.#n=e?.pin?.fadeout?.color??.2,this.#r=e?.pin?.fadeout?.scale??.2,this.#i=e?.pin?.fadeout?.opacity??1,this.#a=this.#n<this.#r?this.#n/this.#r:1,this.#o=e?.pin?.depth??3,this.#s=this.#o}insert(e){this.#c.add(e)}clear(){this.#c.forEach(e=>e.remove()),this.#c.clear(),this.#e.updateCircles([],this.#o)}refresh(){let e=Array.from(this.#c);this.#t=e.reduce((e,t)=>Math.max(e,t.properties.dimensions.radius*2),0),this.#s=Math.max(1,this.#o-Math.log10(e.length))}draw(){let e=Array.from(this.#c),t=[];for(let n=0;n<e.length;n++){let r=e[n],i=Math.max(0,Math.min(1,this.#n*this.#o)),a=Math.max(0,Math.min(1,this.#r*this.#o)),o=Math.max(0,Math.min(1,this.#i*this.#o)),s=r.properties.style?.background??`#008800`,c=_(s,0,1),l=_(s,i,o),u=r.properties.dimensions.radius-r.properties.dimensions.stroke,d=u*(1-a),f=r.properties.style?.stroke??`#ffffff`,p=_(f,0,1),m=_(f,i,o),h=r.properties.dimensions.stroke,g=h*(1-a),v={color:{min:l,max:c},radius:{min:d,max:u},stroke:{color:{min:m,max:p},width:{min:g,max:h}},lat:r.lat,lng:r.lng,rank:r.rank,zoom:r.zoom};t.push(v)}this.#e.updateCircles(t,this.#o)}render(e,t){let n=e.zoom,r=W.viewport(e,t.size,{top:this.#t,bottom:this.#t,right:this.#t,left:this.#t});for(let e of this.#c){let t=Number.isNaN(e.zoom);if(t||=n+this.#s<e.zoom,t||=r.contains(e.lat,e.lng)===!1,t){e.setDisplayed(!1);continue}if(e.shown&&n<e.zoom){let t=(e.zoom-n)/this.#s,r=Math.max(0,1-t*this.#r),i=this.#a;e.setDisplayed(!0),e.setCollapsed(!1),e.setScale(r,i)}else e.setCollapsed(!0),e.getCollapsed()&&e.setDisplayed(!1)}}},K=class{#e=0;#t=0;#n=1;#r=new Set;constructor(e,t){this.update(t)}update(e){this.#n=e?.tooltip?.depth??1}insert(e){this.#r.add(e)}clear(){this.#r.forEach(e=>e.remove()),this.#r.clear()}refresh(){let e=Array.from(this.#r).map(e=>e.properties.dimensions);this.#e=e.reduce((e,t)=>Math.max(e,t.width+2*t.padding),0),this.#t=e.reduce((e,t)=>Math.max(e,t.height+2*t.padding),0)}render(e,t){let n=e.zoom,r=W.viewport(e,t.size,{top:this.#t,bottom:this.#t,right:this.#e,left:this.#e}),i=W.max(e.zoom,t.size,{top:this.#t,bottom:this.#t,right:this.#e,left:this.#e});for(let e of this.#r){let t=Number.isNaN(e.zoom);if(t||=n+this.#n<e.zoom,t||=r.contains(e.lat,e.lng)===!1,t||=i.contains(e.lat,e.lng)===!1,t){e.setDisplayed(!1);continue}if(e.shown&&e.zoom<=n){let t=e.findAngle(n);e.setDisplayed(!0),e.setCollapsed(!1),e.setAngle(t)}else e.setCollapsed(!0),e.getCollapsed()&&(e.setDisplayed(!1),e.setAngle(NaN))}}},q=class{#e;#t=!0;#n={top:0,bottom:0,left:0,right:0};#r=new Set;constructor(e,t){this.#e=e,this.update(t)}update(e){this.#t=e?.popup?.pan?.enabled??this.#t,this.#n={top:e?.popup?.pan?.padding?.top??this.#n.top,bottom:e?.popup?.pan?.padding?.bottom??this.#n.bottom,left:e?.popup?.pan?.padding?.left??this.#n.left,right:e?.popup?.pan?.padding?.right??this.#n.right}}insert(e){this.#r.add(e)}clear(){this.#r.forEach(e=>e.remove()),this.#r.clear()}show(e){if(!e.popup||!e.tooltip||!e.pin||(e.pin.shown=!1,e.tooltip.shown=!1,e.popup.angle=e.tooltip.angle,e.popup.shown=!0,this.#t===!1))return;let t=this.#e.getViewport(),n=this.#e.getParameters().size,r=t.bounds,i=t.zoom,a=e.popup,o=n*2**i,s=v.project(r.sw.lat,r.ne.lng,o),c=v.project(r.ne.lat,r.sw.lng,o),l={x:c.x+this.#n.left,y:c.y+this.#n.top},u={x:s.x-this.#n.right,y:s.y-this.#n.bottom},d=u.x-l.x,f=u.y-l.y,p=a.properties.dimensions,m=p.width+p.padding*8,h=p.height+p.padding*8,_=v.project(a.lat,a.lng,o),y=g.offsets(m,h,e.tooltip.angle),b=_.x+y.x,x=b+m,S=_.y+y.y,C=S+h,w=b-l.x,T=u.x-x,E=S-l.y,D=u.y-C,O=0;d<m?O=(w-T)/2:(w<0&&(O=w),T<0&&(O=-T));let k=0;f<h?k=(E-D)/2:(E<0&&(k=E),D<0&&(k=-D)),(O!==0||k!==0)&&this.#e.panBy(O,k)}hide(e){!e.popup||!e.tooltip||!e.pin||(e.pin.shown=!0,e.tooltip.shown=!0,e.popup.shown=!1)}render(){for(let e of this.#r)e.shown?(e.setDisplayed(!0),e.setCollapsed(!1),e.setAngle(e.angle)):(e.setCollapsed(!0),e.getCollapsed()&&(e.setDisplayed(!1),e.setAngle(NaN)))}},J=class{#e;#t;#n;#r;constructor(e,t){this.#e=new G(e,t),this.#t=new K(e,t),this.#n=new q(e,t),this.#r=[],F.attach()}update(e){this.#e.update(e),this.#t.update(e),this.#n.update(e)}insertElements(e){if(e.length!==0){for(let t=0;t<e.length;t++){let n=e[t].element;this.#r.push(n),this.#e.insert(n.pin),this.#t.insert(n.tooltip),n.popup!==void 0&&this.#n.insert(n.popup)}this.#e.refresh(),this.#t.refresh(),this.#e.draw()}}refreshElements(){this.#e.draw()}renderElements(e,t){this.#n.render(),this.#t.render(e,t),this.#e.render(e,t)}clearElements(){this.#r=[],this.#e.clear(),this.#t.clear(),this.#n.clear()}showPopup(e){for(let t=0;t<this.#r.length;t++){let n=this.#r[t];n.id===e?this.#n.show(n):this.#n.hide(n)}}hidePopup(){for(let e=0;e<this.#r.length;e++){let t=this.#r[e];this.#n.hide(t)}}},Y=class{#e;#t;#n;#r;constructor(e,t,n){this.#e=e,this.#t=t,this.#n=new Map,this.#r=n?.states?.cache?.enabled??!0}update(e){this.#r=e?.states?.cache?.enabled??!0}clearStates(){this.#n.clear()}async updateStates(e,t){if(t.length===0)return;if(t.length===1){t[0].update({zoom:0,directions:[{zoom:0,angle:b.initial}]});return}t.sort((e,t)=>e.info.id.localeCompare(t.info.id));let n=this.getStatesInputs(t),r=y.object(JSON.stringify(n)),i;this.#r&&(i=this.#n.get(r)),i===void 0&&(i=await this.getStatesResult(e,n)),this.#r&&this.#n.set(r,i);for(let e=0;e<t.length;e++){let n=t[e],r=i[e];n.update(r)}}getStatesInputs(e){return e.map(e=>{let t=e.info,n=e.properties.tooltip.dimensions;return{lat:t.lat,lng:t.lng,rank:t.rank,width:n.width+2*n.padding,height:n.height+2*n.padding}})}async getStatesResult(a,o){let s=S({parameters:a,items:o}),c=await x.async(async()=>await fetch(`https://5.1.api.maps.arenarium.dev/states`,{method:`POST`,headers:{[r]:window.location.origin+window.location.pathname,[n]:this.#e,[t]:this.#t,[i]:`1.5.8`,[e]:`application/octet-stream`},body:s}),{retry:{times:3,delay:500}});if(c.failed)throw c.error;let l=c.data;if(!l.ok)throw Error(await l.text());let u=l.headers.get(t);u&&(this.#t=u);let d=C(await l.arrayBuffer()),f=Array(d.length);for(let e=0;e<d.length;e++){let t=d[e];f[e]={zoom:t[0].zoom,directions:t}}return f}};const X=`1.5.8`;var Z=class e extends m{#e;#t;#n;#r;#i;#a;#o;constructor(e,t,n,r){super(),d(l,e),d(c,t),this.#e=e,this.#t=n,this.#n=new H(this.#t,this.#l.bind(this),this.#g.bind(this),this.#p.bind(this),this.#m.bind(this),this.#h.bind(this)),this.#r=new Map,this.#i=new E(this.#y.bind(this)),this.#a=new J(n,r),this.#o=new Y(e,t,r)}static async create(t,n,r){return await e.#s(t,n,r)}update(e){this.#f(e)}clear(){this.#d()}async updateMarkers(e){await this.#b(e)}async removeMarkers(){await this.#x()}showTooltip(e){this.#S(e)}showPopup(e){this.#C(e)}hidePopup(){this.#w()}static async#s(t,n,o){let s={key:t},c=await a.post(`https://5.1.api.maps.arenarium.dev/auth`,s,{headers:{[r]:window.location.origin+window.location.pathname,[i]:X}});this.#c(X,c.version)&&console.warn(`This version of @arenarium/maps is deprecated and may not work correctly. Please upgrade to the latest version.`);let l=c.jwt;if(!l)throw Error(`Failed to get api jwt`);return new e(t,l,n,o)}static#c(e,t){if(!t)return!1;let n=t.split(`.`),r=e.split(`.`);if(n.length!==r.length)return!0;let i=Number.parseInt(n.join(``)),a=Number.parseInt(r.join(``));return Number.isNaN(i)||Number.isNaN(a)?!1:a<i}#l(){return this.#t.getContainer().parentElement===null}#u(e,t){if(t instanceof Error){console.error(t);try{let n={level:o.Error,source:s.Library,title:e,content:{key:this.#e,version:X,name:t.name,message:t.message,cause:t.cause,stack:t.stack}};a.put(`https://5.1.api.maps.arenarium.dev/log`,n,{headers:{[r]:window.location.origin+window.location.pathname,[i]:X}})}catch(e){console.error(e)}}}#d(){this.#n.stop(),this.#i.stop(),this.#r.clear(),this.#o.clearStates(),this.#a.clearElements()}#f(e){this.#o.update(e),this.#a.update(e)}#p(){this.#i.run()}#m(){this.#i.run()}#h(){this.#w()}#g(e,t){this.#d(),this.#u(e,t)}#_(e){let t=[],n=this.#t.getContainer(),r=e=>{let t=document.createElement(`div`);t.style.position=`absolute`,t.style.visibility=`hidden`,t.style.width=`max-content`,t.style.zIndex=`-1`;try{return t.appendChild(e),n.appendChild(t),t.getBoundingClientRect()}finally{n.removeChild(t)}},i=(e,t)=>{if(t)return t;if(e){let t=r(e),n=t.width,i=t.height;return{radius:Math.max(n,i)/2,stroke:2}}else return{radius:8,stroke:2}},a=(e,t)=>{if(t)return t;let n=r(e),i=p(n.width),a=p(n.height);return{width:i,height:a,padding:Math.min(Math.round(Math.min(i,a)/4),8)}};for(let n=0;n<e.length;n++){let r=e[n],o={id:r.id,rank:r.rank??0,lat:f(r.lat),lng:f(r.lng)},s={initialize:r.pin?.initialize,content:r.pin?.element,style:r.pin?.style,dimensions:i(r.pin?.element,r.pin?.dimensions)},c={initialize:r.tooltip.initialize,content:r.tooltip.element,style:r.tooltip.style,dimensions:a(r.tooltip.element,r.tooltip.dimensions)},l;r.popup&&(l={initialize:r.popup.initialize,content:r.popup.element,style:r.popup.style,dimensions:a(r.popup.element,r.popup.dimensions)},r.tooltip.element.addEventListener(`click`,e=>{e.stopPropagation(),this.#C(r.id)}));let u=new B(this.#t,o,s,c,l);t.push(u)}return t}#v(e){d(u,e);let t=new Set;for(let n of e){if(t.has(n.id))throw Error(`Two or more markers have the same id`);t.add(n.id)}let n=new Set;for(let t of e){let e=`${f(t.lat)},${f(t.lng)}`;if(n.has(e))throw Error(`Two or more markers have the same coordinates`);n.add(e)}}#y(){try{if(this.#l())return!0;let e=this.#t.getParameters(),t=this.#t.getViewport();return this.#a.renderElements(t,e),!1}catch(e){return this.#d(),this.#u(`Failed to render markers`,e),!0}}async#b(e){this.#v(e);try{let t=[];for(let n=0;n<e.length;n++){let r=e[n];this.#r.has(r.id)||t.push(r)}let n=this.#_(t);for(let e=0;e<n.length;e++){let t=n[e];this.#r.set(t.info.id,t)}this.#a.insertElements(n),this.#i.run();let r=this.#t.getParameters(),i=Array.from(this.#r.values());await this.#o.updateStates(r,i),this.#a.refreshElements(),this.#i.run(),this.#n.start()}catch(e){throw this.#d(),this.#u(`Failed to update markers`,e),e}}async#x(){try{this.#r.clear(),this.#a.clearElements()}catch(e){throw this.#u(`Failed to remove markers`,e),e}}#S(e){if(!this.#l())try{let t=this.#r.get(e);if(!t)return;let n=t.info.lat,r=t.info.lng,i=t.state?.zoom;if(!i)return;this.#t.moveTo(n,r,i)}catch(e){throw this.#u(`Failed to show tooltip`,e),e}}#C(e){if(!this.#l())try{this.#a.showPopup(e)}catch(e){throw this.#a.hidePopup(),this.#u(`Failed to show popup`,e),e}finally{this.#i.run()}}#w(){if(!this.#l())try{this.#a.hidePopup()}catch(e){throw this.#u(`Failed to hide popup`,e),e}finally{this.#i.run()}}};export{Z as MapManager};
|
|
1
|
+
import{HEADER_CONTENT_TYPE as e,HEADER_JWT as t,HEADER_KEY as n,HEADER_URL as r,HEADER_VERSION as i}from"@arenarium/maps-core/map/headers";import*as a from"@arenarium/maps-core/http";import{LogLevel as o,LogSource as s,MapMarkerOrientation as c,MapMarkerOrientation as l,apiJwtSchema as u,apiKeySchema as d,mapMarkerPropertiesArraySchema as f,validate as p}from"@arenarium/maps-core/declarations/schemas";import{roundCoordinate as m,roundSize as h,stringCoordinate as g}from"@arenarium/maps-core/map/parse";import{IMapManager as _}from"@arenarium/maps-core/declarations/interfaces";import{MAP_ZOOM_SCALE as v}from"@arenarium/maps-core/map/constants";import*as y from"@arenarium/maps-core/map/anchor";import*as b from"@arenarium/maps-core/map/angles";import{transform as x}from"@arenarium/maps-core/color";import*as S from"@arenarium/maps-core/map/mercator";import*as C from"@arenarium/maps-core/hash";import*as w from"@arenarium/maps-core/attempt";import{inputEncode as T,outputDecode as E}from"@arenarium/maps-core/map/states";const D=.1,O=.2;var k=class{#e=!1;#t=!1;#n;#r;#i;constructor(e,t){if((t??0)<0)throw Error(`Invalid interval`);this.#n=t??100/Math.max(4,navigator?.hardwareConcurrency??1),this.#i=e}async process(){this.#e=!1,this.#i()||!this.#e?this.stop():this.#r=window.setTimeout(this.process.bind(this),this.#n)}run(){this.#e=!0,this.#t||(this.#t=!0,this.#r=window.setTimeout(this.process.bind(this),0))}stop(){this.#e=!1,this.#t=!1,this.#r&&window.clearTimeout(this.#r),this.#r=void 0}},A=class e{static attached=!1;static uuid;constructor(){if(!e.attached||!e.uuid)throw Error(`Component must be attached before use!`)}static getStyle(){throw Error(`Component must implement getStyle!`)}static attach(){let t=this.getStyle().replace(/\/\*[\s\S]*?\*\//g,``).replace(/\s*([{}|:;,])\s*/g,`$1`).replace(/\s+/g,` `).trim(),n=Date.now().toString(),r=new CSSStyleSheet;r.replaceSync(t.replaceAll(`uuid`,n)),document.adoptedStyleSheets=document.adoptedStyleSheets.concat(r),e.uuid=n,e.attached=!0}},j=class{#e;#t;#n;#r;#i;#a;#o;#s;#c;constructor(e){if(e.value<0||1<e.value)throw Error(`Invalid value`);this.#e=!1,this.#t=0,this.#n=0,this.#r=e.easing,this.#i=e.callback,this.#a=e.value,this.#o=e.value,this.#s=e.timespan,this.#c=!1}target(e){if(e===this.#o)return;this.#o=e,this.#c=this.#a<this.#o;let t=performance.now(),n=this.#s*Math.abs(e-this.#a);this.#t=t+n,!this.#e&&window.requestAnimationFrame(this.#l.bind(this))}set(e){this.#a=e,this.#o=e,this.#t=performance.now(),this.#e=!1,window.requestAnimationFrame(()=>this.#i(this.#r(e)))}end(){this.set(this.#o)}expired(){return performance.now()>this.#t}#l(e){if(this.#e===!1){this.#n=e,this.#e=!0,window.requestAnimationFrame(this.#l.bind(this));return}let t=e>=this.#t;t===!0&&(this.#a=this.#o);let n=this.#a===this.#o;if(n===!1){let t=(e-this.#n)/this.#s,r=this.#c?Math.min(this.#a+t,this.#o):Math.max(this.#a-t,this.#o);this.#a=r,n=r===this.#o}if(this.#i(this.#r(this.#a)),this.#n=e,t===!0||n===!0){this.#e=!1;return}window.requestAnimationFrame(this.#l.bind(this))}},M=`.pin-uuid{box-sizing:border-box;transform-origin:0 0;backface-visibility:hidden;will-change:scale, opacity;justify-content:center;align-items:center;display:flex;position:absolute;transform:translate(-50%,-50%)}
|
|
2
|
+
`,N=class e extends A{#e;#t;#n;#r;#i=!1;#a=!1;#o=!0;#s=0;#c=1;#l=new j({value:0,timespan:75,easing:this.#u.bind(null),callback:this.#d.bind(this)});constructor(t,n){super();let r=n.style,i=n.dimensions,a=i.radius*2,o=i.stroke,s=r?.background??`#008800`,c=r?.stroke??`#ffffff`,l=r?.shadow??`0px 2px 2px rgba(0, 0, 0, 0.5)`,u=document.createElement(`div`);u.classList.add(`pin-${e.uuid}`),u.style.width=`${a}px`,u.style.height=`${a}px`,u.style.borderRadius=`${a}px`,u.style.border=`solid ${o}px ${c}`,u.style.background=s,u.style.boxShadow=l,u.style.scale=`0`,u.style.filter=`brightness(${this.#f(0)})`,this.#e=t,this.#t=n.content,this.#n=n.initialize,this.#r=u}static getStyle(){return M}getElement(){return this.#r}setDisplayed(e){e===!0&&(this.#r&&this.#t&&this.#t.parentElement!==this.#r&&this.#r.appendChild(this.#t),this.#i===!1&&this.#n&&this.#t&&(this.#i=!0,setTimeout(this.#n.bind(this,this.#e,this.#t),0))),this.#a!==e&&(this.#a=e,this.#r.style.display=e?`flex`:`none`,this.#r.style.contentVisibility=e?`visible`:`hidden`,e===!1&&this.#l.end())}getDisplayed(){return this.#a}setCollapsed(e){this.#o!==e&&(this.#o=e,this.#l.target(this.#o?0:this.#s))}getCollapsed(){return this.#a?this.#l.expired():!0}setScale(e,t){this.#s=e,this.#c=t,this.#l.target(e)}#u(e){return e}#d(e){this.#r.style.scale=e.toString(),this.#r.style.opacity=e.toString(),this.#r.style.filter=`brightness(${this.#f(e)})`}#f(e){return 1-this.#c*(1-e)}},P=class{value;target;speed;min;max;constructor(e){this.value=e.value,this.target=e.value,this.speed=0,this.min=e.min,this.max=e.max}set(e){this.value=e,this.target=e,this.speed=0}snap(){this.value=this.target,this.speed=0}frame(e,t,n,r){if(this.value===this.target)return!0;let i=this.target-this.value;if(Math.abs(i)<t)return!0;let a=i*n-this.speed*r;return this.speed+=a*e,this.value+=this.speed*e,this.value<this.min||this.value>this.max}},F=class{#e;#t;#n;#r;#i;#a;#o;#s;#c;constructor(e){this.#e=!1,this.#t=0,this.#n=0,this.#r=e.callback,this.#i=e.stiffness,this.#a=e.damping,this.#o=e.precision,this.#s=new P(e.x),this.#c=new P(e.y)}target(e,t){if(this.#s.target==e&&this.#c.target==t)return;this.#s.target=e,this.#c.target=t;let n=performance.now(),r=Math.sqrt((e-this.#s.value)**2+(t-this.#c.value)**2),i=2*Math.sqrt(2*Math.abs(r)/this.#i);this.#n=n,this.#t=n+i,this.#e===!1&&(this.#e=!0,window.requestAnimationFrame(this.#l.bind(this)))}set(e,t){this.#s.set(e),this.#c.set(t);let n=performance.now();this.#n=n,this.#t=n,this.#e=!1,window.requestAnimationFrame(()=>this.#r(this.#s.value,this.#c.value))}end(){this.set(this.#s.target,this.#c.target)}expired(){return performance.now()>this.#t}#l(e){let t=!1,n=!1;try{if(e>=this.#t){t=!0,n=!0;return}let r=Math.min(30,e-this.#n);t=this.#s.frame(r,this.#o,this.#i,this.#a),n=this.#c.frame(r,this.#o,this.#i,this.#a)}finally{t===!0&&this.#s.snap(),n===!0&&this.#c.snap(),this.#r(this.#s.value,this.#c.value),this.#n=e,t===!1||n===!1?window.requestAnimationFrame(this.#l.bind(this)):this.#e=!1}}},I=`.element-uuid{box-sizing:border-box;transform-style:flat;transform-origin:0 0;width:0;height:0;position:absolute}.anchor-uuid{will-change:opacity, scale}.pointer-uuid,.bubble-uuid{will-change:transform}.body-uuid{display:initial;cursor:pointer;will-change:opacity;width:max-content}.body-uuid:hover{display:contents}
|
|
3
|
+
`,L=class e extends A{#e;#t;#n;#r;#i;#a;#o;#s;#c;#l;#u;#d;#f;#p;#m;#h;#g;#_=!1;#v=!1;#y=!0;#b;#x=NaN;#S=!1;#C;constructor(t,n){super();let r=n.dimensions,i=n.style,a=r.width+2*r.padding,o=r.height+2*r.padding,s=r.padding,c=r.width,l=r.height,u=i?.background??`#ffffff`,d=Math.min(i?.radius??8,Math.min(c,l)/2),f=Math.min(1,2*d/Math.min(l,c)),p=r.width,m=r.height,h=i?.radius??0,g=r.padding*2,_=Math.min(3,.5*d),v=i?.background??`#ffffff`,y=o<a?o/a:1,b=a<o?a/o:1,x=Math.min(a,o)/2,S=x*Math.SQRT2,C=15*Math.SQRT2,w=document.createElement(`div`);w.classList.add(`element-${e.uuid}`),w.classList.add(`body-${e.uuid}`),w.style.width=`${p}px`,w.style.height=`${m}px`,w.style.borderRadius=`${h}px`,w.style.opacity=`0`,this.#g=w;let T=document.createElement(`div`);T.classList.add(`element-${e.uuid}`),T.classList.add(`bubble-${e.uuid}`),T.style.width=`${c}px`,T.style.height=`${l}px`,T.style.borderRadius=`${d}px`,T.style.backgroundColor=`rgb(from ${u} r g b / 1)`,T.appendChild(w);let E=document.createElement(`div`);E.classList.add(`element-${e.uuid}`),E.classList.add(`pointer-${e.uuid}`),E.style.width=`${g}px`,E.style.height=`${g}px`,E.style.borderRadius=`${_}px`,E.style.backgroundColor=`rgb(from ${v} r g b / 1)`;let O=document.createElement(`div`);O.classList.add(`element-${e.uuid}`),O.classList.add(`anchor-${e.uuid}`),O.style.filter=i?.filter??`drop-shadow(0px 2px 2px rgba(0, 0, 0, 0.5))`,O.style.scale=`0`,O.style.opacity=`0`,O.appendChild(E),O.appendChild(T),this.#e=t,this.#t=n.content,this.#n=n.initialize,this.#r=a,this.#i=o,this.#a=s,this.#o=O,this.#s=E,this.#c=y,this.#l=b,this.#d=x,this.#u=S,this.#f=15,this.#p=C,this.#m=T,this.#h=f;let k=Math.min(4,1+3*(r.width*r.height)/65536),A=25e-5/k;this.#b=new j({value:0,timespan:125*Math.cbrt(k),easing:this.#w.bind(null),callback:this.#T.bind(this)}),this.#C=new F({stiffness:A,damping:2*Math.sqrt(A),precision:1,x:{value:-a/2,min:-a-a*D,max:a*D},y:{value:-o/2,min:-o-o*D,max:o*D},callback:this.#D.bind(this)})}static getStyle(){return I}getElement(){return this.#o}setDisplayed(e){this.#v!==e&&(this.#v=e,e===!0&&(this.#t&&this.#t.parentElement!==this.#g&&this.#g.appendChild(this.#t),this.#_===!1&&this.#n&&this.#t&&(this.#_=!0,setTimeout(this.#n.bind(this,this.#e,this.#t),0))),this.#o.style.display=e?`initial`:`none`,this.#o.style.contentVisibility=e?`visible`:`hidden`,e===!1&&(this.#b.end(),this.#C.end()))}getDisplayed(){return this.#v}setCollapsed(e){this.#y!==e&&(this.#y=e,this.#b.target(+!e))}getCollapsed(){return this.#v?this.#b.expired():!0}#w(e){return-.5*(Math.cos(Math.PI*e)-1)}#T(e){this.#o.style.opacity=`${e}`,this.#o.style.scale=`${e}`,this.#g.style.opacity=`${e}`}setAngle(e){if(Number.isNaN(e)){this.#x=NaN,this.#S=!1;return}if(this.#S===!1){this.#S=!0,this.#x=e;let t=this.#E(e);this.#C.set(Math.round(t.x),Math.round(t.y));return}if(this.#x!==e){this.#x=e;let t=this.#E(e);this.#C.target(Math.round(t.x),Math.round(t.y));return}}#E(e){return e===b.none?y.center(this.#r,this.#i):y.offsets(this.#r,this.#i,e)}#D(e,t){let n=e+this.#r/2,r=t+this.#i/2,i=n*this.#c,a=r*this.#l,o=Math.sqrt(i*i+a*a),s=(o-this.#d)/(this.#u-this.#d),c=Math.atan2(a,i)/Math.PI*180-45,l=this.#f+s*(this.#p-this.#f),u=o<this.#d?o/this.#d:1,d=.5*((1+.5*this.#h)*s),f=e+this.#a*(1-d*(i/this.#d)),p=t+this.#a*(1-d*(a/this.#d));this.#s.style.transform=`scale(${u}) rotate(${c}deg) skew(${l}deg, ${l}deg)`,this.#m.style.transform=`translate(${Math.round(f)}px, ${Math.round(p)}px)`}},R=class{id;pin;tooltip;popup;constructor(e,t,n,r,i){this.id=t.id,this.pin=new B(e,t,n),this.tooltip=new V(e,t,r),this.popup=i?new H(e,t,i):void 0}update(e){this.pin.update(e),this.tooltip.update(e)}remove(){this.pin.remove(),this.tooltip.remove(),this.popup?.remove()}static attach(){N.attach(),L.attach()}},z=class{id;lat;lng;rank;shown=!0;displayed=!1;component;marker;constructor(e,t,n){this.id=t.id,this.lat=t.lat,this.lng=t.lng,this.rank=t.rank;let r=n.getElement(),i=document.createElement(`div`);i.appendChild(r),this.component=n,this.marker=e.createMarker({element:i,lat:t.lat,lng:t.lng,z:this.getZIndex()})}remove(){this.component.setDisplayed(!1),this.marker.remove()}setCollapsed(e){this.component.setCollapsed(e)}getCollapsed(){return this.component.getCollapsed()}getDisplayed(){return this.displayed}setDisplayed(e){this.displayed!==e&&(this.displayed=e,e?(this.component.setDisplayed(!0),this.marker.insert()):(this.component.setDisplayed(!1),this.marker.remove()))}},B=class extends z{properties;zoom=NaN;constructor(e,t,n){let r=new N(t.id,n);super(e,t,r),this.properties=n}update(e){e?this.zoom=e.zoom:this.zoom=NaN,this.marker.update(this.getZIndex())}getZIndex(){return this.zoom===void 0||Number.isNaN(this.zoom)?this.rank:Math.round(-this.zoom*v)+1e6}setScale(e,t){this.component.setScale(e,t)}},V=class extends z{properties;zoom=NaN;angle=NaN;directions=[];constructor(e,t,n){let r=new L(t.id,n);super(e,t,r),this.properties=n}update(e){e?(this.zoom=e.zoom,this.directions=e.directions):(this.zoom=NaN,this.directions=[]),this.marker.update(this.getZIndex())}getZIndex(){return this.zoom===void 0||Number.isNaN(this.zoom)?this.rank:Math.round(-this.zoom*v)+2e6}findAngle(e){let t=this.directions.findLast(t=>t.zoom<=e)?.angle;if(t===void 0)throw Error(`Failed to find angle`);return t}setAngle(e){this.angle=e,this.component.setAngle(e)}},H=class extends z{properties;angle=NaN;constructor(e,t,n){let r=new L(t.id,n);super(e,t,r),this.shown=!1,this.properties=n}getZIndex(){return 3e6}setAngle(e){this.angle=e,this.component.setAngle(e)}},U=class{info;properties;element;state;constructor(e,t,n,r,i){this.info=t,this.properties={pin:n,tooltip:r,popup:i},this.element=new R(e,t,n,r,i)}update(e){this.state=e,this.element.update(e)}},W=class{#e;#t;#n;constructor(e,t){if(t<=0)throw Error(`Invalid timeout`);this.#e=e,this.#t=t}start(){this.#n===void 0&&(this.#n=window.setInterval(this.#e,this.#t))}stop(){this.#n!==void 0&&(window.clearInterval(this.#n),this.#n=void 0)}running(){return this.#n!==void 0}},G=class{#e=void 0;#t=`idle`;#n;#r;#i;#a;#o;#s;#c;constructor(e,t,n,r,i,a){this.#n=e,this.#r=new W(this.#l.bind(this),100/Math.max(4,navigator?.hardwareConcurrency??1)),this.#i=t,this.#a=n,this.#o=r,this.#s=i,this.#c=a}#l(){try{if(this.#i()){this.#r.stop();return}let e=this.#n.getViewport(),t=this.#t,n=JSON.stringify(e)===JSON.stringify(this.#e)?`idle`:`move`;n===`move`&&this.#o(),n===`idle`&&t===`move`&&this.#s(),this.#t=n,this.#e=e}catch(e){this.#a(`Failed to process map state interval`,e)}}start(){this.#r.running()===!1&&(this.#r.start(),this.#n.getContainer().addEventListener(`click`,this.#c))}stop(){this.#r.running()===!0&&(this.#r.stop(),this.#n.getContainer().removeEventListener(`click`,this.#c))}idle(){return this.#t===`idle`}},K=class{#e;#t;constructor(e,t,n,r){if(n<e)throw Error(`Invalid bounds: swLat: ${e}, neLat: ${n}`);if(r<t)throw Error(`Invalid bounds: swLng: ${t}, neLng: ${r}`);this.#e={lat:e,lng:t},this.#t={lat:n,lng:r}}contains(e,t){return!(e<this.#e.lat||this.#t.lat<e||t<this.#e.lng||this.#t.lng<t)}intersects(e){return!(e.ne.lat<this.#e.lat||this.#t.lat<e.sw.lat||e.ne.lng<this.#e.lng||this.#t.lng<e.sw.lng)}},q=class e{#e;#t;constructor(e,t,n,r){if(t<180&&180<r){this.#e=new K(e,t,n,180),this.#t=new K(e,-180,n,r-360);return}if(t<-180&&-180<r){this.#e=new K(e,360+t,n,180),this.#t=new K(e,-180,n,r);return}this.#e=new K(e,t,n,r),this.#t=new K(0,0,0,0)}static normalize(e){let t=e.bounds,n=e.center;if(t.ne.lng-t.sw.lng>360)return{sw:{lat:t.sw.lat,lng:-180},ne:{lat:t.ne.lat,lng:180}};if(t.sw.lng>t.ne.lng)return t.sw.lng+t.ne.lng<0?{sw:{lat:t.sw.lat,lng:t.sw.lng},ne:{lat:t.ne.lat,lng:t.ne.lng+360}}:{sw:{lat:t.sw.lat,lng:t.sw.lng-360},ne:{lat:t.ne.lat,lng:t.ne.lng}};if(-180<=n.lng&&n.lng<=180){let e=Math.abs(t.ne.lng-n.lng),r=Math.abs(t.sw.lng-n.lng);if(e+r>360)return{sw:{lat:t.sw.lat,lng:-180},ne:{lat:t.ne.lat,lng:180}};if(t.sw.lng<=n.lng&&t.ne.lng<=n.lng||t.sw.lng>=n.lng&&t.ne.lng>=n.lng)return{sw:{lat:t.sw.lat,lng:n.lng-e},ne:{lat:t.ne.lat,lng:n.lng+r}}}return e.bounds}static create(t){let n=this.normalize(t),r=n.sw,i=n.ne;return new e(r.lat,r.lng,i.lat,i.lng)}static viewport(t,n,r){let i=this.normalize(t),a=n*2**t.zoom,o=S.project(i.sw.lat,i.sw.lng,a),s=S.project(i.ne.lat,i.ne.lng,a),c=Math.min(o.y+r.bottom,a),l=Math.max(s.y-r.top,0),u=o.x-r.left,d=s.x+r.right;d-u>a&&(u=0,d=a),d<u&&(d=u=(s.x-o.x)/2);let f=S.unproject(u,c,a),p=S.unproject(d,l,a);return new e(f.lat,f.lng,p.lat,p.lng)}static max(t,n,r){let i=n*2**t,a=r.left,o=i-r.bottom,s=i-r.right,c=r.top,l=S.unproject(a,o,i),u=S.unproject(s,c,i);return new e(l.lat,l.lng,u.lat,u.lng)}contains(e,t){return this.#e.contains(e,t)||this.#t.contains(e,t)}intersects(e){return this.#e.intersects(e)||this.#t.intersects(e)}},J=class{#e;#t=0;#n=O;#r=O;#i=1;#a=1;#o=3;#s=3;#c=new Set;constructor(e,t){this.#e=e,this.update(t)}update(e){this.#n=e?.pin?.fadeout?.color??.2,this.#r=e?.pin?.fadeout?.scale??.2,this.#i=e?.pin?.fadeout?.opacity??1,this.#a=this.#n<this.#r?this.#n/this.#r:1,this.#o=e?.pin?.depth??3,this.#s=this.#o}insert(e){this.#c.add(e)}clear(){this.#c.forEach(e=>e.remove()),this.#c.clear(),this.#e.updateCircles([],this.#o)}refresh(){let e=Array.from(this.#c);this.#t=e.reduce((e,t)=>Math.max(e,t.properties.dimensions.radius*2),0),this.#s=Math.max(1,this.#o-Math.log10(e.length))}draw(){let e=Array.from(this.#c),t=[];for(let n=0;n<e.length;n++){let r=e[n],i=Math.max(0,Math.min(1,this.#n*this.#o)),a=Math.max(0,Math.min(1,this.#r*this.#o)),o=Math.max(0,Math.min(1,this.#i*this.#o)),s=r.properties.style?.background??`#008800`,c=x(s,0,1),l=x(s,i,o),u=r.properties.dimensions.radius-r.properties.dimensions.stroke,d=u*(1-a),f=r.properties.style?.stroke??`#ffffff`,p=x(f,0,1),m=x(f,i,o),h=r.properties.dimensions.stroke,g=h*(1-a),_={color:{min:l,max:c},radius:{min:d,max:u},stroke:{color:{min:m,max:p},width:{min:g,max:h}},lat:r.lat,lng:r.lng,rank:r.rank,zoom:r.zoom};t.push(_)}this.#e.updateCircles(t,this.#o)}render(e,t){let n=e.zoom,r=q.viewport(e,t.size,{top:this.#t,bottom:this.#t,right:this.#t,left:this.#t});for(let e of this.#c){let t=Number.isNaN(e.zoom);if(t||=n+this.#s<e.zoom,t||=r.contains(e.lat,e.lng)===!1,t){e.setDisplayed(!1);continue}if(e.shown&&n<e.zoom){let t=(e.zoom-n)/this.#s,r=Math.max(0,1-t*this.#r),i=this.#a;e.setDisplayed(!0),e.setCollapsed(!1),e.setScale(r,i)}else e.setCollapsed(!0),e.getCollapsed()&&e.setDisplayed(!1)}}},Y=class{#e=0;#t=0;#n=1;#r=new Set;constructor(e,t){this.update(t)}update(e){this.#n=e?.tooltip?.depth??1}insert(e){this.#r.add(e)}clear(){this.#r.forEach(e=>e.remove()),this.#r.clear()}refresh(){let e=Array.from(this.#r).map(e=>e.properties.dimensions);this.#e=e.reduce((e,t)=>Math.max(e,t.width+2*t.padding),0),this.#t=e.reduce((e,t)=>Math.max(e,t.height+2*t.padding),0)}render(e,t){let n=e.zoom,r=q.viewport(e,t.size,{top:this.#t,bottom:this.#t,right:this.#e,left:this.#e}),i=q.max(e.zoom,t.size,{top:this.#t,bottom:this.#t,right:this.#e,left:this.#e});for(let e of this.#r){let t=Number.isNaN(e.zoom);if(t||=n+this.#n<e.zoom,t||=r.contains(e.lat,e.lng)===!1,t||=i.contains(e.lat,e.lng)===!1,t){e.setDisplayed(!1);continue}if(e.shown&&e.zoom<=n){let t=e.findAngle(n);e.setDisplayed(!0),e.setCollapsed(!1),e.setAngle(t)}else e.setCollapsed(!0),e.getCollapsed()&&(e.setDisplayed(!1),e.setAngle(NaN))}}},X=class{#e;#t=!0;#n={top:0,bottom:0,left:0,right:0};#r=new Set;constructor(e,t){this.#e=e,this.update(t)}update(e){this.#t=e?.popup?.pan?.enabled??this.#t,this.#n={top:e?.popup?.pan?.padding?.top??this.#n.top,bottom:e?.popup?.pan?.padding?.bottom??this.#n.bottom,left:e?.popup?.pan?.padding?.left??this.#n.left,right:e?.popup?.pan?.padding?.right??this.#n.right}}insert(e){this.#r.add(e)}clear(){this.#r.forEach(e=>e.remove()),this.#r.clear()}show(e){if(!e.popup||!e.tooltip||!e.pin||(e.pin.shown=!1,e.tooltip.shown=!1,e.popup.angle=e.tooltip.angle,e.popup.shown=!0,this.#t===!1))return;let t=this.#e.getViewport(),n=this.#e.getParameters().size,r=t.bounds,i=t.zoom,a=e.popup,o=n*2**i,s=S.project(r.sw.lat,r.ne.lng,o),c=S.project(r.ne.lat,r.sw.lng,o),l={x:c.x+this.#n.left,y:c.y+this.#n.top},u={x:s.x-this.#n.right,y:s.y-this.#n.bottom},d=u.x-l.x,f=u.y-l.y,p=a.properties.dimensions,m=p.width+p.padding*8,h=p.height+p.padding*8,g=S.project(a.lat,a.lng,o),_=y.offsets(m,h,e.tooltip.angle),v=g.x+_.x,b=v+m,x=g.y+_.y,C=x+h,w=v-l.x,T=u.x-b,E=x-l.y,D=u.y-C,O=0;d<m?O=(w-T)/2:(w<0&&(O=w),T<0&&(O=-T));let k=0;f<h?k=(E-D)/2:(E<0&&(k=E),D<0&&(k=-D)),(O!==0||k!==0)&&this.#e.panBy(O,k)}hide(e){!e.popup||!e.tooltip||!e.pin||(e.pin.shown=!0,e.tooltip.shown=!0,e.popup.shown=!1)}render(){for(let e of this.#r)e.shown?(e.setDisplayed(!0),e.setCollapsed(!1),e.setAngle(e.angle)):(e.setCollapsed(!0),e.getCollapsed()&&(e.setDisplayed(!1),e.setAngle(NaN)))}},Z=class{#e;#t;#n;#r;constructor(e,t){this.#e=new J(e,t),this.#t=new Y(e,t),this.#n=new X(e,t),this.#r=[],R.attach()}update(e){this.#e.update(e),this.#t.update(e),this.#n.update(e)}insertElements(e){if(e.length!==0){for(let t=0;t<e.length;t++){let n=e[t].element;this.#r.push(n),this.#e.insert(n.pin),this.#t.insert(n.tooltip),n.popup!==void 0&&this.#n.insert(n.popup)}this.#e.refresh(),this.#t.refresh(),this.#e.draw()}}refreshElements(){this.#e.draw()}renderElements(e,t){this.#n.render(),this.#t.render(e,t),this.#e.render(e,t)}clearElements(){this.#r=[],this.#e.clear(),this.#t.clear(),this.#n.clear()}showPopup(e){for(let t=0;t<this.#r.length;t++){let n=this.#r[t];n.id===e?this.#n.show(n):this.#n.hide(n)}}hidePopup(){for(let e=0;e<this.#r.length;e++){let t=this.#r[e];this.#n.hide(t)}}},Q=class{#e;#t;#n;#r;constructor(e,t,n){this.#e=e,this.#t=t,this.#n=new Map,this.#r=n?.states?.cache?.enabled??!0}update(e){this.#r=e?.states?.cache?.enabled??!0}clearStates(){this.#n.clear()}async updateStates(e,t){if(t.length===0)return;if(t.length===1){t[0].update({zoom:0,directions:[{zoom:0,angle:b.initial}]});return}t.sort((e,t)=>e.info.id.localeCompare(t.info.id));let n=this.getStatesInputs(e,t),r=C.object(JSON.stringify(n)),i;this.#r&&(i=this.#n.get(r)),i===void 0&&(i=await this.getStatesResult(e,n)),this.#r&&this.#n.set(r,i);for(let e=0;e<t.length;e++){let n=t[e],r=i[e];n.update(r)}}getStatesInputs(e,t){return t.map(t=>{let n=t.info,r=t.properties.tooltip.dimensions,i=S.project(n.lat,n.lng,e.size);return{x:i.x,y:i.y,width:r.width+2*r.padding,height:r.height+2*r.padding,rank:n.rank,orientation:n.orientation}})}async getStatesResult(a,o){let s=T({parameters:a,items:o}),c=await w.async(async()=>await fetch(`https://5.1.api.maps.arenarium.dev/states`,{method:`POST`,headers:{[r]:window.location.origin+window.location.pathname,[n]:this.#e,[t]:this.#t,[i]:`1.5.10`,[e]:`application/octet-stream`},body:s}),{retry:{times:3,delay:500}});if(c.failed)throw c.error;let l=c.data;if(!l.ok)throw Error(await l.text());let u=l.headers.get(t);u&&(this.#t=u);let d=E(await l.arrayBuffer()),f=Array(d.length);for(let e=0;e<d.length;e++){let t=d[e];f[e]={zoom:t[0].zoom,directions:t}}return f}};const $=`1.5.10`;var ee=class e extends _{#e;#t;#n;#r;#i;#a;#o;constructor(e,t,n,r){super(),p(d,e),p(u,t),this.#e=e,this.#t=n,this.#n=new G(this.#t,this.#l.bind(this),this.#g.bind(this),this.#p.bind(this),this.#m.bind(this),this.#h.bind(this)),this.#r=new Map,this.#i=new k(this.#y.bind(this)),this.#a=new Z(n,r),this.#o=new Q(e,t,r)}static async create(t,n,r){return await e.#s(t,n,r)}update(e){this.#f(e)}clear(){this.#d()}async updateMarkers(e){await this.#b(e)}async removeMarkers(){await this.#x()}showTooltip(e){this.#S(e)}showPopup(e){this.#C(e)}hidePopup(){this.#w()}static async#s(t,n,o){let s={key:t},c=await a.post(`https://5.1.api.maps.arenarium.dev/auth`,s,{headers:{[r]:window.location.origin+window.location.pathname,[i]:$}});this.#c($,c.version)&&console.warn(`This version of @arenarium/maps is deprecated and may not work correctly. Please upgrade to the latest version.`);let l=c.jwt;if(!l)throw Error(`Failed to get api jwt`);return new e(t,l,n,o)}static#c(e,t){if(!t)return!1;let n=t.split(`.`),r=e.split(`.`);if(n.length!==r.length)return!0;let i=Number.parseInt(n.join(``)),a=Number.parseInt(r.join(``));return Number.isNaN(i)||Number.isNaN(a)?!1:a<i}#l(){return this.#t.getContainer().parentElement===null}#u(e,t){if(t instanceof Error){console.error(t);try{let n={level:o.Error,source:s.Library,title:e,content:{key:this.#e,version:$,name:t.name,message:t.message,cause:t.cause,stack:t.stack}};a.put(`https://5.1.api.maps.arenarium.dev/log`,n,{headers:{[r]:window.location.origin+window.location.pathname,[i]:$}})}catch(e){console.error(e)}}}#d(){this.#n.stop(),this.#i.stop(),this.#r.clear(),this.#o.clearStates(),this.#a.clearElements()}#f(e){this.#o.update(e),this.#a.update(e)}#p(){this.#i.run()}#m(){this.#i.run()}#h(){this.#w()}#g(e,t){this.#d(),this.#u(e,t)}#_(e){let t=[],n=this.#t.getContainer(),r=e=>{let t=document.createElement(`div`);t.style.position=`absolute`,t.style.visibility=`hidden`,t.style.width=`max-content`,t.style.zIndex=`-1`;try{return t.appendChild(e),n.appendChild(t),t.getBoundingClientRect()}finally{n.removeChild(t)}},i=(e,t)=>{if(t)return t;if(e){let t=r(e),n=t.width,i=t.height;return{radius:Math.max(n,i)/2,stroke:2}}else return{radius:8,stroke:2}},a=(e,t)=>{if(t)return t;let n=r(e),i=h(n.width),a=h(n.height);return{width:i,height:a,padding:Math.min(Math.round(Math.min(i,a)/4),8)}};for(let n=0;n<e.length;n++){let r=e[n],o={id:r.id,lat:m(r.lat),lng:m(r.lng),rank:r.rank??1,orientation:r.orientation??l.Dynamic},s={initialize:r.pin?.initialize,content:r.pin?.element,style:r.pin?.style,dimensions:i(r.pin?.element,r.pin?.dimensions)},c={initialize:r.tooltip.initialize,content:r.tooltip.element,style:r.tooltip.style,dimensions:a(r.tooltip.element,r.tooltip.dimensions)},u;r.popup&&(u={initialize:r.popup.initialize,content:r.popup.element,style:r.popup.style,dimensions:a(r.popup.element,r.popup.dimensions)},r.tooltip.element.addEventListener(`click`,e=>{e.stopPropagation(),this.#C(r.id)}));let d=new U(this.#t,o,s,c,u);t.push(d)}return t}#v(e){p(f,e);let t=new Set;for(let n of e){if(t.has(n.id))throw Error(`Two markers have the same id: ${n.id}`);t.add(n.id)}let n=new Set;for(let t of e){let e=`${g(t.lat)},${g(t.lng)}`;if(n.has(e))throw Error(`Two or more markers have the same coordinates: ${e}`);n.add(e)}}#y(){try{if(this.#l())return!0;let e=this.#t.getParameters(),t=this.#t.getViewport();return this.#a.renderElements(t,e),!1}catch(e){return this.#d(),this.#u(`Failed to render markers`,e),!0}}async#b(e){this.#v(e);try{let t=[];for(let n=0;n<e.length;n++){let r=e[n];this.#r.has(r.id)||t.push(r)}let n=this.#_(t);for(let e=0;e<n.length;e++){let t=n[e];this.#r.set(t.info.id,t)}this.#a.insertElements(n),this.#i.run();let r=this.#t.getParameters(),i=Array.from(this.#r.values());await this.#o.updateStates(r,i),this.#a.refreshElements(),this.#i.run(),this.#n.start()}catch(e){throw this.#d(),this.#u(`Failed to update markers`,e),e}}async#x(){try{this.#r.clear(),this.#a.clearElements()}catch(e){throw this.#u(`Failed to remove markers`,e),e}}#S(e){if(!this.#l())try{let t=this.#r.get(e);if(!t)return;let n=t.info.lat,r=t.info.lng,i=t.state?.zoom;if(!i)return;this.#t.moveTo(n,r,i)}catch(e){throw this.#u(`Failed to show tooltip`,e),e}}#C(e){if(!this.#l())try{this.#a.showPopup(e)}catch(e){throw this.#a.hidePopup(),this.#u(`Failed to show popup`,e),e}finally{this.#i.run()}}#w(){if(!this.#l())try{this.#a.hidePopup()}catch(e){throw this.#u(`Failed to hide popup`,e),e}finally{this.#i.run()}}};export{ee as MapManager,c as MapMarkerOrientation};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@arenarium/maps",
|
|
3
|
-
"version": "1.5.
|
|
3
|
+
"version": "1.5.10",
|
|
4
4
|
"description": "Visualize complex map markers clearly. A JavaScript library for effective display of map markers, compatible with MapLibre, Mapbox, and Google Maps.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"arenarium",
|
|
@@ -24,7 +24,7 @@
|
|
|
24
24
|
"./package.json": "./package.json"
|
|
25
25
|
},
|
|
26
26
|
"dependencies": {
|
|
27
|
-
"@arenarium/maps-core": "1.1.
|
|
27
|
+
"@arenarium/maps-core": "1.1.6"
|
|
28
28
|
},
|
|
29
29
|
"devDependencies": {
|
|
30
30
|
"vite": "npm:@voidzero-dev/vite-plus-core@^0.2.3",
|