Skip to content

Commit

Permalink
feat: add MapContext.Provider
Browse files Browse the repository at this point in the history
  • Loading branch information
wangxingkang committed Aug 30, 2022
1 parent 2f2c46c commit a155293
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions src/map/map.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,20 @@ import { useEffect, useRef, useState } from 'react';
import { useBoolean } from '@pansy/react-hooks';
import { getTargetElement } from '@pansy/shared/react';
import MapboxWorker from 'mapbox-gl/dist/mapbox-gl-csp-worker';

import { MapContext } from '@/context';

import { allProps, setterMap, converterMap } from './config';

import 'mapbox-gl/dist/mapbox-gl.css';

import type { FC } from 'react';
import type { MapboxOptions } from 'mapbox-gl';
import type { MapProps } from './types';

// @ts-ignore
Mapbox.workerClass = MapboxWorker;

import { FC } from 'react';

export const Map: FC<MapProps> = (props) => {
const containerRef = useRef<HTMLDivElement>(null);
const [ready, readyAction] = useBoolean(false);
Expand Down Expand Up @@ -69,9 +71,11 @@ export const Map: FC<MapProps> = (props) => {
};

return (
<div ref={containerRef} style={{ height: '100%', width: '100%' }}>
{ready && props.children}
</div>
<MapContext.Provider value={map}>
<div ref={containerRef} style={{ height: '100%', width: '100%' }}>
{ready && props.children}
</div>
</MapContext.Provider>
);
};

Expand Down

0 comments on commit a155293

Please sign in to comment.