@@ -15,48 +15,33 @@ type Props = {
1515 url ?: string
1616} ;
1717
18- const GeoJsonLayer = ( props : Props ) => {
19- const [ data , setData ] = useState ( props . data ) ;
20-
21- /**
22- * If the data is passed as a URL, fetches the passed URL and sets the response on the state.
23- */
24- useEffect ( ( ) => {
25- if ( props . url ) {
26- fetch ( props . url )
27- . then ( ( response ) => response . json ( ) )
28- . then ( ( json ) => setData ( json ) ) ;
29- }
30- } , [ props . url ] ) ;
31-
32- return (
33- < Source
34- data = { data }
35- type = 'geojson'
36- >
37- < Layer
38- filter = { [ '!=' , '$type' , 'Point' ] }
39- paint = { props . fillStyle }
40- type = 'fill'
41- />
42- < Layer
43- filter = { [ '!=' , '$type' , 'Point' ] }
44- paint = { props . lineStyle }
45- type = 'line'
46- />
47- < Layer
48- filter = { [ '==' , '$type' , 'Point' ] }
49- paint = { props . pointStyle }
50- type = 'circle'
51- />
52- </ Source >
53- ) ;
54- } ;
18+ const GeoJsonLayer = ( props : Props ) => (
19+ < Source
20+ data = { props . data || props . url }
21+ type = 'geojson'
22+ >
23+ < Layer
24+ filter = { [ '!=' , '$type' , 'Point' ] }
25+ paint = { props . fillStyle }
26+ type = 'fill'
27+ />
28+ < Layer
29+ filter = { [ '!=' , '$type' , 'Point' ] }
30+ paint = { props . lineStyle }
31+ type = 'line'
32+ />
33+ < Layer
34+ filter = { [ '==' , '$type' , 'Point' ] }
35+ paint = { props . pointStyle }
36+ type = 'circle'
37+ />
38+ </ Source >
39+ ) ;
5540
5641GeoJsonLayer . defaultProps = {
57- fillStyle : MapStyles . fill ,
58- pointStyle : MapStyles . point ,
59- strokeStyle : MapStyles . stroke
42+ fillStyle : MapStyles . fill . paint ,
43+ pointStyle : MapStyles . point . paint ,
44+ strokeStyle : MapStyles . stroke . paint
6045} ;
6146
6247export default GeoJsonLayer ;
0 commit comments