@xyo-network/react-map 2.78.0 → 2.78.2
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/browser/index.cjs +1330 -2
- package/dist/browser/index.cjs.map +1 -1
- package/dist/browser/index.js +1307 -2
- package/dist/browser/index.js.map +1 -1
- package/dist/neutral/index.cjs +1330 -2
- package/dist/neutral/index.cjs.map +1 -1
- package/dist/neutral/index.js +1307 -2
- package/dist/neutral/index.js.map +1 -1
- package/dist/node/index.cjs +1387 -2
- package/dist/node/index.cjs.map +1 -1
- package/dist/node/index.js +1310 -2
- package/dist/node/index.js.map +1 -1
- package/package.json +13 -13
package/dist/browser/index.cjs
CHANGED
|
@@ -1,3 +1,1331 @@
|
|
|
1
|
-
"use strict";var Me=Object.defineProperty;var $t=Object.getOwnPropertyDescriptor;var Qt=Object.getOwnPropertyNames;var Wt=Object.prototype.hasOwnProperty;var qt=(r,e)=>{for(var o in e)Me(r,o,{get:e[o],enumerable:!0})},Zt=(r,e,o,t)=>{if(e&&typeof e=="object"||typeof e=="function")for(let a of Qt(e))!Wt.call(r,a)&&a!==o&&Me(r,a,{get:()=>e[a],enumerable:!(t=$t(e,a))||t.enumerable});return r};var Ut=r=>Zt(Me({},"__esModule",{value:!0}),r);var bo={};qt(bo,{AnimatedHeatMap:()=>Ge,AnimatedHeatMapLegend:()=>ze,AnimatedHeatMapLoaded:()=>mo,AnimatedHeatMapSettings:()=>ee,CircleLayerBuilder:()=>K,ColorGradientLegend:()=>De,DefaultMapSettings:()=>z,FillLayerBuilder:()=>T,HeatMapFillLayerConfig:()=>W,HeatMapInitializerProvider:()=>ke,HeatMapLineLayerConfig:()=>Ae,HeatMapSettings:()=>At,HeatMapSymbolLayerConfig:()=>Be,LayerAnimator:()=>yo,LineLayerBuilder:()=>q,LocationHeatMapLayerBuilder:()=>co,LocationHeatMapLayerBuilderAnimated:()=>U,LocationPointLayerConfig:()=>Te,LocationPointsMapLayerBuilder:()=>po,MapBase:()=>A,MapBox:()=>X,MapBoxInstanceProvider:()=>ve,MapHeat:()=>F,MapHeatConstants:()=>ce,MapPoints:()=>_,MapPointsConstants:()=>xt,MapSettingSwitch:()=>Ne,MapSettings:()=>J,MapSettingsBox:()=>Y,MapSettingsProvider:()=>He,MapStyle:()=>bt,MapboxAccessTokenContext:()=>Q,MapboxAccessTokenProvider:()=>io,MapboxHeatFlexBox:()=>Oe,MapboxPointsFlexBox:()=>Lo,NetworkLocationAnswerSchema:()=>Ot,NetworkLocationHeatmapAnswerSchema:()=>Gt,NetworkLocationHeatmapQuadkeyAnswerSchema:()=>Dt,SymbolLayerBuilder:()=>Z,isNetworkLocationAnswer:()=>Mo,isNetworkLocationHeatmapAnswer:()=>ho,isNetworkLocationHeatmapQuadkeyAnswer:()=>xo,useDynamicMapResize:()=>he,useDynamicPositioning:()=>xe,useFindHashes:()=>be,useHeatMapColors:()=>Ce,useHeatMapInitializer:()=>no,useMapBoxInstance:()=>b,useMapSettings:()=>x,useMapboxAccessToken:()=>so,useQuadKeyPayloadsToFeatures:()=>Se});module.exports=Ut(bo);var z=()=>({debugLayer:{devMode:!0,field:"debugLayer",hidden:!0,label:"Debug Layer",value:!1},debugLogging:{devMode:!0,field:"debugLogging",hidden:!0,label:"Debug Logging",value:!1},dynamicMapResize:{devMode:!0,field:"dynamicMapResize",hidden:!0,label:"Auto Map Resize",value:!0},enableControls:{devMode:!0,field:"enableControls",hidden:!0,label:"Map Controls",value:!1},fitToPoints:{devMode:!0,field:"fitToPoints",hidden:!0,label:"Fit To Points",value:!1},preferDark:{devMode:!1,field:"preferDark",hidden:!0,label:"Prefer dark",value:!1},scrollToZoom:{devMode:!0,field:"scrollToZoom",hidden:!0,label:"Scroll To Zoom",value:!1}});var ee=z(),{debugLayer:Kt,scrollToZoom:Xt,fitToPoints:Yt,preferDark:Vt}=ee;Kt.hidden=!1;Xt.value=!0;Yt.value=!1;Vt.value=!0;var ue=require("@mui/material"),wt=require("@xylabs/react-flexbox"),vt=require("react");var ct=require("@xylabs/forget"),B=require("react");var k=require("react"),he=(r,e,o,t=!0)=>{let[a,n]=(0,k.useState)(!1),i=(0,k.useMemo)(()=>new ResizeObserver(()=>{let s=r.current?.getBoundingClientRect().width;s&&e.current&&(e.current.style.width=`${s}px`,setTimeout(()=>o?.resize()))}),[e,r,o]);(0,k.useEffect)(()=>{let s=!!(t&&o&&r?.current&&e.current);n(s)},[t,e,r,o]),(0,k.useEffect)(()=>{if(a)return r.current&&i.observe(r.current),()=>{i.disconnect()}},[t,a,e,r,o,i])};var $e=require("@xylabs/react-shared"),te=require("react"),jt=1.6,eo=[.5,2],to=[.9121644205263664,1.71785031559439],oo=[-81.4742014851959,12.788958675506933],Je=(r,e,o)=>{let[t,a]=e,[n,i]=o||eo,s=i-n,c=a-t;return(r-n)/s*c+t},xe=()=>{let[r,e]=(0,te.useState)({}),{width:o,height:t}=(0,$e.useWindowSize)();return(0,te.useEffect)(()=>{if(o&&t){let a=o/t;e({center:[Je(a,oo),Je(a,to)],zoom:jt})}},[t,o]),{options:r}};var Qe=require("@xyo-network/react-network"),We=require("react"),ro=["79af071f451fc7af10d009dc63236ef9a9b211732c1ee0c06f028fcecf2336c5","531bfba6d8dfefd3bcc888aca54cdbbd4574ed2b3ec551b230845a1f9a608898","c874412b4faa4947de81372fd1ba12fdd6f43f5e408622b7f357cb2bcb3f17cb","29d3f8b882c61a82a1a1675782a27e797ea7196f45a23b4409680ab8b8d5f14e","cfd20f80ac073fd9518f4ef3f43d2a1f5e4e56e40c2677f38d6f6fecd05df60c","1354fa73497519a39aed19fc99bdbae78a880a1eafb2f7898d607e07db36528d","1043b0d25eacfc5013ae9dba780305a6fbf01a43543bd871d7c00537fca142a9","973dfc5df142851ced258d52d0ac2784e814000ac22e35776f772256b0d4dde9","463808eb74d3d87e6563970e0301a493577f8cd1b501e6e0ffa5e027ad2cea95","15b21acea2e3fd9d1ace3768a72636ee7bdf67a6f8e0807bfa2273dea2207555","32d377bfe7ebe382598c54dd13f8af7510e0a1e2fd2e913311fdd58e517e5e2e,"],ao="c7bbf61f61cfd4a1b2def160c28136fc1d100d39fbdb67b227a2c6e558d9d3a5",be=()=>{let{network:r}=(0,Qe.useNetwork)(),e=r?.nodes?.find(n=>n.type==="archivist")?.explorerMapHashes,o=e?.animatedAnswerHashes||ro,t=e?.staticAnswerHash||ao;return(0,We.useMemo)(()=>[t,...o],[o,t])};var qe=require("@mui/material"),Ce=()=>{let r=(0,qe.useTheme)(),e="#FFFF75",o="#FF0000",t={highUsageColor:o,lowUsageColor:"#FFB3B3",staticMapColor:e},a={endColor:o,endLabel:"High",heading:"Network Usage",startColor:e,startLabel:"Low",textColor:r.palette.common.white};return{heatMapColorProps:t,legendProps:a}};var Ke=require("@xylabs/lodash"),Xe=require("@xyo-network/sdk-geo"),N=require("react"),Ze=({density:r,quadkey:e})=>{let o=new Xe.GeoJson(e).polygonFeature();return o.properties={count:r,density:r},o},Ue=r=>(r.properties&&(r.properties.value=r.properties.density/5),r),Se=r=>{let[e,o]=(0,N.useState)([[]]),[t,a]=(0,N.useState)([]),[n,i]=(0,N.useState)();return(0,N.useEffect)(()=>{if(Array.isArray(r))if((0,Ke.compact)(r).length>0){let s=r?.map(c=>c?.result.map(Ze));o(s.map(c=>c?.map(Ue)??[]))}else i(new Error("Cannot find payloads for provided hashes"));if(r&&r.result){let c=r.result.map(Ze);a(c.map(Ue))}},[r]),{error:n,features:t,multipleFeatureSets:e}};var Ye=require("@xylabs/assert"),Pe=require("@xyo-network/sdk-geo"),A=class{_config;constructor(e){this._config={requestLocation:!0,zoom:2,...e}}get isMapReady(){return!!this._config.map}initializeMapSource(e){let o=()=>{let n=Pe.GeoJson.featureCollection(this._config.features);return Pe.GeoJson.featuresSource(n)},t=this._config.map.getSource(e.source),a=o();return t?t.setData((0,Ye.assertEx)(a.data)):this._config.map.addSource(e.source,a),e.update(this._config.map,!0),this}};var Fe=require("@xylabs/assert"),oe=require("@xylabs/delay"),we=require("@xylabs/forget"),E=require("@xyo-network/sdk-geo"),Ve=require("mapbox-gl");var F=class extends A{static animationStarted=!1;config;constructor(e){super(e),this.config=e}static initialMapPositioning(e,o,t,a){if(!t)return;let n;return a?n=a:(n=new Ve.LngLatBounds,t.forEach(i=>{for(let s of i.geometry.coordinates)for(let c of s)n.extend(c)})),o.setCenter(n.getCenter()),o.fitBounds(n,e),this}static async initializeAnimatedHeatMapSource(e,o,t,a,n){this.animationStarted=!0;let i=0,s=0,c=o.map(y=>{let M=E.GeoJson.featureCollection(y);return E.GeoJson.featuresSource(M)});this.updateLayer(t,e[0],c[0]),this.updateLayer(t,e[1],c[1]);for(let y of e)t.setPaintProperty(y.id,"fill-opacity",0);let l=3e3,m=.5,g=10,p=30,u=l/p,d=a??"#FFB3B3",f=n??"#FF0000",H=(y,M,h)=>{let Le=Math.sin(h/p*Math.PI/2),Et=Math.cos(h/p*Math.PI/2),_t=y+y*Le,Jt=M*Et;return["let","density",["+",["/",["number",["get","value"]],_t],Jt],["interpolate",["linear"],["var","density"],0,d,.5,f]]},I=e.map(y=>!1),Rt=async(y,M)=>{for(let h=p;h>=1;h--)t.setPaintProperty(y,"fill-color",H(g,m,h*(180/u))),await(0,oe.delay)(u);I[M]=!0},zt=async(y,M)=>{for(let h=1;h<=p;h++)t.setPaintProperty(y,"fill-color",H(g,m,h*(180/u))),await(0,oe.delay)(u);I[M]=!1},_e=!1;await(async()=>{for((0,Fe.assertEx)(!_e,()=>"Animation Already Started"),_e=!0;this.animationStarted;){let y=i%e.length,M=(i+1)%e.length,h=s%o.length,Le=(s+1)%o.length;for(I[y]&&(this.updateLayer(t,e[y],c[h]),(0,we.forget)(zt(e[y].id,y))),I[M]||(this.updateLayer(t,e[M],c[Le]),(0,we.forget)(Rt(e[M].id,M)));(I[y]||!I[M])&&this.animationStarted;)await(0,oe.delay)(1e3);i++,s++}})()}static updateLayer(e,o,t){let a=e.getSource(o.source);a&&t.data?a.setData(t.data):t&&e.addSource(o.source,t),o.update(e,!0)}initializeHeatMapSource(e){let o=t=>{let a=E.GeoJson.featureCollection(this.config.features);return E.GeoJson.featuresSource(a)};for(let[t,a]of e.entries()){let n=this.config.map.getSource(a.source),i=o(t);n?n.setData((0,Fe.assertEx)(i.data)):this.config.map.addSource(a.source,i),a.update(this.config.map,!0)}return this}};var je=require("mapbox-gl");var _=class extends A{config;constructor(e){super(e),this.config=e}initialMapPositioning(e,o){let t;return o?t=o:(t=new je.LngLatBounds,this.config.features.forEach(a=>{t.extend(a.geometry.coordinates)})),this.config.map.setCenter(t.getCenter()),this.config.map.fitBounds(t,e),this.config.map}};var re=require("mapbox-gl"),J=class r{static geoLocateControl;static mapListeners={logData:(e,o)=>{let t=o||e?.target;t&&(console.log("zoom",t.getZoom()),console.log("center",t.getCenter()))}};static navControl;static requestLocation;static toggleControls(e,o,t,a){return e?r.addControls(o,t,a):r.removeControls(o),this}static toggleDebugLayer(e,o,t){return o.getLayer(t)&&(e?o.setLayoutProperty(t,"visibility","visible"):o.setLayoutProperty(t,"visibility","none")),this}static toggleDebugLogging(e,o){let t=["resize","zoomend","dragend"];if(e){this.mapListeners.logData(void 0,o);for(let a of t)o.on(a,this.mapListeners.logData)}else for(let a of t)o.off(a,this.mapListeners.logData)}static toggleScrollToZoom(e,o){return e?o.scrollZoom.enable():o.scrollZoom.disable(),this}static updateSettings(e){let{settings:o,map:t,zoom:a,requestLocation:n,debugLayerName:i=""}=e,{scrollToZoom:s,enableControls:c,debugLayer:l,debugLogging:m}=o;r.toggleControls(c?.value,t,a,n).toggleScrollToZoom(s?.value,t).toggleDebugLayer(l?.value,t,i).toggleDebugLogging(m.value,t)}static addControls(e,o,t){let a=new re.GeolocateControl({fitBoundsOptions:{zoom:o||2},positionOptions:{enableHighAccuracy:!0},trackUserLocation:!0}),n=new re.NavigationControl({showCompass:!1});return this.geoLocateControl=this.geoLocateControl||a,this.navControl=this.navControl||n,!e.hasControl(this.geoLocateControl)&&t&&e.addControl(this.geoLocateControl),e.hasControl(this.navControl)||e.addControl(this.navControl,"top-left"),this}static removeControls(e){return this.geoLocateControl&&e.hasControl(this.geoLocateControl)&&this.requestLocation&&e.removeControl(this.geoLocateControl),this.navControl&&e.hasControl(this.navControl)&&e.removeControl(this.navControl),this}};var $=require("react");var et=require("react"),ae=(0,et.createContext)({});var tt=require("react/jsx-runtime"),ve=({children:r})=>{let[e,o]=(0,$.useState)(),[t,a]=(0,$.useState)(!1),n={map:e,mapInitialized:t,setMapBoxInstance:o};return(0,$.useEffect)(()=>{!t&&e&&e?.on("load",()=>{a(!0)})},[e,t,a]),(0,tt.jsx)(ae.Provider,{value:n,children:r})};var ot=require("@xylabs/assert"),rt=require("react");var b=()=>{let r=(0,rt.useContext)(ae);return(0,ot.assertEx)("map"in r,()=>"useMapBoxInstance must be used within a MapBoxInstanceContext"),r};var ie=require("react");var at=require("react"),ne=(0,at.createContext)({});var nt=require("react/jsx-runtime"),He=({children:r,debugLayerName:e,defaultMapSettings:o,requestLocation:t,zoom:a=1})=>{let[n,i]=(0,ie.useState)(o||{}),{map:s,mapInitialized:c}=b(),l={mapSettings:n,setMapSettings:i};return(0,ie.useEffect)(()=>{n&&s&&c&&J.updateSettings({debugLayerName:e,map:s,requestLocation:t,settings:n,zoom:a})},[e,s,c,n,t,a]),(0,nt.jsx)(ne.Provider,{value:l,children:r})};var it=require("react");var x=()=>(0,it.useContext)(ne);var st=require("react"),se=(0,st.createContext)({});var lt=require("react/jsx-runtime"),ke=({children:r,featureSets:e,featureSetsLayers:o,features:t,fitToPadding:a,heatMapColorProps:n,layers:i,zoom:s})=>{let[c,l]=(0,B.useState)(),{options:m}=xe(),{mapSettings:g}=x(),{map:p,mapInitialized:u}=b(),d={MapHeat:c,heatMapColorProps:n};return(0,B.useEffect)(()=>{if(u&&e?.length&&e[0].length>0&&p&&o?.length){let{lowUsageColor:f,highUsageColor:H}=n;(0,ct.forget)(F.initializeAnimatedHeatMapSource(o,e,p,f,H))}return()=>{F.animationStarted=!1}},[e,o,u,p,n]),(0,B.useEffect)(()=>{c&&u&&t?.length&&i?.length&&c.initializeHeatMapSource(i)},[c,t?.length,i,u]),(0,B.useEffect)(()=>{if(u){let{fitToPoints:f}=g||{};p&&(f?.value===!0?F.initialMapPositioning({padding:a},p,t):m.zoom&&m.center&&(p.setZoom(m.zoom),p.setCenter(m.center)))}},[c,p,g,a,m,u,t]),(0,B.useEffect)(()=>{p&&t?.length&&l(new F({features:t,map:p,zoom:s}))},[p,t,s]),(0,lt.jsx)(se.Provider,{value:d,children:r})};var pt=require("@xylabs/assert"),mt=require("react");var no=()=>{let r=(0,mt.useContext)(se);return(0,pt.assertEx)("heatMapInitialized"in r,()=>"useHeatMapInitializer must be used within a HeatMapInitializerContext"),r};var ut=require("@xyo-network/react-shared"),Q=(0,ut.createContextEx)();var dt=require("react");var ft=require("react/jsx-runtime"),io=({defaultAccessToken:r,...e})=>{let[o,t]=(0,dt.useState)();return(0,ft.jsx)(Q.Provider,{value:{accessToken:o??r,provided:!0,setAccessToken:t},...e})};var gt=require("@xyo-network/react-shared");var so=(r=!1)=>(0,gt.useContextEx)(Q,"MapboxAccessToken",r);var W=r=>({paint:{"fill-color":r,"fill-opacity":["let","density",["+",["/",["number",["get","value"]],4],.125],["interpolate",["linear"],["var","density"],.8,["var","density"],1,.85]]}});var Ae=r=>({layout:{visibility:"none"},paint:{"line-color":r,"line-opacity":["let","density",0,["interpolate",["linear"],["var","density"],.8,["var","density"],1,.85]],"line-width":.5}});var Be=r=>({layout:{"text-anchor":"center","text-field":["concat","value: ",["to-string",["+",["/",["number",["get","value"]],2],.25]],`
|
|
2
|
-
`,"count: ",["to-string",["get","count"]]],"text-size":10,visibility:"none"},paint:{"text-color":r}});var Te=(r,e,o)=>({paint:{"circle-color":r,"circle-opacity":o,"circle-radius":e}});var yt=require("@xyo-network/sdk-geo"),T=class extends yt.LayerBase{FillLayerOptions;type="fill";constructor(e,o,t){super(e,o),this.FillLayerOptions=t||{id:this.id,source:this.source}}buildLayer(){return{...this.FillLayerOptions,id:this.id,source:this.source,type:this.type}}};var Lt=require("@xyo-network/sdk-geo"),q=class extends Lt.LayerBase{LineLayerOptions;type="line";constructor(e,o,t){super(e,o),this.LineLayerOptions=t||{id:this.id,source:this.source}}buildLayer(){return{...this.LineLayerOptions,id:this.id,layout:{},source:this.source,type:this.type}}};var Mt=require("@xyo-network/sdk-geo"),Z=class extends Mt.LayerBase{SymbolLayerOptions;type="symbol";constructor(e,o,t){super(e,o),this.SymbolLayerOptions=t||{id:this.id,source:this.source}}buildLayer(){return{...this.SymbolLayerOptions,id:this.id,source:this.source,type:this.type}}};var ce={LocationDebugLayerId:"location-debug-id",LocationDebugLayerSource:"location-debug-source",LocationFillLayerId:"location-fill-id",LocationFillLayerSource:"location-fill-source",LocationLineLayerId:"location-line-id",LocationLineLayerSource:"location-line-source"},co=(r,e="#000")=>{let{LocationFillLayerId:o,LocationFillLayerSource:t,LocationLineLayerId:a,LocationLineLayerSource:n,LocationDebugLayerId:i,LocationDebugLayerSource:s}=ce,c=W(r),l=Ae(r),m=Be(e),g=new T(o,t,c),p=new q(a,n,l),u=new Z(i,s,m);return[g,p,u]};var lo=(r,e)=>({LocationDebugLayerId:`location-${e}-debug-id-${r}`,LocationDebugLayerSource:`location-${e}-debug-source-${r}`,LocationFillLayerId:`location-${e}-fill-id-${r}`,LocationFillLayerSource:`location-${e}-fill-source-${r}`,LocationLineLayerId:`location-${e}-line-id-${r}`,LocationLineLayerSource:`location-${e}-line-source-${r}`}),U=(r,e,o="")=>{let{LocationFillLayerId:t,LocationFillLayerSource:a}=lo(e,o),n=W(r);return new T(t,a,n)};var ht=require("@xyo-network/sdk-geo"),K=class extends ht.LayerBase{CircleLayerOptions;type="circle";constructor(e,o,t){super(e,o),this.CircleLayerOptions=t||{id:this.id,source:this.source,type:"circle"}}buildLayer(){return{filter:["==","$type","Point"],layout:{},paint:{"circle-color":"#ff0000","circle-radius":6},type:this.type,...this.CircleLayerOptions,id:this.id,source:this.source}}};var xt={LocationDotsLayerId:"location-dots",LocationDotsLayerSource:"location-dots-source"},po=(r,e=6,o=.8)=>{let{LocationDotsLayerId:t,LocationDotsLayerSource:a}=xt,n=Te(r,e,o);return[new K(t,a,n)]};var Ft=require("@xylabs/react-flexbox");var $r=require("mapbox-gl/dist/mapbox-gl.css"),Ct=require("mapbox-gl"),w=require("react");var bt=(i=>(i.Dark="mapbox/dark-v10",i.Light="mapbox/light-v10",i.Outdoors="mapbox/outdoors-v11",i.Satellite="mapbox/satellite-v9",i.SatelliteStreets="mapbox/satellite-streets-v11",i.Streets="mapbox/streets-v11",i))(bt||{});var St=require("react/jsx-runtime"),X=({accessToken:r,darkMode:e=!1,options:o,zoom:t=2,...a})=>{let[n,i]=(0,w.useState)(),s=(0,w.useRef)(null),c=(0,w.useRef)(null),{setMapBoxInstance:l,map:m}=b(),{mapSettings:g}=x(),p=g?.dynamicMapResize.value;return he(s,c,m,p),(0,w.useEffect)(()=>{g?.preferDark?.value===!0?n?.setStyle("mapbox://styles/mapbox/dark-v10"):n?.setStyle(`mapbox://styles/${e?"mapbox/dark-v10":"mapbox/light-v10"}`)},[n,e,g]),(0,w.useEffect)(()=>{let u=new Ct.Map({accessToken:r,center:[0,0],container:s.current??"",style:"mapbox://styles/mapbox/light-v10",zoom:t,...o});return l?.(u),i(u),c.current=document.querySelector(".mapboxgl-canvas"),console.log("Created Map"),()=>{console.log("Removing Map"),u.remove()}},[s,i,o,t,l,r]),(0,St.jsx)("div",{ref:u=>s.current=u,style:{bottom:0,left:0,position:"absolute",right:0,top:0,...a}})};var le=require("@mui/material");var Ie=require("react/jsx-runtime"),Ne=({developerMode:r,field:e,...o})=>{let{mapSettings:t,setMapSettings:a}=x(),n=t?.[e],i=s=>{n&&a?.(c=>(c[n.field].value=s.target.checked,{...c}))};return n?.devMode&&r===!1||n?.hidden?null:(0,Ie.jsx)(le.FormControlLabel,{label:n?.label,control:(0,Ie.jsx)(le.Switch,{checked:n?.value,onChange:i,...o})})};var pe=require("@mui/material"),me=require("@xylabs/react-flexbox"),Pt=require("@xyo-network/react-app-settings");var O=require("react/jsx-runtime"),Y=({developerMode:r,...e})=>{let{mapSettings:o}=x(),{developerMode:t}=(0,Pt.useAppSettings)();return o&&(r??t)?(0,O.jsx)(me.FlexGrowRow,{bottom:36,left:10,position:"absolute",...e,children:(0,O.jsx)(me.FlexRow,{paddingX:2,children:(0,O.jsx)(pe.Paper,{children:(0,O.jsx)(pe.Stack,{direction:"row",spacing:1,marginX:1,children:Object.keys(o).map((n,i)=>(0,O.jsx)(Ne,{field:o[n].field,developerMode:r},i))})})})}):null};var V=require("react/jsx-runtime"),Oe=({accessToken:r,children:e,mapBoxOptions:o,zoom:t,legend:a,developerMode:n,...i})=>(0,V.jsxs)(Ft.FlexCol,{...i,children:[(0,V.jsx)(X,{accessToken:r,options:o,zoom:t}),(0,V.jsx)(Y,{developerMode:n}),a,e]});var G=require("react/jsx-runtime"),Ge=({accessToken:r,animatedFeatureSets:e,defaultMapSettings:o,heatMapColorProps:t,staticFeatureSet:a,...n})=>{let i=(0,ue.useTheme)(),{staticMapColor:s,lowUsageColor:c,highUsageColor:l}=t||{},m=s??i.palette.primary.light,[g]=(0,vt.useState)([U(m,0,"static"),U(c||m,0,"animated"),U(l||(0,ue.darken)(m,.9),1,"animated")]);return e?.length?(0,G.jsx)(ve,{children:(0,G.jsx)(He,{defaultMapSettings:o,debugLayerName:ce.LocationDebugLayerId,children:(0,G.jsx)(ke,{features:a,layers:[g[0]],featureSets:e,featureSetsLayers:g.slice(1,3),heatMapColorProps:t,children:(0,G.jsx)(Oe,{accessToken:r,...n})})})}):(0,G.jsx)(wt.FlexCol,{minHeight:160,minWidth:160,busy:!0})};var j=require("@mui/material"),kt=require("@xylabs/react-flexbox"),fe=require("@xyo-network/react-archivist");var de=require("@mui/material"),Ht=require("@xylabs/react-flexbox");var D=require("@mui/material"),R=require("@xylabs/react-flexbox"),C=require("react/jsx-runtime"),De=({startColor:r,endColor:e,startLabel:o,endLabel:t,heading:a,textColor:n,...i})=>{let s=(0,D.useTheme)();return(0,C.jsxs)(R.FlexCol,{...i,children:[(0,C.jsx)(D.Typography,{mb:s.spacing(.25),color:n,variant:"caption",textAlign:"center",children:a}),(0,C.jsx)(R.FlexCol,{flexGrow:1,alignItems:"stretch",paddingX:s.spacing(1),mb:s.spacing(.25),children:(0,C.jsx)(R.FlexCol,{height:s.spacing(.75),border:`1px solid ${n}`,sx:{backgroundImage:`linear-gradient(to right, ${r},${e})`}})}),(0,C.jsxs)(R.FlexRow,{flexGrow:1,justifyContent:"space-between",children:[(0,C.jsx)(D.Typography,{color:n,variant:"caption",children:o}),(0,C.jsx)(D.Typography,{color:n,variant:"caption",children:t})]})]})};var Re=require("react/jsx-runtime"),ze=({...r})=>{let{startColor:e,endColor:o,startLabel:t,endLabel:a,heading:n,textColor:i}=r,s=(0,de.useTheme)(),c=(0,de.useMediaQuery)(s.breakpoints.down("sm"));return(0,Re.jsx)(Ht.FlexCol,{position:"absolute",bottom:0,right:0,children:(0,Re.jsx)(De,{startColor:e,endColor:o,startLabel:t,endLabel:a,heading:n,textColor:i,alignItems:"stretch",marginBottom:s.spacing(4),marginLeft:c?s.spacing(3):0,marginRight:c?s.spacing(2):s.spacing(3),width:c?"40vw":s.spacing(18)})})};var v=require("react/jsx-runtime"),mo=({accessToken:r,archivistNameOrAddress:e,...o})=>{let t=be(),[a]=(0,fe.useWeakArchivistFromNode)(e),[n,i]=(0,fe.useWeakArchivistGet)(a,t),{multipleFeatureSets:s}=Se(n),{heatMapColorProps:c,legendProps:l}=Ce(),m={flexGrow:1,legend:l?(0,v.jsx)(ze,{...l}):null};return(0,v.jsxs)(kt.FlexCol,{alignItems:"stretch",...o,children:[i?(0,v.jsxs)(j.Alert,{sx:{mt:2},children:[(0,v.jsx)(j.AlertTitle,{children:"Error Loading Map"}),i.message?`Error: ${i.message}`:null,"You might try authenticating again."]}):null,t===void 0?(0,v.jsx)(j.Alert,{children:"Missing answer hash for heat map query"}):(0,v.jsx)(Ge,{accessToken:r,defaultMapSettings:ee,animatedFeatureSets:s.slice(1,s.length),staticFeatureSet:s[0],heatMapColorProps:c,...m})]})};var At=z(),{debugLayer:uo,scrollToZoom:fo,fitToPoints:go}=At;uo.hidden=!1;fo.value=!0;go.value=!0;var Tt=require("@xylabs/react-shared"),L=require("react"),ge=require("react/jsx-runtime"),Ee=2e3,Bt=3,yo=({animateLayers:r,children:e,layers:o,layersInitialized:t,map:a})=>{let[n,i]=(0,L.useState)([]),s=(0,L.useRef)([]),c=(0,L.useCallback)(d=>(n[d]?s.current.push(d):s.current.push(0),s.current.at(-1)),[n]),l=(0,L.useCallback)(()=>{let d=s.current.at(-1);return d===void 0?(c(0),0):d},[c]),m=(0,L.useCallback)(()=>{s.current.shift()},[]),g=(0,L.useCallback)(()=>{let d=n[l()];return c(l()+1),d},[n,c,l]),p=(0,L.useCallback)(d=>{d?(a?.setPaintProperty(d.id,"fill-opacity",.85),setTimeout(()=>{a?.setPaintProperty(d.id,"fill-opacity",0),m()},Ee*2)):console.warn("tried to queue an empty layer")},[a,m]);(0,L.useEffect)(()=>{o?.length&&a&&t&&i(o.filter(d=>{let f=d.id.startsWith("location-fill");return f&&a.setPaintProperty(d.id,"fill-opacity-transition",{delay:0,duration:4e3}),f}))},[o,t,a]);let u=(0,L.useCallback)(()=>{let d=[];for(let f=0;f<Bt;f++)d.push(g());for(let[f,H]of d.entries())f===0?p(H):setTimeout(()=>{p(H)},Ee*f)},[g,p]);return(0,L.useEffect)(()=>{r&&t&&a&&n.length>0&&u()},[r,n.length,t,a,u]),(0,Tt.useInterval)(()=>{r&&t&&a&&n.length>0&&u()},Ee*Bt),(0,ge.jsx)(ge.Fragment,{children:e})};var It=require("@mui/material"),Nt=require("@xylabs/react-flexbox"),P=require("react");var S=require("react/jsx-runtime"),Lo=({accessToken:r,features:e,fitToPointsPadding:o=20,layers:t,zoom:a,...n})=>{let[i,s]=(0,P.useState)(),{mapSettings:c}=x(),{map:l,mapInitialized:m}=b(),g=f=>f!==void 0?{maxZoom:f}:{},p=(0,P.useCallback)(()=>{if(i?.isMapReady&&e?.length&&t)for(let f of t)i.initializeMapSource(f)},[i,e,t]),u=(0,P.useCallback)(()=>{let{fitToPoints:f}=c||{};i&&l&&f?.value===!0&&i.initialMapPositioning({padding:o,...g(a)})},[c,i,l,o,a]),d=(0,P.useCallback)(()=>{i?.initialMapPositioning({padding:o,...g(a)}),p()},[i,o,p,a]);return(0,P.useEffect)(()=>{l&&e?.length&&s(new _({features:e,map:l,zoom:a}))},[l,e,a]),(0,P.useEffect)(()=>{m&&(u(),d())},[m,d,u]),(0,S.jsx)(Nt.FlexCol,{alignItems:"stretch",id:"xyo-mapbox-wrap",...n,children:e?(0,S.jsxs)(S.Fragment,{children:[(0,S.jsx)(X,{accessToken:r,zoom:a}),(0,S.jsx)(Y,{})]}):(0,S.jsx)(It.Alert,{severity:"error",children:"No data to show"})})};var ye=require("@xyo-network/payload-model"),Ot="network.xyo.location.range.answer",Mo=(0,ye.isPayloadOfSchemaType)(Ot),Gt="network.xyo.location.heatmap.answer",ho=(0,ye.isPayloadOfSchemaType)(Gt),Dt="network.xyo.location.heatmap.quadkey.answer",xo=(0,ye.isPayloadOfSchemaType)(Dt);
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/index.ts
|
|
21
|
+
var src_exports = {};
|
|
22
|
+
__export(src_exports, {
|
|
23
|
+
AnimatedHeatMap: () => AnimatedHeatMap,
|
|
24
|
+
AnimatedHeatMapLegend: () => AnimatedHeatMapLegend,
|
|
25
|
+
AnimatedHeatMapLoaded: () => AnimatedHeatMapLoaded,
|
|
26
|
+
AnimatedHeatMapSettings: () => AnimatedHeatMapSettings,
|
|
27
|
+
CircleLayerBuilder: () => CircleLayerBuilder,
|
|
28
|
+
ColorGradientLegend: () => ColorGradientLegend,
|
|
29
|
+
DefaultMapSettings: () => DefaultMapSettings,
|
|
30
|
+
FillLayerBuilder: () => FillLayerBuilder,
|
|
31
|
+
HeatMapFillLayerConfig: () => HeatMapFillLayerConfig,
|
|
32
|
+
HeatMapInitializerProvider: () => HeatMapInitializerProvider,
|
|
33
|
+
HeatMapLineLayerConfig: () => HeatMapLineLayerConfig,
|
|
34
|
+
HeatMapSettings: () => HeatMapSettings,
|
|
35
|
+
HeatMapSymbolLayerConfig: () => HeatMapSymbolLayerConfig,
|
|
36
|
+
LayerAnimator: () => LayerAnimator,
|
|
37
|
+
LineLayerBuilder: () => LineLayerBuilder,
|
|
38
|
+
LocationHeatMapLayerBuilder: () => LocationHeatMapLayerBuilder,
|
|
39
|
+
LocationHeatMapLayerBuilderAnimated: () => LocationHeatMapLayerBuilderAnimated,
|
|
40
|
+
LocationPointLayerConfig: () => LocationPointLayerConfig,
|
|
41
|
+
LocationPointsMapLayerBuilder: () => LocationPointsMapLayerBuilder,
|
|
42
|
+
MapBase: () => MapBase,
|
|
43
|
+
MapBox: () => MapBox,
|
|
44
|
+
MapBoxInstanceProvider: () => MapBoxInstanceProvider,
|
|
45
|
+
MapHeat: () => MapHeat,
|
|
46
|
+
MapHeatConstants: () => MapHeatConstants,
|
|
47
|
+
MapPoints: () => MapPoints,
|
|
48
|
+
MapPointsConstants: () => MapPointsConstants,
|
|
49
|
+
MapSettingSwitch: () => MapSettingSwitch,
|
|
50
|
+
MapSettings: () => MapSettings,
|
|
51
|
+
MapSettingsBox: () => MapSettingsBox,
|
|
52
|
+
MapSettingsProvider: () => MapSettingsProvider,
|
|
53
|
+
MapStyle: () => MapStyle,
|
|
54
|
+
MapboxAccessTokenContext: () => MapboxAccessTokenContext,
|
|
55
|
+
MapboxAccessTokenProvider: () => MapboxAccessTokenProvider,
|
|
56
|
+
MapboxHeatFlexBox: () => MapboxHeatFlexBox,
|
|
57
|
+
MapboxPointsFlexBox: () => MapboxPointsFlexBox,
|
|
58
|
+
NetworkLocationAnswerSchema: () => NetworkLocationAnswerSchema,
|
|
59
|
+
NetworkLocationHeatmapAnswerSchema: () => NetworkLocationHeatmapAnswerSchema,
|
|
60
|
+
NetworkLocationHeatmapQuadkeyAnswerSchema: () => NetworkLocationHeatmapQuadkeyAnswerSchema,
|
|
61
|
+
SymbolLayerBuilder: () => SymbolLayerBuilder,
|
|
62
|
+
isNetworkLocationAnswer: () => isNetworkLocationAnswer,
|
|
63
|
+
isNetworkLocationHeatmapAnswer: () => isNetworkLocationHeatmapAnswer,
|
|
64
|
+
isNetworkLocationHeatmapQuadkeyAnswer: () => isNetworkLocationHeatmapQuadkeyAnswer,
|
|
65
|
+
useDynamicMapResize: () => useDynamicMapResize,
|
|
66
|
+
useDynamicPositioning: () => useDynamicPositioning,
|
|
67
|
+
useFindHashes: () => useFindHashes,
|
|
68
|
+
useHeatMapColors: () => useHeatMapColors,
|
|
69
|
+
useHeatMapInitializer: () => useHeatMapInitializer,
|
|
70
|
+
useMapBoxInstance: () => useMapBoxInstance,
|
|
71
|
+
useMapSettings: () => useMapSettings,
|
|
72
|
+
useMapboxAccessToken: () => useMapboxAccessToken,
|
|
73
|
+
useQuadKeyPayloadsToFeatures: () => useQuadKeyPayloadsToFeatures
|
|
74
|
+
});
|
|
75
|
+
module.exports = __toCommonJS(src_exports);
|
|
76
|
+
|
|
77
|
+
// src/Settings/DefaultMapSettings.ts
|
|
78
|
+
var DefaultMapSettings = () => ({
|
|
79
|
+
debugLayer: {
|
|
80
|
+
devMode: true,
|
|
81
|
+
field: "debugLayer",
|
|
82
|
+
hidden: true,
|
|
83
|
+
label: "Debug Layer",
|
|
84
|
+
value: false
|
|
85
|
+
},
|
|
86
|
+
debugLogging: {
|
|
87
|
+
devMode: true,
|
|
88
|
+
field: "debugLogging",
|
|
89
|
+
hidden: true,
|
|
90
|
+
label: "Debug Logging",
|
|
91
|
+
value: false
|
|
92
|
+
},
|
|
93
|
+
dynamicMapResize: {
|
|
94
|
+
devMode: true,
|
|
95
|
+
field: "dynamicMapResize",
|
|
96
|
+
hidden: true,
|
|
97
|
+
label: "Auto Map Resize",
|
|
98
|
+
value: true
|
|
99
|
+
},
|
|
100
|
+
enableControls: {
|
|
101
|
+
devMode: true,
|
|
102
|
+
field: "enableControls",
|
|
103
|
+
hidden: true,
|
|
104
|
+
label: "Map Controls",
|
|
105
|
+
value: false
|
|
106
|
+
},
|
|
107
|
+
fitToPoints: {
|
|
108
|
+
devMode: true,
|
|
109
|
+
field: "fitToPoints",
|
|
110
|
+
hidden: true,
|
|
111
|
+
label: "Fit To Points",
|
|
112
|
+
value: false
|
|
113
|
+
},
|
|
114
|
+
preferDark: {
|
|
115
|
+
devMode: false,
|
|
116
|
+
field: "preferDark",
|
|
117
|
+
hidden: true,
|
|
118
|
+
label: "Prefer dark",
|
|
119
|
+
value: false
|
|
120
|
+
},
|
|
121
|
+
scrollToZoom: {
|
|
122
|
+
devMode: true,
|
|
123
|
+
field: "scrollToZoom",
|
|
124
|
+
hidden: true,
|
|
125
|
+
label: "Scroll To Zoom",
|
|
126
|
+
value: false
|
|
127
|
+
}
|
|
128
|
+
});
|
|
129
|
+
|
|
130
|
+
// src/AnimatedHeatMapSettings.ts
|
|
131
|
+
var AnimatedHeatMapSettings = DefaultMapSettings();
|
|
132
|
+
var { debugLayer, scrollToZoom, fitToPoints, preferDark } = AnimatedHeatMapSettings;
|
|
133
|
+
debugLayer.hidden = false;
|
|
134
|
+
scrollToZoom.value = true;
|
|
135
|
+
fitToPoints.value = false;
|
|
136
|
+
preferDark.value = true;
|
|
137
|
+
|
|
138
|
+
// src/Components/AnimatedHeatMap.tsx
|
|
139
|
+
var import_material4 = require("@mui/material");
|
|
140
|
+
var import_react_flexbox3 = require("@xylabs/react-flexbox");
|
|
141
|
+
var import_react16 = require("react");
|
|
142
|
+
|
|
143
|
+
// src/Contexts/HeatMapInitializer/Provider.tsx
|
|
144
|
+
var import_forget2 = require("@xylabs/forget");
|
|
145
|
+
var import_react12 = require("react");
|
|
146
|
+
|
|
147
|
+
// src/hooks/useDynamicMapResize.tsx
|
|
148
|
+
var import_react = require("react");
|
|
149
|
+
var useDynamicMapResize = (mapContainerRef, mapCanvasRef, mapInstance, active = true) => {
|
|
150
|
+
const [dependenciesReady, setDependenciesReady] = (0, import_react.useState)(false);
|
|
151
|
+
const resizer = (0, import_react.useMemo)(
|
|
152
|
+
() => new ResizeObserver(() => {
|
|
153
|
+
const width = mapContainerRef.current?.getBoundingClientRect().width;
|
|
154
|
+
if (width && mapCanvasRef.current) {
|
|
155
|
+
mapCanvasRef.current.style.width = `${width}px`;
|
|
156
|
+
setTimeout(() => mapInstance?.resize());
|
|
157
|
+
}
|
|
158
|
+
}),
|
|
159
|
+
[mapCanvasRef, mapContainerRef, mapInstance]
|
|
160
|
+
);
|
|
161
|
+
(0, import_react.useEffect)(() => {
|
|
162
|
+
const dependenciesReady2 = !!(active && mapInstance && mapContainerRef?.current && mapCanvasRef.current);
|
|
163
|
+
setDependenciesReady(dependenciesReady2);
|
|
164
|
+
}, [active, mapCanvasRef, mapContainerRef, mapInstance]);
|
|
165
|
+
(0, import_react.useEffect)(() => {
|
|
166
|
+
if (dependenciesReady) {
|
|
167
|
+
if (mapContainerRef.current) {
|
|
168
|
+
resizer.observe(mapContainerRef.current);
|
|
169
|
+
}
|
|
170
|
+
return () => {
|
|
171
|
+
resizer.disconnect();
|
|
172
|
+
};
|
|
173
|
+
}
|
|
174
|
+
}, [active, dependenciesReady, mapCanvasRef, mapContainerRef, mapInstance, resizer]);
|
|
175
|
+
};
|
|
176
|
+
|
|
177
|
+
// src/hooks/useDynamicPositioning.tsx
|
|
178
|
+
var import_react_shared = require("@xylabs/react-shared");
|
|
179
|
+
var import_react2 = require("react");
|
|
180
|
+
var defaultZoom = 1.6;
|
|
181
|
+
var defaultAspectRatioRange = [0.5, 2];
|
|
182
|
+
var latRange = [0.9121644205263664, 1.71785031559439];
|
|
183
|
+
var lngRange = [-81.4742014851959, 12.788958675506933];
|
|
184
|
+
var linearInterpolate = (aspectRatio, degreeRange, aspectRatioRange) => {
|
|
185
|
+
const [degreeMin, degreeMax] = degreeRange;
|
|
186
|
+
const [aspectRatioMin, aspectRatioMax] = aspectRatioRange || defaultAspectRatioRange;
|
|
187
|
+
const aspectRatioRangeSpan = aspectRatioMax - aspectRatioMin;
|
|
188
|
+
const degreeRangeSpan = degreeMax - degreeMin;
|
|
189
|
+
const percent = (aspectRatio - aspectRatioMin) / aspectRatioRangeSpan;
|
|
190
|
+
const scaledDegree = percent * degreeRangeSpan + degreeMin;
|
|
191
|
+
return scaledDegree;
|
|
192
|
+
};
|
|
193
|
+
var useDynamicPositioning = () => {
|
|
194
|
+
const [options, setOptions] = (0, import_react2.useState)({});
|
|
195
|
+
const { width, height } = (0, import_react_shared.useWindowSize)();
|
|
196
|
+
(0, import_react2.useEffect)(() => {
|
|
197
|
+
if (width && height) {
|
|
198
|
+
const aspectRatio = width / height;
|
|
199
|
+
setOptions({
|
|
200
|
+
center: [linearInterpolate(aspectRatio, lngRange), linearInterpolate(aspectRatio, latRange)],
|
|
201
|
+
zoom: defaultZoom
|
|
202
|
+
});
|
|
203
|
+
}
|
|
204
|
+
}, [height, width]);
|
|
205
|
+
return { options };
|
|
206
|
+
};
|
|
207
|
+
|
|
208
|
+
// src/hooks/useFindHashes.tsx
|
|
209
|
+
var import_react_network = require("@xyo-network/react-network");
|
|
210
|
+
var import_react3 = require("react");
|
|
211
|
+
var animatedAnswerHashesConst = [
|
|
212
|
+
"79af071f451fc7af10d009dc63236ef9a9b211732c1ee0c06f028fcecf2336c5",
|
|
213
|
+
"531bfba6d8dfefd3bcc888aca54cdbbd4574ed2b3ec551b230845a1f9a608898",
|
|
214
|
+
"c874412b4faa4947de81372fd1ba12fdd6f43f5e408622b7f357cb2bcb3f17cb",
|
|
215
|
+
"29d3f8b882c61a82a1a1675782a27e797ea7196f45a23b4409680ab8b8d5f14e",
|
|
216
|
+
"cfd20f80ac073fd9518f4ef3f43d2a1f5e4e56e40c2677f38d6f6fecd05df60c",
|
|
217
|
+
"1354fa73497519a39aed19fc99bdbae78a880a1eafb2f7898d607e07db36528d",
|
|
218
|
+
"1043b0d25eacfc5013ae9dba780305a6fbf01a43543bd871d7c00537fca142a9",
|
|
219
|
+
"973dfc5df142851ced258d52d0ac2784e814000ac22e35776f772256b0d4dde9",
|
|
220
|
+
"463808eb74d3d87e6563970e0301a493577f8cd1b501e6e0ffa5e027ad2cea95",
|
|
221
|
+
"15b21acea2e3fd9d1ace3768a72636ee7bdf67a6f8e0807bfa2273dea2207555",
|
|
222
|
+
"32d377bfe7ebe382598c54dd13f8af7510e0a1e2fd2e913311fdd58e517e5e2e,"
|
|
223
|
+
];
|
|
224
|
+
var staticAnswerHashConst = "c7bbf61f61cfd4a1b2def160c28136fc1d100d39fbdb67b227a2c6e558d9d3a5";
|
|
225
|
+
var useFindHashes = () => {
|
|
226
|
+
const { network } = (0, import_react_network.useNetwork)();
|
|
227
|
+
const exploreMapHashes = network?.nodes?.find((node) => node.type === "archivist")?.explorerMapHashes;
|
|
228
|
+
const animatedAnswerHashes = exploreMapHashes?.animatedAnswerHashes || animatedAnswerHashesConst;
|
|
229
|
+
const staticAnswerHash = exploreMapHashes?.staticAnswerHash || staticAnswerHashConst;
|
|
230
|
+
const foundHashes = (0, import_react3.useMemo)(() => [staticAnswerHash, ...animatedAnswerHashes], [animatedAnswerHashes, staticAnswerHash]);
|
|
231
|
+
return foundHashes;
|
|
232
|
+
};
|
|
233
|
+
|
|
234
|
+
// src/hooks/useHeatMapColors.tsx
|
|
235
|
+
var import_material = require("@mui/material");
|
|
236
|
+
var useHeatMapColors = () => {
|
|
237
|
+
const theme = (0, import_material.useTheme)();
|
|
238
|
+
const staticMapColor = "#FFFF75";
|
|
239
|
+
const highUsageColor = "#FF0000";
|
|
240
|
+
const heatMapColorProps = {
|
|
241
|
+
highUsageColor,
|
|
242
|
+
lowUsageColor: "#FFB3B3",
|
|
243
|
+
staticMapColor
|
|
244
|
+
};
|
|
245
|
+
const legendProps = {
|
|
246
|
+
endColor: highUsageColor,
|
|
247
|
+
endLabel: "High",
|
|
248
|
+
heading: "Network Usage",
|
|
249
|
+
startColor: staticMapColor,
|
|
250
|
+
startLabel: "Low",
|
|
251
|
+
textColor: theme.palette.common.white
|
|
252
|
+
};
|
|
253
|
+
return { heatMapColorProps, legendProps };
|
|
254
|
+
};
|
|
255
|
+
|
|
256
|
+
// src/hooks/useQuadKeyPayloadsToFeatures.tsx
|
|
257
|
+
var import_lodash = require("@xylabs/lodash");
|
|
258
|
+
var import_sdk_geo = require("@xyo-network/sdk-geo");
|
|
259
|
+
var import_react4 = require("react");
|
|
260
|
+
var quadKeyToFeature = ({ density, quadkey }) => {
|
|
261
|
+
const polygonFeature = new import_sdk_geo.GeoJson(quadkey).polygonFeature();
|
|
262
|
+
polygonFeature.properties = {
|
|
263
|
+
count: density,
|
|
264
|
+
density
|
|
265
|
+
};
|
|
266
|
+
return polygonFeature;
|
|
267
|
+
};
|
|
268
|
+
var setDensity = (feature) => {
|
|
269
|
+
if (feature.properties) {
|
|
270
|
+
feature.properties.value = feature.properties.density / 5;
|
|
271
|
+
}
|
|
272
|
+
return feature;
|
|
273
|
+
};
|
|
274
|
+
var useQuadKeyPayloadsToFeatures = (payloads) => {
|
|
275
|
+
const [multipleFeatureSets, setMultipleFeatureSets] = (0, import_react4.useState)([[]]);
|
|
276
|
+
const [features, setFeatures] = (0, import_react4.useState)([]);
|
|
277
|
+
const [error, setError] = (0, import_react4.useState)();
|
|
278
|
+
(0, import_react4.useEffect)(() => {
|
|
279
|
+
if (Array.isArray(payloads)) {
|
|
280
|
+
if ((0, import_lodash.compact)(payloads).length > 0) {
|
|
281
|
+
const mappedFeatures = payloads?.map((payload) => payload?.result.map(quadKeyToFeature));
|
|
282
|
+
setMultipleFeatureSets(mappedFeatures.map((features2) => features2?.map(setDensity) ?? []));
|
|
283
|
+
} else {
|
|
284
|
+
setError(new Error("Cannot find payloads for provided hashes"));
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
if (payloads && payloads.result) {
|
|
288
|
+
const singlePayload = payloads;
|
|
289
|
+
const mappedFeatures = singlePayload.result.map(quadKeyToFeature);
|
|
290
|
+
setFeatures(mappedFeatures.map(setDensity));
|
|
291
|
+
}
|
|
292
|
+
}, [payloads]);
|
|
293
|
+
return { error, features, multipleFeatureSets };
|
|
294
|
+
};
|
|
295
|
+
|
|
296
|
+
// src/MapBoxClasses/MapBase.ts
|
|
297
|
+
var import_assert = require("@xylabs/assert");
|
|
298
|
+
var import_sdk_geo2 = require("@xyo-network/sdk-geo");
|
|
299
|
+
var MapBase = class {
|
|
300
|
+
_config;
|
|
301
|
+
constructor(config) {
|
|
302
|
+
this._config = { requestLocation: true, zoom: 2, ...config };
|
|
303
|
+
}
|
|
304
|
+
get isMapReady() {
|
|
305
|
+
return !!this._config.map;
|
|
306
|
+
}
|
|
307
|
+
initializeMapSource(layer) {
|
|
308
|
+
const getSource = () => {
|
|
309
|
+
const featuresCollection = import_sdk_geo2.GeoJson.featureCollection(this._config.features);
|
|
310
|
+
return import_sdk_geo2.GeoJson.featuresSource(featuresCollection);
|
|
311
|
+
};
|
|
312
|
+
const existingSource = this._config.map.getSource(layer.source);
|
|
313
|
+
const source = getSource();
|
|
314
|
+
if (existingSource) {
|
|
315
|
+
existingSource.setData((0, import_assert.assertEx)(source.data));
|
|
316
|
+
} else {
|
|
317
|
+
this._config.map.addSource(layer.source, source);
|
|
318
|
+
}
|
|
319
|
+
layer.update(this._config.map, true);
|
|
320
|
+
return this;
|
|
321
|
+
}
|
|
322
|
+
};
|
|
323
|
+
|
|
324
|
+
// src/MapBoxClasses/MapHeat.ts
|
|
325
|
+
var import_assert2 = require("@xylabs/assert");
|
|
326
|
+
var import_delay = require("@xylabs/delay");
|
|
327
|
+
var import_forget = require("@xylabs/forget");
|
|
328
|
+
var import_sdk_geo3 = require("@xyo-network/sdk-geo");
|
|
329
|
+
var import_mapbox_gl = require("mapbox-gl");
|
|
330
|
+
var MapHeat = class extends MapBase {
|
|
331
|
+
static animationStarted = false;
|
|
332
|
+
config;
|
|
333
|
+
constructor(config) {
|
|
334
|
+
super(config);
|
|
335
|
+
this.config = config;
|
|
336
|
+
}
|
|
337
|
+
static initialMapPositioning(options, map, features, initialBounds) {
|
|
338
|
+
if (!features) {
|
|
339
|
+
return;
|
|
340
|
+
}
|
|
341
|
+
let bounds;
|
|
342
|
+
if (initialBounds) {
|
|
343
|
+
bounds = initialBounds;
|
|
344
|
+
} else {
|
|
345
|
+
bounds = new import_mapbox_gl.LngLatBounds();
|
|
346
|
+
features.forEach((feature) => {
|
|
347
|
+
for (const coordinates of feature.geometry.coordinates) {
|
|
348
|
+
for (const position of coordinates) {
|
|
349
|
+
bounds.extend(position);
|
|
350
|
+
}
|
|
351
|
+
}
|
|
352
|
+
});
|
|
353
|
+
}
|
|
354
|
+
map.setCenter(bounds.getCenter());
|
|
355
|
+
map.fitBounds(bounds, options);
|
|
356
|
+
return this;
|
|
357
|
+
}
|
|
358
|
+
static async initializeAnimatedHeatMapSource(layers, featureSet, map, startColor, endColor) {
|
|
359
|
+
this.animationStarted = true;
|
|
360
|
+
let layerTick = 0;
|
|
361
|
+
let sourceTick = 0;
|
|
362
|
+
const sources = featureSet.map((feature) => {
|
|
363
|
+
const featuresCollection = import_sdk_geo3.GeoJson.featureCollection(feature);
|
|
364
|
+
return import_sdk_geo3.GeoJson.featuresSource(featuresCollection);
|
|
365
|
+
});
|
|
366
|
+
this.updateLayer(map, layers[0], sources[0]);
|
|
367
|
+
this.updateLayer(map, layers[1], sources[1]);
|
|
368
|
+
for (const layer of layers) {
|
|
369
|
+
map.setPaintProperty(layer.id, "fill-opacity", 0);
|
|
370
|
+
}
|
|
371
|
+
const frameLength = 3e3;
|
|
372
|
+
const initialPad = 0.5;
|
|
373
|
+
const factor = 10;
|
|
374
|
+
const steps = 30;
|
|
375
|
+
const stepLength = frameLength / steps;
|
|
376
|
+
const lowUsageColor = startColor ?? "#FFB3B3";
|
|
377
|
+
const highUsageColor = endColor ?? "#FF0000";
|
|
378
|
+
const dynamicFillColor = (factor2, initialPad2, i) => {
|
|
379
|
+
const sinFade = Math.sin(i / steps * Math.PI / 2);
|
|
380
|
+
const cosFade = Math.cos(i / steps * Math.PI / 2);
|
|
381
|
+
const divisor = factor2 + factor2 * sinFade;
|
|
382
|
+
const offset = initialPad2 * cosFade;
|
|
383
|
+
return [
|
|
384
|
+
"let",
|
|
385
|
+
"density",
|
|
386
|
+
["+", ["/", ["number", ["get", "value"]], divisor], offset],
|
|
387
|
+
["interpolate", ["linear"], ["var", "density"], 0, lowUsageColor, 0.5, highUsageColor]
|
|
388
|
+
];
|
|
389
|
+
};
|
|
390
|
+
const fadedIn = layers.map((_) => false);
|
|
391
|
+
const fadeIn = async (id, index) => {
|
|
392
|
+
for (let i = steps; i >= 1; i--) {
|
|
393
|
+
map.setPaintProperty(id, "fill-color", dynamicFillColor(factor, initialPad, i * (180 / stepLength)));
|
|
394
|
+
await (0, import_delay.delay)(stepLength);
|
|
395
|
+
}
|
|
396
|
+
fadedIn[index] = true;
|
|
397
|
+
};
|
|
398
|
+
const fadeOut = async (id, index) => {
|
|
399
|
+
for (let i = 1; i <= steps; i++) {
|
|
400
|
+
map.setPaintProperty(id, "fill-color", dynamicFillColor(factor, initialPad, i * (180 / stepLength)));
|
|
401
|
+
await (0, import_delay.delay)(stepLength);
|
|
402
|
+
}
|
|
403
|
+
fadedIn[index] = false;
|
|
404
|
+
};
|
|
405
|
+
let started = false;
|
|
406
|
+
const startAnimation = async () => {
|
|
407
|
+
(0, import_assert2.assertEx)(!started, () => "Animation Already Started");
|
|
408
|
+
started = true;
|
|
409
|
+
while (this.animationStarted) {
|
|
410
|
+
const upLayer = layerTick % layers.length;
|
|
411
|
+
const downLayer = (layerTick + 1) % layers.length;
|
|
412
|
+
const incomingSource = sourceTick % featureSet.length;
|
|
413
|
+
const outgoingSource = (sourceTick + 1) % featureSet.length;
|
|
414
|
+
if (fadedIn[upLayer]) {
|
|
415
|
+
this.updateLayer(map, layers[upLayer], sources[incomingSource]);
|
|
416
|
+
(0, import_forget.forget)(fadeOut(layers[upLayer].id, upLayer));
|
|
417
|
+
}
|
|
418
|
+
if (!fadedIn[downLayer]) {
|
|
419
|
+
this.updateLayer(map, layers[downLayer], sources[outgoingSource]);
|
|
420
|
+
(0, import_forget.forget)(fadeIn(layers[downLayer].id, downLayer));
|
|
421
|
+
}
|
|
422
|
+
while ((fadedIn[upLayer] || !fadedIn[downLayer]) && this.animationStarted) {
|
|
423
|
+
await (0, import_delay.delay)(1e3);
|
|
424
|
+
}
|
|
425
|
+
layerTick++;
|
|
426
|
+
sourceTick++;
|
|
427
|
+
}
|
|
428
|
+
};
|
|
429
|
+
await startAnimation();
|
|
430
|
+
}
|
|
431
|
+
static updateLayer(map, layer, source) {
|
|
432
|
+
const existingSource = map.getSource(layer.source);
|
|
433
|
+
if (existingSource && source.data) {
|
|
434
|
+
existingSource.setData(source.data);
|
|
435
|
+
} else if (source) {
|
|
436
|
+
map.addSource(layer.source, source);
|
|
437
|
+
}
|
|
438
|
+
layer.update(map, true);
|
|
439
|
+
}
|
|
440
|
+
// Build layers each with the same features
|
|
441
|
+
initializeHeatMapSource(layers) {
|
|
442
|
+
const getSource = (_) => {
|
|
443
|
+
const featuresCollection = import_sdk_geo3.GeoJson.featureCollection(this.config.features);
|
|
444
|
+
return import_sdk_geo3.GeoJson.featuresSource(featuresCollection);
|
|
445
|
+
};
|
|
446
|
+
for (const [index, layer] of layers.entries()) {
|
|
447
|
+
const existingSource = this.config.map.getSource(layer.source);
|
|
448
|
+
const source = getSource(index);
|
|
449
|
+
if (existingSource) {
|
|
450
|
+
existingSource.setData((0, import_assert2.assertEx)(source.data));
|
|
451
|
+
} else {
|
|
452
|
+
this.config.map.addSource(layer.source, source);
|
|
453
|
+
}
|
|
454
|
+
layer.update(this.config.map, true);
|
|
455
|
+
}
|
|
456
|
+
return this;
|
|
457
|
+
}
|
|
458
|
+
};
|
|
459
|
+
|
|
460
|
+
// src/MapBoxClasses/MapPoints.ts
|
|
461
|
+
var import_mapbox_gl2 = require("mapbox-gl");
|
|
462
|
+
var MapPoints = class extends MapBase {
|
|
463
|
+
config;
|
|
464
|
+
constructor(config) {
|
|
465
|
+
super(config);
|
|
466
|
+
this.config = config;
|
|
467
|
+
}
|
|
468
|
+
initialMapPositioning(options, initialBounds) {
|
|
469
|
+
let bounds;
|
|
470
|
+
if (initialBounds) {
|
|
471
|
+
bounds = initialBounds;
|
|
472
|
+
} else {
|
|
473
|
+
bounds = new import_mapbox_gl2.LngLatBounds();
|
|
474
|
+
this.config.features.forEach((feature) => {
|
|
475
|
+
bounds.extend(feature.geometry.coordinates);
|
|
476
|
+
});
|
|
477
|
+
}
|
|
478
|
+
this.config.map.setCenter(bounds.getCenter());
|
|
479
|
+
this.config.map.fitBounds(bounds, options);
|
|
480
|
+
return this.config.map;
|
|
481
|
+
}
|
|
482
|
+
};
|
|
483
|
+
|
|
484
|
+
// src/MapBoxClasses/MapSettings.ts
|
|
485
|
+
var import_mapbox_gl3 = require("mapbox-gl");
|
|
486
|
+
var MapSettings = class _MapSettings {
|
|
487
|
+
static geoLocateControl;
|
|
488
|
+
static mapListeners = {
|
|
489
|
+
logData: (ev, map) => {
|
|
490
|
+
const target = map || ev?.target;
|
|
491
|
+
if (target) {
|
|
492
|
+
console.log("zoom", target.getZoom());
|
|
493
|
+
console.log("center", target.getCenter());
|
|
494
|
+
}
|
|
495
|
+
}
|
|
496
|
+
};
|
|
497
|
+
static navControl;
|
|
498
|
+
static requestLocation;
|
|
499
|
+
static toggleControls(value, map, zoom, requestLocation) {
|
|
500
|
+
if (value) {
|
|
501
|
+
_MapSettings.addControls(map, zoom, requestLocation);
|
|
502
|
+
} else {
|
|
503
|
+
_MapSettings.removeControls(map);
|
|
504
|
+
}
|
|
505
|
+
return this;
|
|
506
|
+
}
|
|
507
|
+
static toggleDebugLayer(value, map, layerName) {
|
|
508
|
+
const debugLayer3 = map.getLayer(layerName);
|
|
509
|
+
if (debugLayer3) {
|
|
510
|
+
if (value) {
|
|
511
|
+
map.setLayoutProperty(layerName, "visibility", "visible");
|
|
512
|
+
} else {
|
|
513
|
+
map.setLayoutProperty(layerName, "visibility", "none");
|
|
514
|
+
}
|
|
515
|
+
}
|
|
516
|
+
return this;
|
|
517
|
+
}
|
|
518
|
+
static toggleDebugLogging(value, map) {
|
|
519
|
+
const debugEvents = ["resize", "zoomend", "dragend"];
|
|
520
|
+
if (value) {
|
|
521
|
+
this.mapListeners.logData(void 0, map);
|
|
522
|
+
for (const event of debugEvents) map.on(event, this.mapListeners.logData);
|
|
523
|
+
} else {
|
|
524
|
+
for (const event of debugEvents) map.off(event, this.mapListeners.logData);
|
|
525
|
+
}
|
|
526
|
+
}
|
|
527
|
+
static toggleScrollToZoom(value, map) {
|
|
528
|
+
if (value) {
|
|
529
|
+
map.scrollZoom.enable();
|
|
530
|
+
} else {
|
|
531
|
+
map.scrollZoom.disable();
|
|
532
|
+
}
|
|
533
|
+
return this;
|
|
534
|
+
}
|
|
535
|
+
static updateSettings(config) {
|
|
536
|
+
const { settings, map, zoom, requestLocation, debugLayerName = "" } = config;
|
|
537
|
+
const { scrollToZoom: scrollToZoom3, enableControls, debugLayer: debugLayer3, debugLogging } = settings;
|
|
538
|
+
_MapSettings.toggleControls(enableControls?.value, map, zoom, requestLocation).toggleScrollToZoom(scrollToZoom3?.value, map).toggleDebugLayer(debugLayer3?.value, map, debugLayerName).toggleDebugLogging(debugLogging.value, map);
|
|
539
|
+
}
|
|
540
|
+
// Needs to be static so we ensure controls are only instantiated once
|
|
541
|
+
static addControls(map, zoom, requestLocation) {
|
|
542
|
+
const geolocateControl = new import_mapbox_gl3.GeolocateControl({
|
|
543
|
+
fitBoundsOptions: {
|
|
544
|
+
zoom: zoom || 2
|
|
545
|
+
},
|
|
546
|
+
positionOptions: {
|
|
547
|
+
enableHighAccuracy: true
|
|
548
|
+
},
|
|
549
|
+
trackUserLocation: true
|
|
550
|
+
});
|
|
551
|
+
const navControl = new import_mapbox_gl3.NavigationControl({
|
|
552
|
+
showCompass: false
|
|
553
|
+
});
|
|
554
|
+
this.geoLocateControl = this.geoLocateControl || geolocateControl;
|
|
555
|
+
this.navControl = this.navControl || navControl;
|
|
556
|
+
if (!map.hasControl(this.geoLocateControl) && requestLocation) {
|
|
557
|
+
map.addControl(this.geoLocateControl);
|
|
558
|
+
}
|
|
559
|
+
if (!map.hasControl(this.navControl)) {
|
|
560
|
+
map.addControl(this.navControl, "top-left");
|
|
561
|
+
}
|
|
562
|
+
return this;
|
|
563
|
+
}
|
|
564
|
+
static removeControls(map) {
|
|
565
|
+
if (this.geoLocateControl && map.hasControl(this.geoLocateControl) && this.requestLocation) {
|
|
566
|
+
map.removeControl(this.geoLocateControl);
|
|
567
|
+
}
|
|
568
|
+
if (this.navControl && map.hasControl(this.navControl)) {
|
|
569
|
+
map.removeControl(this.navControl);
|
|
570
|
+
}
|
|
571
|
+
return this;
|
|
572
|
+
}
|
|
573
|
+
};
|
|
574
|
+
|
|
575
|
+
// src/Contexts/MapBoxInstance/Provider.tsx
|
|
576
|
+
var import_react6 = require("react");
|
|
577
|
+
|
|
578
|
+
// src/Contexts/MapBoxInstance/Context.ts
|
|
579
|
+
var import_react5 = require("react");
|
|
580
|
+
var MapBoxInstanceContext = (0, import_react5.createContext)({});
|
|
581
|
+
|
|
582
|
+
// src/Contexts/MapBoxInstance/Provider.tsx
|
|
583
|
+
var import_jsx_runtime = require("react/jsx-runtime");
|
|
584
|
+
var MapBoxInstanceProvider = ({ children }) => {
|
|
585
|
+
const [map, setMapBoxInstance] = (0, import_react6.useState)();
|
|
586
|
+
const [mapInitialized, setMapInitialized] = (0, import_react6.useState)(false);
|
|
587
|
+
const value = { map, mapInitialized, setMapBoxInstance };
|
|
588
|
+
(0, import_react6.useEffect)(() => {
|
|
589
|
+
if (!mapInitialized && map) {
|
|
590
|
+
map?.on("load", () => {
|
|
591
|
+
setMapInitialized(true);
|
|
592
|
+
});
|
|
593
|
+
}
|
|
594
|
+
}, [map, mapInitialized, setMapInitialized]);
|
|
595
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(MapBoxInstanceContext.Provider, { value, children });
|
|
596
|
+
};
|
|
597
|
+
|
|
598
|
+
// src/Contexts/MapBoxInstance/useMapBoxInstance.tsx
|
|
599
|
+
var import_assert3 = require("@xylabs/assert");
|
|
600
|
+
var import_react7 = require("react");
|
|
601
|
+
var useMapBoxInstance = () => {
|
|
602
|
+
const context = (0, import_react7.useContext)(MapBoxInstanceContext);
|
|
603
|
+
(0, import_assert3.assertEx)("map" in context, () => "useMapBoxInstance must be used within a MapBoxInstanceContext");
|
|
604
|
+
return context;
|
|
605
|
+
};
|
|
606
|
+
|
|
607
|
+
// src/Contexts/MapSettings/Provider.tsx
|
|
608
|
+
var import_react9 = require("react");
|
|
609
|
+
|
|
610
|
+
// src/Contexts/MapSettings/Context.ts
|
|
611
|
+
var import_react8 = require("react");
|
|
612
|
+
var MapSettingsContext = (0, import_react8.createContext)({});
|
|
613
|
+
|
|
614
|
+
// src/Contexts/MapSettings/Provider.tsx
|
|
615
|
+
var import_jsx_runtime2 = require("react/jsx-runtime");
|
|
616
|
+
var MapSettingsProvider = ({
|
|
617
|
+
children,
|
|
618
|
+
debugLayerName,
|
|
619
|
+
defaultMapSettings,
|
|
620
|
+
requestLocation,
|
|
621
|
+
zoom = 1
|
|
622
|
+
}) => {
|
|
623
|
+
const [mapSettings, setMapSettings] = (0, import_react9.useState)(defaultMapSettings || {});
|
|
624
|
+
const { map, mapInitialized } = useMapBoxInstance();
|
|
625
|
+
const value = {
|
|
626
|
+
mapSettings,
|
|
627
|
+
setMapSettings
|
|
628
|
+
};
|
|
629
|
+
(0, import_react9.useEffect)(() => {
|
|
630
|
+
if (mapSettings && map && mapInitialized) {
|
|
631
|
+
MapSettings.updateSettings({ debugLayerName, map, requestLocation, settings: mapSettings, zoom });
|
|
632
|
+
}
|
|
633
|
+
}, [debugLayerName, map, mapInitialized, mapSettings, requestLocation, zoom]);
|
|
634
|
+
return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(MapSettingsContext.Provider, { value, children });
|
|
635
|
+
};
|
|
636
|
+
|
|
637
|
+
// src/Contexts/MapSettings/useMapSettings.tsx
|
|
638
|
+
var import_react10 = require("react");
|
|
639
|
+
var useMapSettings = () => {
|
|
640
|
+
const context = (0, import_react10.useContext)(MapSettingsContext);
|
|
641
|
+
return context;
|
|
642
|
+
};
|
|
643
|
+
|
|
644
|
+
// src/Contexts/HeatMapInitializer/Context.ts
|
|
645
|
+
var import_react11 = require("react");
|
|
646
|
+
var HeatMapInitializerContext = (0, import_react11.createContext)({});
|
|
647
|
+
|
|
648
|
+
// src/Contexts/HeatMapInitializer/Provider.tsx
|
|
649
|
+
var import_jsx_runtime3 = require("react/jsx-runtime");
|
|
650
|
+
var HeatMapInitializerProvider = ({
|
|
651
|
+
children,
|
|
652
|
+
featureSets,
|
|
653
|
+
featureSetsLayers,
|
|
654
|
+
features,
|
|
655
|
+
fitToPadding,
|
|
656
|
+
heatMapColorProps,
|
|
657
|
+
layers,
|
|
658
|
+
zoom
|
|
659
|
+
}) => {
|
|
660
|
+
const [mapHeat, setMapHeat] = (0, import_react12.useState)();
|
|
661
|
+
const { options } = useDynamicPositioning();
|
|
662
|
+
const { mapSettings } = useMapSettings();
|
|
663
|
+
const { map, mapInitialized } = useMapBoxInstance();
|
|
664
|
+
const value = {
|
|
665
|
+
MapHeat: mapHeat,
|
|
666
|
+
heatMapColorProps
|
|
667
|
+
};
|
|
668
|
+
(0, import_react12.useEffect)(() => {
|
|
669
|
+
if (mapInitialized && featureSets?.length && featureSets[0].length > 0 && map && featureSetsLayers?.length) {
|
|
670
|
+
const { lowUsageColor, highUsageColor } = heatMapColorProps;
|
|
671
|
+
(0, import_forget2.forget)(MapHeat.initializeAnimatedHeatMapSource(featureSetsLayers, featureSets, map, lowUsageColor, highUsageColor));
|
|
672
|
+
}
|
|
673
|
+
return () => {
|
|
674
|
+
MapHeat.animationStarted = false;
|
|
675
|
+
};
|
|
676
|
+
}, [featureSets, featureSetsLayers, mapInitialized, map, heatMapColorProps]);
|
|
677
|
+
(0, import_react12.useEffect)(() => {
|
|
678
|
+
if (mapHeat && mapInitialized && features?.length && layers?.length) {
|
|
679
|
+
mapHeat.initializeHeatMapSource(layers);
|
|
680
|
+
}
|
|
681
|
+
}, [mapHeat, features?.length, layers, mapInitialized]);
|
|
682
|
+
(0, import_react12.useEffect)(() => {
|
|
683
|
+
if (mapInitialized) {
|
|
684
|
+
const { fitToPoints: fitToPoints3 } = mapSettings || {};
|
|
685
|
+
if (map) {
|
|
686
|
+
if (fitToPoints3?.value === true) {
|
|
687
|
+
MapHeat.initialMapPositioning({ padding: fitToPadding }, map, features);
|
|
688
|
+
} else if (options.zoom && options.center) {
|
|
689
|
+
map.setZoom(options.zoom);
|
|
690
|
+
map.setCenter(options.center);
|
|
691
|
+
}
|
|
692
|
+
}
|
|
693
|
+
}
|
|
694
|
+
}, [mapHeat, map, mapSettings, fitToPadding, options, mapInitialized, features]);
|
|
695
|
+
(0, import_react12.useEffect)(() => {
|
|
696
|
+
if (map && features?.length) {
|
|
697
|
+
setMapHeat(new MapHeat({ features, map, zoom }));
|
|
698
|
+
}
|
|
699
|
+
}, [map, features, zoom]);
|
|
700
|
+
return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(HeatMapInitializerContext.Provider, { value, children });
|
|
701
|
+
};
|
|
702
|
+
|
|
703
|
+
// src/Contexts/HeatMapInitializer/useHeatMapInitializer.tsx
|
|
704
|
+
var import_assert4 = require("@xylabs/assert");
|
|
705
|
+
var import_react13 = require("react");
|
|
706
|
+
var useHeatMapInitializer = () => {
|
|
707
|
+
const context = (0, import_react13.useContext)(HeatMapInitializerContext);
|
|
708
|
+
(0, import_assert4.assertEx)("heatMapInitialized" in context, () => "useHeatMapInitializer must be used within a HeatMapInitializerContext");
|
|
709
|
+
return context;
|
|
710
|
+
};
|
|
711
|
+
|
|
712
|
+
// src/Contexts/MapboxAccessToken/Context.ts
|
|
713
|
+
var import_react_shared2 = require("@xyo-network/react-shared");
|
|
714
|
+
var MapboxAccessTokenContext = (0, import_react_shared2.createContextEx)();
|
|
715
|
+
|
|
716
|
+
// src/Contexts/MapboxAccessToken/Provider.tsx
|
|
717
|
+
var import_react14 = require("react");
|
|
718
|
+
var import_jsx_runtime4 = require("react/jsx-runtime");
|
|
719
|
+
var MapboxAccessTokenProvider = ({ defaultAccessToken, ...props }) => {
|
|
720
|
+
const [accessToken, setAccessToken] = (0, import_react14.useState)();
|
|
721
|
+
return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(MapboxAccessTokenContext.Provider, { value: { accessToken: accessToken ?? defaultAccessToken, provided: true, setAccessToken }, ...props });
|
|
722
|
+
};
|
|
723
|
+
|
|
724
|
+
// src/Contexts/MapboxAccessToken/use.ts
|
|
725
|
+
var import_react_shared3 = require("@xyo-network/react-shared");
|
|
726
|
+
var useMapboxAccessToken = (required = false) => {
|
|
727
|
+
return (0, import_react_shared3.useContextEx)(MapboxAccessTokenContext, "MapboxAccessToken", required);
|
|
728
|
+
};
|
|
729
|
+
|
|
730
|
+
// src/Layers/Configs/HeatMapFillLayerConfig.ts
|
|
731
|
+
var HeatMapFillLayerConfig = (color) => ({
|
|
732
|
+
paint: {
|
|
733
|
+
"fill-color": color,
|
|
734
|
+
"fill-opacity": [
|
|
735
|
+
"let",
|
|
736
|
+
"density",
|
|
737
|
+
["+", ["/", ["number", ["get", "value"]], 4], 0.125],
|
|
738
|
+
["interpolate", ["linear"], ["var", "density"], 0.8, ["var", "density"], 1, 0.85]
|
|
739
|
+
]
|
|
740
|
+
}
|
|
741
|
+
});
|
|
742
|
+
|
|
743
|
+
// src/Layers/Configs/HeatMapLineLayerConfig.ts
|
|
744
|
+
var HeatMapLineLayerConfig = (color) => ({
|
|
745
|
+
layout: {
|
|
746
|
+
// Enable for debugging
|
|
747
|
+
visibility: "none"
|
|
748
|
+
},
|
|
749
|
+
paint: {
|
|
750
|
+
"line-color": color,
|
|
751
|
+
"line-opacity": ["let", "density", 0, ["interpolate", ["linear"], ["var", "density"], 0.8, ["var", "density"], 1, 0.85]],
|
|
752
|
+
"line-width": 0.5
|
|
753
|
+
}
|
|
754
|
+
});
|
|
755
|
+
|
|
756
|
+
// src/Layers/Configs/HeatMapSymbolLayerConfig.ts
|
|
757
|
+
var HeatMapSymbolLayerConfig = (color) => ({
|
|
758
|
+
layout: {
|
|
759
|
+
"text-anchor": "center",
|
|
760
|
+
"text-field": [
|
|
761
|
+
"concat",
|
|
762
|
+
"value: ",
|
|
763
|
+
["to-string", ["+", ["/", ["number", ["get", "value"]], 2], 0.25]],
|
|
764
|
+
"\n",
|
|
765
|
+
"count: ",
|
|
766
|
+
["to-string", ["get", "count"]]
|
|
767
|
+
],
|
|
768
|
+
"text-size": 10,
|
|
769
|
+
visibility: "none"
|
|
770
|
+
},
|
|
771
|
+
paint: {
|
|
772
|
+
"text-color": color
|
|
773
|
+
}
|
|
774
|
+
});
|
|
775
|
+
|
|
776
|
+
// src/Layers/Configs/LocationPointLayerConfig.ts
|
|
777
|
+
var LocationPointLayerConfig = (color, circleRadius, circleOpacity) => {
|
|
778
|
+
return {
|
|
779
|
+
paint: {
|
|
780
|
+
"circle-color": color,
|
|
781
|
+
"circle-opacity": circleOpacity,
|
|
782
|
+
"circle-radius": circleRadius
|
|
783
|
+
}
|
|
784
|
+
};
|
|
785
|
+
};
|
|
786
|
+
|
|
787
|
+
// src/Layers/FillLayer.ts
|
|
788
|
+
var import_sdk_geo4 = require("@xyo-network/sdk-geo");
|
|
789
|
+
var FillLayerBuilder = class extends import_sdk_geo4.LayerBase {
|
|
790
|
+
FillLayerOptions;
|
|
791
|
+
// ensures this class passes for `AnyLayer` type in MapBox
|
|
792
|
+
type = "fill";
|
|
793
|
+
constructor(id, source, FillLayerOptions) {
|
|
794
|
+
super(id, source);
|
|
795
|
+
this.FillLayerOptions = FillLayerOptions || { id: this.id, source: this.source };
|
|
796
|
+
}
|
|
797
|
+
buildLayer() {
|
|
798
|
+
return {
|
|
799
|
+
...this.FillLayerOptions,
|
|
800
|
+
id: this.id,
|
|
801
|
+
source: this.source,
|
|
802
|
+
type: this.type
|
|
803
|
+
};
|
|
804
|
+
}
|
|
805
|
+
};
|
|
806
|
+
|
|
807
|
+
// src/Layers/LineLayer.ts
|
|
808
|
+
var import_sdk_geo5 = require("@xyo-network/sdk-geo");
|
|
809
|
+
var LineLayerBuilder = class extends import_sdk_geo5.LayerBase {
|
|
810
|
+
LineLayerOptions;
|
|
811
|
+
// ensures this class passes for `AnyLayer` type in MapBox
|
|
812
|
+
type = "line";
|
|
813
|
+
constructor(id, source, LineLayerOptions) {
|
|
814
|
+
super(id, source);
|
|
815
|
+
this.LineLayerOptions = LineLayerOptions || { id: this.id, source: this.source };
|
|
816
|
+
}
|
|
817
|
+
buildLayer() {
|
|
818
|
+
return {
|
|
819
|
+
...this.LineLayerOptions,
|
|
820
|
+
id: this.id,
|
|
821
|
+
layout: {},
|
|
822
|
+
source: this.source,
|
|
823
|
+
type: this.type
|
|
824
|
+
};
|
|
825
|
+
}
|
|
826
|
+
};
|
|
827
|
+
|
|
828
|
+
// src/Layers/SymbolLayer.ts
|
|
829
|
+
var import_sdk_geo6 = require("@xyo-network/sdk-geo");
|
|
830
|
+
var SymbolLayerBuilder = class extends import_sdk_geo6.LayerBase {
|
|
831
|
+
SymbolLayerOptions;
|
|
832
|
+
// ensures this class passes for `AnyLayer` type in MapBox
|
|
833
|
+
type = "symbol";
|
|
834
|
+
constructor(id, source, SymbolLayerOptions) {
|
|
835
|
+
super(id, source);
|
|
836
|
+
this.SymbolLayerOptions = SymbolLayerOptions || { id: this.id, source: this.source };
|
|
837
|
+
}
|
|
838
|
+
buildLayer() {
|
|
839
|
+
return {
|
|
840
|
+
...this.SymbolLayerOptions,
|
|
841
|
+
id: this.id,
|
|
842
|
+
source: this.source,
|
|
843
|
+
type: this.type
|
|
844
|
+
};
|
|
845
|
+
}
|
|
846
|
+
};
|
|
847
|
+
|
|
848
|
+
// src/Layers/Builders/LocationHeatMapLayerBuilder.ts
|
|
849
|
+
var MapHeatConstants = {
|
|
850
|
+
LocationDebugLayerId: "location-debug-id",
|
|
851
|
+
LocationDebugLayerSource: "location-debug-source",
|
|
852
|
+
LocationFillLayerId: "location-fill-id",
|
|
853
|
+
LocationFillLayerSource: "location-fill-source",
|
|
854
|
+
LocationLineLayerId: "location-line-id",
|
|
855
|
+
LocationLineLayerSource: "location-line-source"
|
|
856
|
+
};
|
|
857
|
+
var LocationHeatMapLayerBuilder = (color, alternateColor = "#000") => {
|
|
858
|
+
const {
|
|
859
|
+
LocationFillLayerId,
|
|
860
|
+
LocationFillLayerSource,
|
|
861
|
+
LocationLineLayerId,
|
|
862
|
+
LocationLineLayerSource,
|
|
863
|
+
LocationDebugLayerId,
|
|
864
|
+
LocationDebugLayerSource
|
|
865
|
+
} = MapHeatConstants;
|
|
866
|
+
const fillLayerConfig = HeatMapFillLayerConfig(color);
|
|
867
|
+
const lineLayerConfig = HeatMapLineLayerConfig(color);
|
|
868
|
+
const debugLayerConfig = HeatMapSymbolLayerConfig(alternateColor);
|
|
869
|
+
const fillLayer = new FillLayerBuilder(LocationFillLayerId, LocationFillLayerSource, fillLayerConfig);
|
|
870
|
+
const lineLayer = new LineLayerBuilder(LocationLineLayerId, LocationLineLayerSource, lineLayerConfig);
|
|
871
|
+
const debugLayer3 = new SymbolLayerBuilder(LocationDebugLayerId, LocationDebugLayerSource, debugLayerConfig);
|
|
872
|
+
return [fillLayer, lineLayer, debugLayer3];
|
|
873
|
+
};
|
|
874
|
+
|
|
875
|
+
// src/Layers/Builders/LocationHeatMapLayerBuilderAnimated.ts
|
|
876
|
+
var MapHeatConstants2 = (index, type) => ({
|
|
877
|
+
LocationDebugLayerId: `location-${type}-debug-id-${index}`,
|
|
878
|
+
LocationDebugLayerSource: `location-${type}-debug-source-${index}`,
|
|
879
|
+
LocationFillLayerId: `location-${type}-fill-id-${index}`,
|
|
880
|
+
LocationFillLayerSource: `location-${type}-fill-source-${index}`,
|
|
881
|
+
LocationLineLayerId: `location-${type}-line-id-${index}`,
|
|
882
|
+
LocationLineLayerSource: `location-${type}-line-source-${index}`
|
|
883
|
+
});
|
|
884
|
+
var LocationHeatMapLayerBuilderAnimated = (color, index, type = "") => {
|
|
885
|
+
const { LocationFillLayerId, LocationFillLayerSource } = MapHeatConstants2(index, type);
|
|
886
|
+
const fillLayerConfig = HeatMapFillLayerConfig(color);
|
|
887
|
+
const fillLayer = new FillLayerBuilder(LocationFillLayerId, LocationFillLayerSource, fillLayerConfig);
|
|
888
|
+
return fillLayer;
|
|
889
|
+
};
|
|
890
|
+
|
|
891
|
+
// src/Layers/CircleLayer.ts
|
|
892
|
+
var import_sdk_geo7 = require("@xyo-network/sdk-geo");
|
|
893
|
+
var CircleLayerBuilder = class extends import_sdk_geo7.LayerBase {
|
|
894
|
+
CircleLayerOptions;
|
|
895
|
+
// ensures this class passes for `AnyLayer` type in MapBox
|
|
896
|
+
type = "circle";
|
|
897
|
+
constructor(id, source, CircleLayerOptions) {
|
|
898
|
+
super(id, source);
|
|
899
|
+
this.CircleLayerOptions = CircleLayerOptions || { id: this.id, source: this.source, type: "circle" };
|
|
900
|
+
}
|
|
901
|
+
buildLayer() {
|
|
902
|
+
return {
|
|
903
|
+
filter: ["==", "$type", "Point"],
|
|
904
|
+
layout: {},
|
|
905
|
+
paint: {
|
|
906
|
+
"circle-color": "#ff0000",
|
|
907
|
+
"circle-radius": 6
|
|
908
|
+
},
|
|
909
|
+
type: this.type,
|
|
910
|
+
...this.CircleLayerOptions,
|
|
911
|
+
id: this.id,
|
|
912
|
+
source: this.source
|
|
913
|
+
};
|
|
914
|
+
}
|
|
915
|
+
};
|
|
916
|
+
|
|
917
|
+
// src/Layers/Builders/LocationPointsMapLayerBuilder.ts
|
|
918
|
+
var MapPointsConstants = {
|
|
919
|
+
LocationDotsLayerId: "location-dots",
|
|
920
|
+
LocationDotsLayerSource: "location-dots-source"
|
|
921
|
+
};
|
|
922
|
+
var LocationPointsMapLayerBuilder = (color, circleRadius = 6, circleOpacity = 0.8) => {
|
|
923
|
+
const { LocationDotsLayerId, LocationDotsLayerSource } = MapPointsConstants;
|
|
924
|
+
const dotLayerConfig = LocationPointLayerConfig(color, circleRadius, circleOpacity);
|
|
925
|
+
const dotLayer = new CircleLayerBuilder(LocationDotsLayerId, LocationDotsLayerSource, dotLayerConfig);
|
|
926
|
+
return [dotLayer];
|
|
927
|
+
};
|
|
928
|
+
|
|
929
|
+
// src/Components/MapBoxHeat.tsx
|
|
930
|
+
var import_react_flexbox2 = require("@xylabs/react-flexbox");
|
|
931
|
+
|
|
932
|
+
// src/Components/MapBox.tsx
|
|
933
|
+
var import_mapbox_gl4 = require("mapbox-gl/dist/mapbox-gl.css");
|
|
934
|
+
var import_mapbox_gl5 = require("mapbox-gl");
|
|
935
|
+
var import_react15 = require("react");
|
|
936
|
+
|
|
937
|
+
// src/lib/MapStyle.ts
|
|
938
|
+
var MapStyle = /* @__PURE__ */ ((MapStyle2) => {
|
|
939
|
+
MapStyle2["Dark"] = "mapbox/dark-v10";
|
|
940
|
+
MapStyle2["Light"] = "mapbox/light-v10";
|
|
941
|
+
MapStyle2["Outdoors"] = "mapbox/outdoors-v11";
|
|
942
|
+
MapStyle2["Satellite"] = "mapbox/satellite-v9";
|
|
943
|
+
MapStyle2["SatelliteStreets"] = "mapbox/satellite-streets-v11";
|
|
944
|
+
MapStyle2["Streets"] = "mapbox/streets-v11";
|
|
945
|
+
return MapStyle2;
|
|
946
|
+
})(MapStyle || {});
|
|
947
|
+
|
|
948
|
+
// src/Components/MapBox.tsx
|
|
949
|
+
var import_jsx_runtime5 = require("react/jsx-runtime");
|
|
950
|
+
var MapBox = ({ accessToken, darkMode = false, options, zoom = 2, ...props }) => {
|
|
951
|
+
const [map, setMap] = (0, import_react15.useState)();
|
|
952
|
+
const mapContainerRef = (0, import_react15.useRef)(null);
|
|
953
|
+
const mapCanvasRef = (0, import_react15.useRef)(null);
|
|
954
|
+
const { setMapBoxInstance, map: mapInstance } = useMapBoxInstance();
|
|
955
|
+
const { mapSettings } = useMapSettings();
|
|
956
|
+
const activeResize = mapSettings?.dynamicMapResize.value;
|
|
957
|
+
useDynamicMapResize(mapContainerRef, mapCanvasRef, mapInstance, activeResize);
|
|
958
|
+
(0, import_react15.useEffect)(() => {
|
|
959
|
+
if (mapSettings?.preferDark?.value === true) {
|
|
960
|
+
map?.setStyle(`mapbox://styles/${"mapbox/dark-v10" /* Dark */}`);
|
|
961
|
+
} else {
|
|
962
|
+
map?.setStyle(`mapbox://styles/${darkMode ? "mapbox/dark-v10" /* Dark */ : "mapbox/light-v10" /* Light */}`);
|
|
963
|
+
}
|
|
964
|
+
}, [map, darkMode, mapSettings]);
|
|
965
|
+
(0, import_react15.useEffect)(() => {
|
|
966
|
+
const map2 = new import_mapbox_gl5.Map({
|
|
967
|
+
accessToken,
|
|
968
|
+
center: [0, 0],
|
|
969
|
+
container: mapContainerRef.current ?? "",
|
|
970
|
+
style: `mapbox://styles/${"mapbox/light-v10" /* Light */}`,
|
|
971
|
+
zoom,
|
|
972
|
+
...options
|
|
973
|
+
});
|
|
974
|
+
setMapBoxInstance?.(map2);
|
|
975
|
+
setMap(map2);
|
|
976
|
+
mapCanvasRef.current = document.querySelector(".mapboxgl-canvas");
|
|
977
|
+
console.log("Created Map");
|
|
978
|
+
return () => {
|
|
979
|
+
console.log("Removing Map");
|
|
980
|
+
map2.remove();
|
|
981
|
+
};
|
|
982
|
+
}, [mapContainerRef, setMap, options, zoom, setMapBoxInstance, accessToken]);
|
|
983
|
+
return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
|
|
984
|
+
"div",
|
|
985
|
+
{
|
|
986
|
+
ref: (el) => mapContainerRef.current = el,
|
|
987
|
+
style: {
|
|
988
|
+
bottom: 0,
|
|
989
|
+
left: 0,
|
|
990
|
+
position: "absolute",
|
|
991
|
+
right: 0,
|
|
992
|
+
top: 0,
|
|
993
|
+
...props
|
|
994
|
+
}
|
|
995
|
+
}
|
|
996
|
+
);
|
|
997
|
+
};
|
|
998
|
+
|
|
999
|
+
// src/Components/MapSettingsComponents/Setting.tsx
|
|
1000
|
+
var import_material2 = require("@mui/material");
|
|
1001
|
+
var import_jsx_runtime6 = require("react/jsx-runtime");
|
|
1002
|
+
var MapSettingSwitch = ({ developerMode, field, ...props }) => {
|
|
1003
|
+
const { mapSettings, setMapSettings } = useMapSettings();
|
|
1004
|
+
const setting = mapSettings?.[field];
|
|
1005
|
+
const onLocalChange = (event) => {
|
|
1006
|
+
if (setting) {
|
|
1007
|
+
setMapSettings?.((previous) => {
|
|
1008
|
+
previous[setting.field].value = event.target.checked;
|
|
1009
|
+
return { ...previous };
|
|
1010
|
+
});
|
|
1011
|
+
}
|
|
1012
|
+
};
|
|
1013
|
+
if (setting?.devMode && developerMode === false) {
|
|
1014
|
+
return null;
|
|
1015
|
+
}
|
|
1016
|
+
return setting?.hidden ? null : /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(import_material2.FormControlLabel, { label: setting?.label, control: /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(import_material2.Switch, { checked: setting?.value, onChange: onLocalChange, ...props }) });
|
|
1017
|
+
};
|
|
1018
|
+
|
|
1019
|
+
// src/Components/MapSettingsComponents/SettingsBox.tsx
|
|
1020
|
+
var import_material3 = require("@mui/material");
|
|
1021
|
+
var import_react_flexbox = require("@xylabs/react-flexbox");
|
|
1022
|
+
var import_react_app_settings = require("@xyo-network/react-app-settings");
|
|
1023
|
+
var import_jsx_runtime7 = require("react/jsx-runtime");
|
|
1024
|
+
var MapSettingsBox = ({ developerMode, ...props }) => {
|
|
1025
|
+
const { mapSettings } = useMapSettings();
|
|
1026
|
+
const { developerMode: devModeFromContext } = (0, import_react_app_settings.useAppSettings)();
|
|
1027
|
+
const resolveDeveloperMode = developerMode ?? devModeFromContext;
|
|
1028
|
+
return mapSettings && resolveDeveloperMode ? /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(import_react_flexbox.FlexGrowRow, { bottom: 36, left: 10, position: "absolute", ...props, children: /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(import_react_flexbox.FlexRow, { paddingX: 2, children: /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(import_material3.Paper, { children: /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(import_material3.Stack, { direction: "row", spacing: 1, marginX: 1, children: Object.keys(mapSettings).map((key, index) => {
|
|
1029
|
+
return /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(MapSettingSwitch, { field: mapSettings[key].field, developerMode }, index);
|
|
1030
|
+
}) }) }) }) }) : null;
|
|
1031
|
+
};
|
|
1032
|
+
|
|
1033
|
+
// src/Components/MapBoxHeat.tsx
|
|
1034
|
+
var import_jsx_runtime8 = require("react/jsx-runtime");
|
|
1035
|
+
var MapboxHeatFlexBox = ({ accessToken, children, mapBoxOptions, zoom, legend, developerMode, ...props }) => {
|
|
1036
|
+
return /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)(import_react_flexbox2.FlexCol, { ...props, children: [
|
|
1037
|
+
/* @__PURE__ */ (0, import_jsx_runtime8.jsx)(MapBox, { accessToken, options: mapBoxOptions, zoom }),
|
|
1038
|
+
/* @__PURE__ */ (0, import_jsx_runtime8.jsx)(MapSettingsBox, { developerMode }),
|
|
1039
|
+
legend,
|
|
1040
|
+
children
|
|
1041
|
+
] });
|
|
1042
|
+
};
|
|
1043
|
+
|
|
1044
|
+
// src/Components/AnimatedHeatMap.tsx
|
|
1045
|
+
var import_jsx_runtime9 = require("react/jsx-runtime");
|
|
1046
|
+
var AnimatedHeatMap = ({
|
|
1047
|
+
accessToken,
|
|
1048
|
+
animatedFeatureSets,
|
|
1049
|
+
defaultMapSettings,
|
|
1050
|
+
heatMapColorProps,
|
|
1051
|
+
staticFeatureSet,
|
|
1052
|
+
...props
|
|
1053
|
+
}) => {
|
|
1054
|
+
const theme = (0, import_material4.useTheme)();
|
|
1055
|
+
const { staticMapColor, lowUsageColor, highUsageColor } = heatMapColorProps || {};
|
|
1056
|
+
const localStaticMapColor = staticMapColor ?? theme.palette.primary.light;
|
|
1057
|
+
const [layers] = (0, import_react16.useState)([
|
|
1058
|
+
LocationHeatMapLayerBuilderAnimated(localStaticMapColor, 0, "static"),
|
|
1059
|
+
LocationHeatMapLayerBuilderAnimated(lowUsageColor || localStaticMapColor, 0, "animated"),
|
|
1060
|
+
LocationHeatMapLayerBuilderAnimated(highUsageColor || (0, import_material4.darken)(localStaticMapColor, 0.9), 1, "animated")
|
|
1061
|
+
]);
|
|
1062
|
+
return animatedFeatureSets?.length ? /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(MapBoxInstanceProvider, { children: /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(MapSettingsProvider, { defaultMapSettings, debugLayerName: MapHeatConstants.LocationDebugLayerId, children: /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(
|
|
1063
|
+
HeatMapInitializerProvider,
|
|
1064
|
+
{
|
|
1065
|
+
features: staticFeatureSet,
|
|
1066
|
+
layers: [layers[0]],
|
|
1067
|
+
featureSets: animatedFeatureSets,
|
|
1068
|
+
featureSetsLayers: layers.slice(1, 3),
|
|
1069
|
+
heatMapColorProps,
|
|
1070
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(MapboxHeatFlexBox, { accessToken, ...props })
|
|
1071
|
+
}
|
|
1072
|
+
) }) }) : /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(import_react_flexbox3.FlexCol, { minHeight: 160, minWidth: 160, busy: true });
|
|
1073
|
+
};
|
|
1074
|
+
|
|
1075
|
+
// src/Components/AnimatedHeatMapLoaded.tsx
|
|
1076
|
+
var import_material7 = require("@mui/material");
|
|
1077
|
+
var import_react_flexbox6 = require("@xylabs/react-flexbox");
|
|
1078
|
+
var import_react_archivist = require("@xyo-network/react-archivist");
|
|
1079
|
+
|
|
1080
|
+
// src/Components/Legend.tsx
|
|
1081
|
+
var import_material6 = require("@mui/material");
|
|
1082
|
+
var import_react_flexbox5 = require("@xylabs/react-flexbox");
|
|
1083
|
+
|
|
1084
|
+
// src/Components/Legends/ColorGradient.tsx
|
|
1085
|
+
var import_material5 = require("@mui/material");
|
|
1086
|
+
var import_react_flexbox4 = require("@xylabs/react-flexbox");
|
|
1087
|
+
var import_jsx_runtime10 = require("react/jsx-runtime");
|
|
1088
|
+
var ColorGradientLegend = ({ startColor, endColor, startLabel, endLabel, heading, textColor, ...props }) => {
|
|
1089
|
+
const theme = (0, import_material5.useTheme)();
|
|
1090
|
+
return /* @__PURE__ */ (0, import_jsx_runtime10.jsxs)(import_react_flexbox4.FlexCol, { ...props, children: [
|
|
1091
|
+
/* @__PURE__ */ (0, import_jsx_runtime10.jsx)(import_material5.Typography, { mb: theme.spacing(0.25), color: textColor, variant: "caption", textAlign: "center", children: heading }),
|
|
1092
|
+
/* @__PURE__ */ (0, import_jsx_runtime10.jsx)(import_react_flexbox4.FlexCol, { flexGrow: 1, alignItems: "stretch", paddingX: theme.spacing(1), mb: theme.spacing(0.25), children: /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(
|
|
1093
|
+
import_react_flexbox4.FlexCol,
|
|
1094
|
+
{
|
|
1095
|
+
height: theme.spacing(0.75),
|
|
1096
|
+
border: `1px solid ${textColor}`,
|
|
1097
|
+
sx: { backgroundImage: `linear-gradient(to right, ${startColor},${endColor})` }
|
|
1098
|
+
}
|
|
1099
|
+
) }),
|
|
1100
|
+
/* @__PURE__ */ (0, import_jsx_runtime10.jsxs)(import_react_flexbox4.FlexRow, { flexGrow: 1, justifyContent: "space-between", children: [
|
|
1101
|
+
/* @__PURE__ */ (0, import_jsx_runtime10.jsx)(import_material5.Typography, { color: textColor, variant: "caption", children: startLabel }),
|
|
1102
|
+
/* @__PURE__ */ (0, import_jsx_runtime10.jsx)(import_material5.Typography, { color: textColor, variant: "caption", children: endLabel })
|
|
1103
|
+
] })
|
|
1104
|
+
] });
|
|
1105
|
+
};
|
|
1106
|
+
|
|
1107
|
+
// src/Components/Legend.tsx
|
|
1108
|
+
var import_jsx_runtime11 = require("react/jsx-runtime");
|
|
1109
|
+
var AnimatedHeatMapLegend = ({ ...legendProps }) => {
|
|
1110
|
+
const { startColor, endColor, startLabel, endLabel, heading, textColor } = legendProps;
|
|
1111
|
+
const theme = (0, import_material6.useTheme)();
|
|
1112
|
+
const isSmall = (0, import_material6.useMediaQuery)(theme.breakpoints.down("sm"));
|
|
1113
|
+
return /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(import_react_flexbox5.FlexCol, { position: "absolute", bottom: 0, right: 0, children: /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(
|
|
1114
|
+
ColorGradientLegend,
|
|
1115
|
+
{
|
|
1116
|
+
startColor,
|
|
1117
|
+
endColor,
|
|
1118
|
+
startLabel,
|
|
1119
|
+
endLabel,
|
|
1120
|
+
heading,
|
|
1121
|
+
textColor,
|
|
1122
|
+
...{
|
|
1123
|
+
alignItems: "stretch",
|
|
1124
|
+
marginBottom: theme.spacing(4),
|
|
1125
|
+
marginLeft: isSmall ? theme.spacing(3) : 0,
|
|
1126
|
+
marginRight: isSmall ? theme.spacing(2) : theme.spacing(3),
|
|
1127
|
+
width: isSmall ? "40vw" : theme.spacing(18)
|
|
1128
|
+
}
|
|
1129
|
+
}
|
|
1130
|
+
) });
|
|
1131
|
+
};
|
|
1132
|
+
|
|
1133
|
+
// src/Components/AnimatedHeatMapLoaded.tsx
|
|
1134
|
+
var import_jsx_runtime12 = require("react/jsx-runtime");
|
|
1135
|
+
var AnimatedHeatMapLoaded = ({ accessToken, archivistNameOrAddress, ...props }) => {
|
|
1136
|
+
const hashes = useFindHashes();
|
|
1137
|
+
const [archivist] = (0, import_react_archivist.useWeakArchivistFromNode)(archivistNameOrAddress);
|
|
1138
|
+
const [payloads, xyoError] = (0, import_react_archivist.useWeakArchivistGet)(archivist, hashes);
|
|
1139
|
+
const { multipleFeatureSets } = useQuadKeyPayloadsToFeatures(payloads);
|
|
1140
|
+
const { heatMapColorProps, legendProps } = useHeatMapColors();
|
|
1141
|
+
const MapBoxHeatProps = {
|
|
1142
|
+
flexGrow: 1,
|
|
1143
|
+
legend: legendProps ? /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(AnimatedHeatMapLegend, { ...legendProps }) : null
|
|
1144
|
+
};
|
|
1145
|
+
return /* @__PURE__ */ (0, import_jsx_runtime12.jsxs)(import_react_flexbox6.FlexCol, { alignItems: "stretch", ...props, children: [
|
|
1146
|
+
xyoError ? /* @__PURE__ */ (0, import_jsx_runtime12.jsxs)(import_material7.Alert, { sx: { mt: 2 }, children: [
|
|
1147
|
+
/* @__PURE__ */ (0, import_jsx_runtime12.jsx)(import_material7.AlertTitle, { children: "Error Loading Map" }),
|
|
1148
|
+
xyoError.message ? `Error: ${xyoError.message}` : null,
|
|
1149
|
+
"You might try authenticating again."
|
|
1150
|
+
] }) : null,
|
|
1151
|
+
hashes === void 0 ? /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(import_material7.Alert, { children: "Missing answer hash for heat map query" }) : /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(
|
|
1152
|
+
AnimatedHeatMap,
|
|
1153
|
+
{
|
|
1154
|
+
accessToken,
|
|
1155
|
+
defaultMapSettings: AnimatedHeatMapSettings,
|
|
1156
|
+
animatedFeatureSets: multipleFeatureSets.slice(1, multipleFeatureSets.length),
|
|
1157
|
+
staticFeatureSet: multipleFeatureSets[0],
|
|
1158
|
+
heatMapColorProps,
|
|
1159
|
+
...MapBoxHeatProps
|
|
1160
|
+
}
|
|
1161
|
+
)
|
|
1162
|
+
] });
|
|
1163
|
+
};
|
|
1164
|
+
|
|
1165
|
+
// src/Components/HeatMapSettings.ts
|
|
1166
|
+
var HeatMapSettings = DefaultMapSettings();
|
|
1167
|
+
var { debugLayer: debugLayer2, scrollToZoom: scrollToZoom2, fitToPoints: fitToPoints2 } = HeatMapSettings;
|
|
1168
|
+
debugLayer2.hidden = false;
|
|
1169
|
+
scrollToZoom2.value = true;
|
|
1170
|
+
fitToPoints2.value = true;
|
|
1171
|
+
|
|
1172
|
+
// src/Components/LayerAnimator.tsx
|
|
1173
|
+
var import_react_shared4 = require("@xylabs/react-shared");
|
|
1174
|
+
var import_react17 = require("react");
|
|
1175
|
+
var import_jsx_runtime13 = require("react/jsx-runtime");
|
|
1176
|
+
var timeIncrement = 2e3;
|
|
1177
|
+
var animatedLayerCount = 3;
|
|
1178
|
+
var LayerAnimator = ({ animateLayers, children, layers, layersInitialized, map }) => {
|
|
1179
|
+
const [fillLayers, setFillLayers] = (0, import_react17.useState)([]);
|
|
1180
|
+
const layerIndexQueue = (0, import_react17.useRef)([]);
|
|
1181
|
+
const incrementQueue = (0, import_react17.useCallback)(
|
|
1182
|
+
(index) => {
|
|
1183
|
+
if (fillLayers[index]) {
|
|
1184
|
+
layerIndexQueue.current.push(index);
|
|
1185
|
+
} else {
|
|
1186
|
+
layerIndexQueue.current.push(0);
|
|
1187
|
+
}
|
|
1188
|
+
return layerIndexQueue.current.at(-1);
|
|
1189
|
+
},
|
|
1190
|
+
[fillLayers]
|
|
1191
|
+
);
|
|
1192
|
+
const lastQueuedIndex = (0, import_react17.useCallback)(() => {
|
|
1193
|
+
const last = layerIndexQueue.current.at(-1);
|
|
1194
|
+
if (last === void 0) {
|
|
1195
|
+
incrementQueue(0);
|
|
1196
|
+
return 0;
|
|
1197
|
+
} else {
|
|
1198
|
+
return last;
|
|
1199
|
+
}
|
|
1200
|
+
}, [incrementQueue]);
|
|
1201
|
+
const unshiftQueue = (0, import_react17.useCallback)(() => {
|
|
1202
|
+
layerIndexQueue.current.shift();
|
|
1203
|
+
}, []);
|
|
1204
|
+
const getNextLayer = (0, import_react17.useCallback)(() => {
|
|
1205
|
+
const nextLayer = fillLayers[lastQueuedIndex()];
|
|
1206
|
+
incrementQueue(lastQueuedIndex() + 1);
|
|
1207
|
+
return nextLayer;
|
|
1208
|
+
}, [fillLayers, incrementQueue, lastQueuedIndex]);
|
|
1209
|
+
const layerAnimateWorker = (0, import_react17.useCallback)(
|
|
1210
|
+
(layer) => {
|
|
1211
|
+
if (layer) {
|
|
1212
|
+
map?.setPaintProperty(layer.id, "fill-opacity", 0.85);
|
|
1213
|
+
setTimeout(() => {
|
|
1214
|
+
map?.setPaintProperty(layer.id, "fill-opacity", 0);
|
|
1215
|
+
unshiftQueue();
|
|
1216
|
+
}, timeIncrement * 2);
|
|
1217
|
+
} else {
|
|
1218
|
+
console.warn("tried to queue an empty layer");
|
|
1219
|
+
}
|
|
1220
|
+
},
|
|
1221
|
+
[map, unshiftQueue]
|
|
1222
|
+
);
|
|
1223
|
+
(0, import_react17.useEffect)(() => {
|
|
1224
|
+
if (layers?.length && map && layersInitialized) {
|
|
1225
|
+
setFillLayers(
|
|
1226
|
+
layers.filter((layer) => {
|
|
1227
|
+
const fillLayer = layer.id.startsWith("location-fill");
|
|
1228
|
+
if (fillLayer) {
|
|
1229
|
+
map.setPaintProperty(layer.id, "fill-opacity-transition", { delay: 0, duration: 4e3 });
|
|
1230
|
+
}
|
|
1231
|
+
return fillLayer;
|
|
1232
|
+
})
|
|
1233
|
+
);
|
|
1234
|
+
}
|
|
1235
|
+
}, [layers, layersInitialized, map]);
|
|
1236
|
+
const queueLayerAnimation = (0, import_react17.useCallback)(() => {
|
|
1237
|
+
const animatedLayers = [];
|
|
1238
|
+
for (let i = 0; i < animatedLayerCount; i++) {
|
|
1239
|
+
animatedLayers.push(getNextLayer());
|
|
1240
|
+
}
|
|
1241
|
+
for (const [index, layer] of animatedLayers.entries()) {
|
|
1242
|
+
if (index === 0) {
|
|
1243
|
+
layerAnimateWorker(layer);
|
|
1244
|
+
} else {
|
|
1245
|
+
setTimeout(() => {
|
|
1246
|
+
layerAnimateWorker(layer);
|
|
1247
|
+
}, timeIncrement * index);
|
|
1248
|
+
}
|
|
1249
|
+
}
|
|
1250
|
+
}, [getNextLayer, layerAnimateWorker]);
|
|
1251
|
+
(0, import_react17.useEffect)(() => {
|
|
1252
|
+
if (animateLayers && layersInitialized && map && fillLayers.length > 0) {
|
|
1253
|
+
queueLayerAnimation();
|
|
1254
|
+
}
|
|
1255
|
+
}, [animateLayers, fillLayers.length, layersInitialized, map, queueLayerAnimation]);
|
|
1256
|
+
(0, import_react_shared4.useInterval)(() => {
|
|
1257
|
+
if (animateLayers && layersInitialized && map && fillLayers.length > 0) {
|
|
1258
|
+
queueLayerAnimation();
|
|
1259
|
+
}
|
|
1260
|
+
}, timeIncrement * animatedLayerCount);
|
|
1261
|
+
return /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(import_jsx_runtime13.Fragment, { children });
|
|
1262
|
+
};
|
|
1263
|
+
|
|
1264
|
+
// src/Components/MapBoxPoints.tsx
|
|
1265
|
+
var import_material8 = require("@mui/material");
|
|
1266
|
+
var import_react_flexbox7 = require("@xylabs/react-flexbox");
|
|
1267
|
+
var import_react18 = require("react");
|
|
1268
|
+
var import_jsx_runtime14 = require("react/jsx-runtime");
|
|
1269
|
+
var MapboxPointsFlexBox = ({
|
|
1270
|
+
accessToken,
|
|
1271
|
+
features,
|
|
1272
|
+
fitToPointsPadding = 20,
|
|
1273
|
+
layers,
|
|
1274
|
+
zoom,
|
|
1275
|
+
...props
|
|
1276
|
+
}) => {
|
|
1277
|
+
const [mapPoints, setMapPoints] = (0, import_react18.useState)();
|
|
1278
|
+
const { mapSettings } = useMapSettings();
|
|
1279
|
+
const { map, mapInitialized } = useMapBoxInstance();
|
|
1280
|
+
const customFitToBoundsOptions = (zoom2) => {
|
|
1281
|
+
if (zoom2 !== void 0) {
|
|
1282
|
+
return {
|
|
1283
|
+
maxZoom: zoom2
|
|
1284
|
+
};
|
|
1285
|
+
}
|
|
1286
|
+
return {};
|
|
1287
|
+
};
|
|
1288
|
+
const updateFeatures = (0, import_react18.useCallback)(() => {
|
|
1289
|
+
if (mapPoints?.isMapReady && features?.length && layers)
|
|
1290
|
+
for (const layer of layers) {
|
|
1291
|
+
mapPoints.initializeMapSource(layer);
|
|
1292
|
+
}
|
|
1293
|
+
}, [mapPoints, features, layers]);
|
|
1294
|
+
const updateMapSetup = (0, import_react18.useCallback)(() => {
|
|
1295
|
+
const { fitToPoints: fitToPoints3 } = mapSettings || {};
|
|
1296
|
+
if (mapPoints && map && fitToPoints3?.value === true) {
|
|
1297
|
+
mapPoints.initialMapPositioning({ padding: fitToPointsPadding, ...customFitToBoundsOptions(zoom) });
|
|
1298
|
+
}
|
|
1299
|
+
}, [mapSettings, mapPoints, map, fitToPointsPadding, zoom]);
|
|
1300
|
+
const reInitializeMap = (0, import_react18.useCallback)(() => {
|
|
1301
|
+
mapPoints?.initialMapPositioning({ padding: fitToPointsPadding, ...customFitToBoundsOptions(zoom) });
|
|
1302
|
+
updateFeatures();
|
|
1303
|
+
}, [mapPoints, fitToPointsPadding, updateFeatures, zoom]);
|
|
1304
|
+
(0, import_react18.useEffect)(() => {
|
|
1305
|
+
if (map && features?.length) {
|
|
1306
|
+
setMapPoints(new MapPoints({ features, map, zoom }));
|
|
1307
|
+
}
|
|
1308
|
+
}, [map, features, zoom]);
|
|
1309
|
+
(0, import_react18.useEffect)(() => {
|
|
1310
|
+
if (mapInitialized) {
|
|
1311
|
+
updateMapSetup();
|
|
1312
|
+
reInitializeMap();
|
|
1313
|
+
}
|
|
1314
|
+
}, [mapInitialized, reInitializeMap, updateMapSetup]);
|
|
1315
|
+
return /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(import_react_flexbox7.FlexCol, { alignItems: "stretch", id: "xyo-mapbox-wrap", ...props, children: features ? /* @__PURE__ */ (0, import_jsx_runtime14.jsxs)(import_jsx_runtime14.Fragment, { children: [
|
|
1316
|
+
/* @__PURE__ */ (0, import_jsx_runtime14.jsx)(MapBox, { accessToken, zoom }),
|
|
1317
|
+
/* @__PURE__ */ (0, import_jsx_runtime14.jsx)(MapSettingsBox, {})
|
|
1318
|
+
] }) : /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(import_material8.Alert, { severity: "error", children: "No data to show" }) });
|
|
1319
|
+
};
|
|
1320
|
+
|
|
1321
|
+
// src/types/NetworkLocationAnswerBase.ts
|
|
1322
|
+
var import_payload_model = require("@xyo-network/payload-model");
|
|
1323
|
+
var NetworkLocationAnswerSchema = "network.xyo.location.range.answer";
|
|
1324
|
+
var isNetworkLocationAnswer = (0, import_payload_model.isPayloadOfSchemaType)(NetworkLocationAnswerSchema);
|
|
1325
|
+
var NetworkLocationHeatmapAnswerSchema = "network.xyo.location.heatmap.answer";
|
|
1326
|
+
var isNetworkLocationHeatmapAnswer = (0, import_payload_model.isPayloadOfSchemaType)(NetworkLocationHeatmapAnswerSchema);
|
|
1327
|
+
var NetworkLocationHeatmapQuadkeyAnswerSchema = "network.xyo.location.heatmap.quadkey.answer";
|
|
1328
|
+
var isNetworkLocationHeatmapQuadkeyAnswer = (0, import_payload_model.isPayloadOfSchemaType)(
|
|
1329
|
+
NetworkLocationHeatmapQuadkeyAnswerSchema
|
|
1330
|
+
);
|
|
3
1331
|
//# sourceMappingURL=index.cjs.map
|