import atlas from 'azure-maps-control' ; import React , { useContext , useState } from 'react' ; import { useCheckRef } from '../hooks/useCheckRef' ; import { DataSourceType , IAzureMapsContextProps , IAzureMapSourceEventType , IAzureVectorTileSourceStatefulProviderProps , MapType } from '../types' ; import { AzureMapDataSourceRawProvider as Provider } from './AzureMapDataSourceContext' ; import { AzureMapsContext } from './AzureMapContext' ; param id param children param options param events const AzureMapVectorTileSourceStatefulProvider = ( { id , children , options , events = { } , } ) => { const [ dataSourceRef ] = useState < atlas . source . VectorTileSource > ( new atlas . source . VectorTileSource ( id , options ) ) ; const { mapRef } = useContext < IAzureMapsContextProps > ( AzureMapsContext ) ; useCheckRef < MapType , DataSourceType > ( mapRef , dataSourceRef , ( mref , dref ) => { for ( const eventType in events ) { const handler = events [ eventType as IAzureMapSourceEventType ] as ( e : atlas . source . Source ) => void | undefined ; if ( handler ) { mref . events . add ( eventType as IAzureMapSourceEventType , dref , handler ) ; } } mref . sources . add ( dref ) ; } ) ; return ( < Provider value = { { dataSourceRef , } } > { mapRef && children } < /Provider>); } ; export { AzureMapVectorTileSourceStatefulProvider as AzureMapVectorTileSourceProvider } ;