react-azure-maps
Advanced tools
Comparing version
@@ -1,1 +0,1 @@ | ||
import e,{createContext as t,useState as r,useContext as o,useEffect as n,memo as a,useRef as s}from"react";import i from"azure-maps-control";export{AuthenticationType}from"azure-maps-control";import{Guid as c}from"guid-typescript";import{renderToStaticMarkup as l}from"react-dom/server";const u=t({mapRef:null,isMapReady:!1,setMapRef:e=>{},removeMapRef:()=>{},setMapReady:()=>{}}),{Provider:p,Consumer:d}=u,m=({children:t})=>{const[o,n]=r(null),[a,s]=r(!1);return e.createElement(p,{value:{mapRef:o,setMapRef:n,isMapReady:a,setMapReady:s,removeMapRef:()=>n(null)}},t)},y=()=>o(u);function f(e,t,r){n((()=>{if(e&&t)return r(e,t)}),[t])}function v(e,t,r){n((()=>{if(e&&t)return r(e,t)}),[])}const g=(e,t)=>{switch(e){case"CompassControl":return new i.control.CompassControl(t);case"PitchControl":return new i.control.PitchControl(t);case"StyleControl":return new i.control.StyleControl(t);case"ZoomControl":return new i.control.ZoomControl(t);case"TrafficControl":return new i.control.TrafficControl(t);case"TrafficLegendControl":return new i.control.TrafficLegendControl;default:console.warn("Check the type and passed props properties or try CustomControl")}},C=a((({children:t,LoaderComponent:a=()=>e.createElement("div",null,"Loading ..."),providedMapId:l,containerClassName:p,styles:d,options:m={},imageSprites:y,controls:v,customControls:C,events:S,cameraOptions:w,trafficOptions:h,userInteraction:L,styleOptions:M,serviceOptions:P})=>{const{setMapRef:R,removeMapRef:I,mapRef:E,setMapReady:b,isMapReady:O}=o(u),[T]=r(l||c.create().toString()),z=s(null);return n((()=>{E&&E.setTraffic(h)}),[h]),n((()=>{E&&E.setUserInteraction(L)}),[L]),n((()=>{E&&E.setCamera(w)}),[w]),n((()=>{E&&E.setStyle(M)}),[M]),n((()=>{E&&P&&E.setServiceOptions(P)}),[P]),f(E,E,(e=>{e.events.add("ready",(()=>{y&&(async(e,t)=>{await Promise.all(t.map((async({id:t,templateName:r,color:o,secondaryColor:n,scale:a,icon:s})=>(s&&await e.imageSprite.add(t,s),e.imageSprite.createFromTemplate(t,r||"marker",o,n,a)))))})(e,y),v&&((e,t)=>{t.forEach((t=>{const{controlName:r,options:o,controlOptions:n}=t;e.controls.add(g(r,n),o)}))})(e,v),C&&((e,t)=>{t.forEach((({control:t,controlOptions:r})=>{e.controls.add(t,r)}))})(e,C),h&&e.setTraffic(h),L&&e.setUserInteraction(L),w&&e.setCamera(w),M&&e.setStyle(M),P&&e.setServiceOptions(P),b(!0)}));for(const t in S)e.events.add(t,S[t])})),n((()=>(null===z.current&&(z.current=new i.Map(T,{...m||{},sessionId:(null==m?void 0:m.sessionId)||`react-azure-maps:${c.create().toString()}`})),R(z.current),()=>{I()})),[]),e.createElement(e.Fragment,null,!O&&a&&e.createElement(a,null),e.createElement("div",{className:p,id:T,style:{...d,height:"100%"}},O&&t))})),S=a((({markerContent:e,options:t,events:a,isPopupVisible:s})=>{const[c]=r(new i.HtmlMarker({...t,htmlContent:e&&l(e)})),{mapRef:p}=o(u);return v(p,!0,(e=>(e.markers.add(c),a&&a.forEach((({eventName:t,callback:r})=>{e.events.add(t,c,r)})),()=>{e.markers.remove(c)}))),n((()=>{c&&p&&c.setOptions({...t,htmlContent:e&&l(e)})}),[e,t]),n((()=>{if(c&&c.getOptions().popup&&p){const e=c.getOptions().popup;s?(null==e||e.setOptions({position:c.getOptions().position}),null==e||e.open(p)):null==e||e.close()}}),[s,t,p]),null})),w=e=>new i.data.LineString(e),h=(e,t)=>i.Pixel.getHeading(e,t),L=(e,t)=>e.layers.getLayers().filter((e=>{if(e.getSource){const r=e.getSource();return("string"==typeof r?r:r.getId())===t.getId()}return!1})),M=t({dataSourceRef:null}),{Provider:P,Consumer:R}=M,I=({id:t,children:a,options:s,events:c,dataFromUrl:l,collection:p})=>{const[d]=r(new i.source.DataSource(t,s)),{mapRef:m}=o(u);return f(m,d,((e,t)=>{for(const r in c||{})e.events.add(r,t,c[r]);return e.sources.add(t),t instanceof i.source.DataSource&&(l&&t.importDataFromUrl(l),p&&t.add(p)),()=>{for(const r in c||{})e.events.remove(r,t,c[r]);L(e,t).forEach((t=>{e.layers.remove(t.getId()?t.getId():t)})),e.sources.remove(t)}})),n((()=>{d&&p&&(d.clear(),d.add(p))}),[p]),n((()=>{d&&s&&d.setOptions(s)}),[s]),e.createElement(P,{value:{dataSourceRef:d}},m&&a)},E=a((t=>{const{properties:r,id:a,variant:s="feature"}=t,{dataSourceRef:c}=o(M),[l,u]=e.useState(null),[p,d]=e.useState(null);return(({setCoords:e,setProperties:t},r,o,a)=>{f(r,a,((e,t)=>{if(e instanceof i.source.DataSource)return e.add(t),()=>{e.remove(t)};r instanceof i.source.VectorTileSource&&console.error(`Unable to add Feature(${t.id}) to VectorTileSource(${r.getId()}): AzureMapFeature has to be a child of AzureMapDataSourceProvider`)})),f(r,o,((e,t)=>{if(e instanceof i.source.DataSource)return e.add(t),()=>{e.remove(t)};r instanceof i.source.VectorTileSource&&console.error(`Unable to add Shape(${t.getId()}) to VectorTileSource(${r.getId()}): AzureMapFeature has to be a child of AzureMapDataSourceProvider`)})),n((()=>{o&&e&&o.setCoordinates(e)}),[e]),n((()=>{o&&t&&o.setProperties(t)}),[t])})(t,c,p,l),n((()=>{const e=(({type:e,coordinate:t,coordinates:r,multipleCoordinates:o,multipleDimensionCoordinates:n,bbox:a})=>{switch(e){case"Point":return t&&new i.data.Point(t);case"MultiPoint":return r&&new i.data.MultiPoint(r,a);case"LineString":return r&&new i.data.LineString(r,a);case"MultiLineString":return o&&new i.data.MultiLineString(o,a);case"Polygon":return r&&new i.data.Polygon(r,a);case"MultiPolygon":return n&&new i.data.MultiPolygon(n,a);default:console.warn("Check the type and passed props properties")}})(t);if((!l||!p)&&e)switch(s){case"shape":d(new i.Shape(e,a,r));break;case"feature":u(new i.data.Feature(e,r,a))}}),[]),null})),b=({id:t,children:n,options:a,events:s={}})=>{const[c]=r(new i.source.VectorTileSource(t,a)),{mapRef:l}=o(u);return f(l,c,((e,t)=>{for(const r in s){const o=s[r];o&&e.events.add(r,t,o)}return e.sources.add(t),()=>{for(const r in s||{}){const o=s[r];o&&e.events.remove(r,t,o)}L(e,t).forEach((t=>{e.layers.remove(t.getId()?t.getId():t)})),e.sources.remove(t)}})),e.createElement(P,{value:{dataSourceRef:c}},l&&n)},O=({id:e,options:t,type:a,events:s,lifecycleEvents:c,onCreateCustomLayer:l})=>{const{mapRef:p}=o(u),{dataSourceRef:d}=o(M),[m,y]=r(null);return f(!m,d,((...[,r])=>{let o=null;o="custom"===a?l&&l(r,p):(({id:e,options:t={},type:r},o)=>{switch(r){case"SymbolLayer":return new i.layer.SymbolLayer(o,e,t);case"HeatLayer":return new i.layer.HeatMapLayer(o,e,t);case"ImageLayer":return new i.layer.ImageLayer(t,e);case"LineLayer":return new i.layer.LineLayer(o,e,t);case"PolygonExtrusionLayer":return new i.layer.PolygonExtrusionLayer(o,e,t);case"PolygonLayer":return new i.layer.PolygonLayer(o,e,t);case"TileLayer":return new i.layer.TileLayer(t,e);case"BubbleLayer":return new i.layer.BubbleLayer(o,e,t);default:return null}})({id:e,options:t,type:a},r),y(o)})),f(p,m,((e,t)=>{for(const r in s)e.events.add(r,t,s[r]);for(const r in c)e.events.add(r,t,c[r]);return e.layers.add(t),()=>{try{e.layers.getLayerById(t.getId())&&e.layers.remove(t.getId()?t.getId():t)}catch(e){console.error("Error on remove layer",e)}}})),n((()=>{m&&t&&m.setOptions(t)}),[t]),{layerRef:m}},T=t({layerRef:null}),{Provider:z,Consumer:k}=T,V=({id:t,options:r,type:o,events:n,lifecycleEvents:a,onCreateCustomLayer:s})=>{const{layerRef:i}=O({id:t,options:r,type:o,events:n,lifecycleEvents:a,onCreateCustomLayer:s});return e.createElement(z,{value:{layerRef:i}})},A=({options:e,popupContent:t,isVisible:a})=>{const[s]=r(new i.Popup({...e,content:l(t)})),{mapRef:c}=o(u);return n((()=>{s.setOptions({...e,content:l(t)}),c&&a&&!s.isOpen()&&s.open(c)}),[e,t]),s},D=a((({isVisible:e,popupContent:t,options:r,events:a})=>{const{mapRef:s}=o(u),i=A({options:r,popupContent:t,isVisible:e});return v(s,!0,(e=>(a&&a.forEach((({eventName:t,callback:r})=>{e.events.add(t,i,r)})),()=>{e.popups.remove(i)}))),n((()=>{s&&(e&&!i.isOpen()?i.open(s):s.popups.getPopups().length&&!e&&i.isOpen()&&i.close())}),[e]),null}));export{C as AzureMap,R as AzureMapDataSourceConsumer,M as AzureMapDataSourceContext,I as AzureMapDataSourceProvider,E as AzureMapFeature,S as AzureMapHtmlMarker,k as AzureMapLayerConsumer,T as AzureMapLayerContext,V as AzureMapLayerProvider,D as AzureMapPopup,b as AzureMapVectorTileSourceProvider,d as AzureMapsConsumer,u as AzureMapsContext,m as AzureMapsProvider,w as generateLinesFromArrayOfPosition,h as generatePixelHeading,y as useAzureMaps,A as useCreatePopup}; | ||
import e,{createContext as t,useState as r,useContext as o,useEffect as n,memo as a,useRef as s}from"react";import l from"azure-maps-control";export{AuthenticationType}from"azure-maps-control";import{Guid as c}from"guid-typescript";import{renderToStaticMarkup as i}from"react-dom/server";const u=t({mapRef:null,isMapReady:!1,setMapRef:e=>{},removeMapRef:()=>{},setMapReady:()=>{}}),{Provider:p,Consumer:d}=u,m=({children:t})=>{const[o,n]=r(null),[a,s]=r(!1);return e.createElement(p,{value:{mapRef:o,setMapRef:n,isMapReady:a,setMapReady:s,removeMapRef:()=>n(null)}},t)},y=()=>o(u);function f(e,t,r){n((()=>{if(e&&t)return r(e,t)}),[t])}function v(e,t,r){n((()=>{if(e&&t)return r(e,t)}),[])}const g=(e,t)=>{switch(e){case"CompassControl":return new l.control.CompassControl(t);case"PitchControl":return new l.control.PitchControl(t);case"StyleControl":return new l.control.StyleControl(t);case"ZoomControl":return new l.control.ZoomControl(t);case"TrafficControl":return new l.control.TrafficControl(t);case"TrafficLegendControl":return new l.control.TrafficLegendControl;case"ScaleControl":return new l.control.ScaleControl(t);case"FullscreenControl":return new l.control.FullscreenControl(t);default:console.warn("Check the type and passed props properties or try CustomControl")}},C=a((({children:t,LoaderComponent:a=()=>e.createElement("div",null,"Loading ..."),providedMapId:i,containerClassName:p,styles:d,options:m={},imageSprites:y,controls:v,customControls:C,events:S,cameraOptions:w,trafficOptions:h,userInteraction:L,styleOptions:M,serviceOptions:P})=>{const{setMapRef:R,removeMapRef:I,mapRef:E,setMapReady:b,isMapReady:O}=o(u),[T]=r(i||c.create().toString()),z=s(null);return n((()=>{E&&E.setTraffic(h)}),[h]),n((()=>{E&&E.setUserInteraction(L)}),[L]),n((()=>{E&&E.setCamera(w)}),[w]),n((()=>{E&&E.setStyle(M)}),[M]),n((()=>{E&&P&&E.setServiceOptions(P)}),[P]),f(E,E,(e=>{e.events.add("ready",(()=>{y&&(async(e,t)=>{await Promise.all(t.map((async({id:t,templateName:r,color:o,secondaryColor:n,scale:a,icon:s})=>(s&&await e.imageSprite.add(t,s),e.imageSprite.createFromTemplate(t,r||"marker",o,n,a)))))})(e,y),v&&((e,t)=>{t.forEach((t=>{const{controlName:r,options:o,controlOptions:n}=t;e.controls.add(g(r,n),o)}))})(e,v),C&&((e,t)=>{t.forEach((({control:t,controlOptions:r})=>{e.controls.add(t,r)}))})(e,C),h&&e.setTraffic(h),L&&e.setUserInteraction(L),w&&e.setCamera(w),M&&e.setStyle(M),P&&e.setServiceOptions(P),b(!0)}));for(const t in S)e.events.add(t,S[t])})),n((()=>(null===z.current&&(z.current=new l.Map(T,{...m||{},sessionId:(null==m?void 0:m.sessionId)||`react-azure-maps:${c.create().toString()}`})),R(z.current),()=>{I()})),[]),e.createElement(e.Fragment,null,!O&&a&&e.createElement(a,null),e.createElement("div",{className:p,id:T,style:{...d,height:"100%"}},O&&t))})),S=a((({markerContent:e,options:t,events:a,isPopupVisible:s})=>{const[c]=r(new l.HtmlMarker({...t,htmlContent:e&&i(e)})),{mapRef:p}=o(u);return v(p,!0,(e=>(e.markers.add(c),a&&a.forEach((({eventName:t,callback:r})=>{e.events.add(t,c,r)})),()=>{e.markers.remove(c)}))),n((()=>{c&&p&&c.setOptions({...t,htmlContent:e&&i(e)})}),[e,t]),n((()=>{if(c&&c.getOptions().popup&&p){const e=c.getOptions().popup;s?(null==e||e.setOptions({position:c.getOptions().position}),null==e||e.open(p)):null==e||e.close()}}),[s,t,p]),null})),w=e=>new l.data.LineString(e),h=(e,t)=>l.Pixel.getHeading(e,t),L=(e,t)=>e.layers.getLayers().filter((e=>{if(e.getSource){const r=e.getSource();return("string"==typeof r?r:r.getId())===t.getId()}return!1})),M=t({dataSourceRef:null}),{Provider:P,Consumer:R}=M,I=({id:t,children:a,options:s,events:c,dataFromUrl:i,collection:p})=>{const[d]=r(new l.source.DataSource(t,s)),{mapRef:m}=o(u);return f(m,d,((e,t)=>{for(const r in c||{})e.events.add(r,t,c[r]);return e.sources.add(t),t instanceof l.source.DataSource&&(i&&t.importDataFromUrl(i),p&&t.add(p)),()=>{for(const r in c||{})e.events.remove(r,t,c[r]);L(e,t).forEach((t=>{e.layers.remove(t.getId()?t.getId():t)})),e.sources.remove(t)}})),n((()=>{d&&p&&(d.clear(),d.add(p))}),[p]),n((()=>{d&&s&&d.setOptions(s)}),[s]),e.createElement(P,{value:{dataSourceRef:d}},m&&a)},E=a((t=>{const{properties:r,id:a,variant:s="feature"}=t,{dataSourceRef:c}=o(M),[i,u]=e.useState(null),[p,d]=e.useState(null);return(({setCoords:e,setProperties:t},r,o,a)=>{f(r,a,((e,t)=>{if(e instanceof l.source.DataSource)return e.add(t),()=>{e.remove(t)};r instanceof l.source.VectorTileSource&&console.error(`Unable to add Feature(${t.id}) to VectorTileSource(${r.getId()}): AzureMapFeature has to be a child of AzureMapDataSourceProvider`)})),f(r,o,((e,t)=>{if(e instanceof l.source.DataSource)return e.add(t),()=>{e.remove(t)};r instanceof l.source.VectorTileSource&&console.error(`Unable to add Shape(${t.getId()}) to VectorTileSource(${r.getId()}): AzureMapFeature has to be a child of AzureMapDataSourceProvider`)})),n((()=>{o&&e&&o.setCoordinates(e)}),[e]),n((()=>{o&&t&&o.setProperties(t)}),[t])})(t,c,p,i),n((()=>{const e=(({type:e,coordinate:t,coordinates:r,multipleCoordinates:o,multipleDimensionCoordinates:n,bbox:a})=>{switch(e){case"Point":return t&&new l.data.Point(t);case"MultiPoint":return r&&new l.data.MultiPoint(r,a);case"LineString":return r&&new l.data.LineString(r,a);case"MultiLineString":return o&&new l.data.MultiLineString(o,a);case"Polygon":return r&&new l.data.Polygon(r,a);case"MultiPolygon":return n&&new l.data.MultiPolygon(n,a);default:console.warn("Check the type and passed props properties")}})(t);if((!i||!p)&&e)switch(s){case"shape":d(new l.Shape(e,a,r));break;case"feature":u(new l.data.Feature(e,r,a))}}),[]),null})),b=({id:t,children:n,options:a,events:s={}})=>{const[c]=r(new l.source.VectorTileSource(t,a)),{mapRef:i}=o(u);return f(i,c,((e,t)=>{for(const r in s){const o=s[r];o&&e.events.add(r,t,o)}return e.sources.add(t),()=>{for(const r in s||{}){const o=s[r];o&&e.events.remove(r,t,o)}L(e,t).forEach((t=>{e.layers.remove(t.getId()?t.getId():t)})),e.sources.remove(t)}})),e.createElement(P,{value:{dataSourceRef:c}},i&&n)},O=({id:e,options:t,type:a,events:s,lifecycleEvents:c,onCreateCustomLayer:i})=>{const{mapRef:p}=o(u),{dataSourceRef:d}=o(M),[m,y]=r(null);return f(!m,d,((...[,r])=>{let o=null;o="custom"===a?i&&i(r,p):(({id:e,options:t={},type:r},o)=>{switch(r){case"SymbolLayer":return new l.layer.SymbolLayer(o,e,t);case"HeatLayer":return new l.layer.HeatMapLayer(o,e,t);case"ImageLayer":return new l.layer.ImageLayer(t,e);case"LineLayer":return new l.layer.LineLayer(o,e,t);case"PolygonExtrusionLayer":return new l.layer.PolygonExtrusionLayer(o,e,t);case"PolygonLayer":return new l.layer.PolygonLayer(o,e,t);case"TileLayer":return new l.layer.TileLayer(t,e);case"BubbleLayer":return new l.layer.BubbleLayer(o,e,t);default:return null}})({id:e,options:t,type:a},r),y(o)})),f(p,m,((e,t)=>{for(const r in s)e.events.add(r,t,s[r]);for(const r in c)e.events.add(r,t,c[r]);return e.layers.add(t),()=>{try{e.layers.getLayerById(t.getId())&&e.layers.remove(t.getId()?t.getId():t)}catch(e){console.error("Error on remove layer",e)}}})),n((()=>{m&&t&&m.setOptions(t)}),[t]),{layerRef:m}},T=t({layerRef:null}),{Provider:z,Consumer:k}=T,F=({id:t,options:r,type:o,events:n,lifecycleEvents:a,onCreateCustomLayer:s})=>{const{layerRef:l}=O({id:t,options:r,type:o,events:n,lifecycleEvents:a,onCreateCustomLayer:s});return e.createElement(z,{value:{layerRef:l}})},V=({options:e,popupContent:t,isVisible:a})=>{const[s]=r(new l.Popup({...e,content:i(t)})),{mapRef:c}=o(u);return n((()=>{s.setOptions({...e,content:i(t)}),c&&a&&!s.isOpen()&&s.open(c)}),[e,t]),s},A=a((({isVisible:e,popupContent:t,options:r,events:a})=>{const{mapRef:s}=o(u),l=V({options:r,popupContent:t,isVisible:e});return v(s,!0,(e=>(a&&a.forEach((({eventName:t,callback:r})=>{e.events.add(t,l,r)})),()=>{e.popups.remove(l)}))),n((()=>{s&&(e&&!l.isOpen()?l.open(s):s.popups.getPopups().length&&!e&&l.isOpen()&&l.close())}),[e]),null}));export{C as AzureMap,R as AzureMapDataSourceConsumer,M as AzureMapDataSourceContext,I as AzureMapDataSourceProvider,E as AzureMapFeature,S as AzureMapHtmlMarker,k as AzureMapLayerConsumer,T as AzureMapLayerContext,F as AzureMapLayerProvider,A as AzureMapPopup,b as AzureMapVectorTileSourceProvider,d as AzureMapsConsumer,u as AzureMapsContext,m as AzureMapsProvider,w as generateLinesFromArrayOfPosition,h as generatePixelHeading,y as useAzureMaps,V as useCreatePopup}; |
{ | ||
"name": "react-azure-maps", | ||
"version": "1.0.1", | ||
"version": "1.0.2", | ||
"description": "React Wrapper for Azure Maps", | ||
@@ -97,3 +97,3 @@ "keywords": [ | ||
"@types/react-dom": "^18.0.6", | ||
"azure-maps-control": "^3.0.3", | ||
"azure-maps-control": "^3.5.0", | ||
"babel-preset-env": "^1.7.0", | ||
@@ -124,3 +124,3 @@ "concurrently": "^5.3.0", | ||
"peerDependencies": { | ||
"azure-maps-control": "^3.0.1", | ||
"azure-maps-control": "^3.5.0", | ||
"react": "^17.0.2 || ^18.0.0", | ||
@@ -127,0 +127,0 @@ "react-dom": "^17.0.2 || ^18.0.0" |
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
37155
0.33%0
-100%