-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
62a26e3
commit 9f825eb
Showing
6 changed files
with
130 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import React, { useEffect } from 'react'; | ||
import { useMap } from '../../hooks/useMap'; | ||
|
||
import type { Code, WorldViewProps } from './types'; | ||
|
||
export const WorldView: React.FC<WorldViewProps> = (props) => { | ||
const { code = 'CN' } = props; | ||
const { map } = useMap(); | ||
|
||
useEffect(() => { | ||
if (code) { | ||
filterLayers(code); | ||
} | ||
}, [code]); | ||
|
||
const filterLayers = (worldview: Code) => { | ||
console.log(worldview); | ||
map.setFilter('admin-0-boundary-disputed', [ | ||
'all', | ||
['==', ['get', 'disputed'], 'true'], | ||
['==', ['get', 'admin_level'], 0], | ||
['==', ['get', 'maritime'], 'false'], | ||
['match', ['get', 'worldview'], ['all', worldview], true, false], | ||
]); | ||
|
||
map.setFilter('admin-0-boundary', [ | ||
'all', | ||
['==', ['get', 'admin_level'], 0], | ||
['==', ['get', 'disputed'], 'false'], | ||
['==', ['get', 'maritime'], 'false'], | ||
['match', ['get', 'worldview'], ['all', worldview], true, false], | ||
]); | ||
|
||
map.setFilter('admin-0-boundary-bg', [ | ||
'all', | ||
['==', ['get', 'admin_level'], 0], | ||
['==', ['get', 'maritime'], 'false'], | ||
['match', ['get', 'worldview'], ['all', worldview], true, false], | ||
]); | ||
}; | ||
|
||
return null; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export { WorldView } from './WorldView'; | ||
export type { WorldViewProps, Code } from './types'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
export type Code = 'CN' | 'IN' | 'JP' | 'US'; | ||
|
||
export interface WorldViewProps { | ||
code?: Code; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
import React, { useState } from 'react'; | ||
import { Radio } from 'antd'; | ||
import { Map, StyleLoadFinish, WorldView as WorldViewCom } from '../../src'; | ||
import { Language } from './components/Language'; | ||
import { Flyto } from './components/Flyto'; | ||
|
||
import type { Meta, StoryObj } from '@storybook/react'; | ||
|
||
const worldViews = [ | ||
{ | ||
value: 'CN', | ||
label: '中国', | ||
}, | ||
{ | ||
value: 'IN', | ||
label: '印度', | ||
}, | ||
{ | ||
value: 'JP', | ||
label: '日本', | ||
}, | ||
{ | ||
value: 'US', | ||
label: '美国', | ||
}, | ||
]; | ||
|
||
const meta = { | ||
title: '示例/WorldView', | ||
render: () => { | ||
const [worldView, setWorldView] = useState(worldViews[0].value); | ||
|
||
return ( | ||
<Map | ||
containerStyle={{ height: '100vh' }} | ||
zoom={1} | ||
style="mapbox://styles/mapbox/light-v11" | ||
onClick={(e) => { | ||
console.log(e); | ||
}} | ||
> | ||
<StyleLoadFinish> | ||
<Flyto center={[85.14477595859074, 29.68859973130745]} zoom={4} /> | ||
<WorldViewCom code={worldView as any} /> | ||
</StyleLoadFinish> | ||
<Language /> | ||
|
||
<div style={{ position: 'absolute', background: '#efefef', right: 0, padding: 12 }}> | ||
<Radio.Group | ||
value={worldView} | ||
options={worldViews} | ||
onChange={(e) => { | ||
setWorldView(e.target.value); | ||
}} | ||
/> | ||
</div> | ||
</Map> | ||
); | ||
}, | ||
parameters: {}, | ||
argTypes: {}, | ||
args: {}, | ||
} satisfies Meta<typeof Map>; | ||
|
||
export default meta; | ||
type Story = StoryObj<typeof meta>; | ||
|
||
export const WorldView: Story = { | ||
args: {}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters