Skip to content

Commit 68b59ed

Browse files
Merge pull request #107 from Chia-Chi-Shen/accessible-popups
Add accessible popups sample
2 parents c2eb1af + 4c4ef5d commit 68b59ed

File tree

5 files changed

+150
-8
lines changed

5 files changed

+150
-8
lines changed

package-lock.json

Lines changed: 6 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"dependencies": {
66
"azure-maps-control": "^3.3.0",
77
"react": "^18.2.0",
8-
"react-azure-maps": "^1.0.2",
8+
"react-azure-maps": "^1.0.3",
99
"react-dom": "^18.2.0",
1010
"react-router-dom": "^6.3.0"
1111
},
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
import { Meta, Source } from '@storybook/blocks';
2+
3+
import AccessiblePopup from './AccessiblePopup';
4+
5+
<Meta title='Map Annotations/Popup/Accessible Popup' />
6+
7+
# Accessible Popup
8+
This sample shows how to use popups in a way that users can easily access them using keyboard shortcuts (tab).
9+
<fieldset style={{ width: 'fit-content'}}>Use <b>Tab</b> to navigate.</fieldset>
10+
<AccessiblePopup />
11+
<br/>
12+
<Source code={`
13+
import {
14+
AzureMap,
15+
AzureMapDataSourceProvider,
16+
AzureMapFeature,
17+
AzureMapLayerProvider,
18+
AzureMapsProvider,
19+
AzureMapPopup,
20+
} from 'react-azure-maps';
21+
import { data } from 'azure-maps-control';
22+
23+
const points = Array.from({ length: 10 }).map(() => {
24+
const randomLongitude = Math.floor(Math.random() * 60 - 30);
25+
const randomLatitude = Math.floor(Math.random() * 40 - 20);
26+
return new data.Position(randomLongitude, randomLatitude);
27+
});
28+
29+
const AccessiblePopups = () => {
30+
31+
return (
32+
<AzureMapsProvider>
33+
<div style={...}>
34+
<AzureMap options={{...yourOptions, zoom: 2}}>
35+
<AzureMapDataSourceProvider
36+
id={'MultiplePoint AzureMapDataSourceProvider'}>
37+
<AzureMapLayerProvider
38+
id={'MultiplePoint AzureMapLayerProvider'}
39+
options={{
40+
iconOptions: {
41+
image: 'pin-red',
42+
},
43+
}}
44+
type="SymbolLayer"
45+
/>
46+
{
47+
points.map(
48+
(coordinates, idx) =>
49+
<AzureMapFeature
50+
key={idx}
51+
type="Point"
52+
coordinate={coordinates}
53+
/>
54+
)
55+
}
56+
</AzureMapDataSourceProvider>
57+
<>
58+
{points.map((point, idx) =>
59+
<AzureMapPopup
60+
key={idx}
61+
isVisible={!idx}
62+
options={{
63+
position: point,
64+
pixelOffset: [0, -5],
65+
}}
66+
popupContent={
67+
<div style={{ padding: '15px' }}>{ \`Lng: \${point[0]}, Lat: \${point[1]}\` }</div>
68+
}
69+
/>
70+
)}
71+
</>
72+
</AzureMap>
73+
</div>
74+
</AzureMapsProvider>
75+
);
76+
}
77+
78+
export default AccessiblePopups;
79+
`} />
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
import {
2+
AzureMap,
3+
AzureMapDataSourceProvider,
4+
AzureMapFeature,
5+
AzureMapLayerProvider,
6+
AzureMapsProvider,
7+
AzureMapPopup,
8+
} from 'react-azure-maps';
9+
import { data } from 'azure-maps-control';
10+
import { mapOptions } from '../../../../key';
11+
12+
const points = Array.from({ length: 10 }).map(() => {
13+
const randomLongitude = Math.floor(Math.random() * 60 - 30);
14+
const randomLatitude = Math.floor(Math.random() * 40 - 20);
15+
return new data.Position(randomLongitude, randomLatitude);
16+
});
17+
18+
const AccessiblePopups = () => {
19+
20+
return (
21+
<AzureMapsProvider>
22+
<div className='defaultMap sb-unstyled'>
23+
<AzureMap options={{...mapOptions, zoom: 2}}>
24+
<AzureMapDataSourceProvider
25+
id={'MultiplePoint AzureMapDataSourceProvider'}>
26+
<AzureMapLayerProvider
27+
id={'MultiplePoint AzureMapLayerProvider'}
28+
options={{
29+
iconOptions: {
30+
image: 'pin-red',
31+
},
32+
}}
33+
type="SymbolLayer"
34+
/>
35+
{
36+
points.map(
37+
(coordinates, idx) =>
38+
<AzureMapFeature key={idx} type="Point" coordinate={coordinates}/>
39+
)
40+
}
41+
</AzureMapDataSourceProvider>
42+
<>
43+
{points.map((point, idx) =>
44+
<AzureMapPopup
45+
key={idx}
46+
isVisible={!idx}
47+
options={{
48+
position: point,
49+
pixelOffset: [0, -5],
50+
}}
51+
popupContent={
52+
<div style={{ padding: '15px' }}>{ `Lng: ${point[0]}, Lat: ${point[1]}` }</div>
53+
}
54+
/>
55+
)}
56+
</>
57+
</AzureMap>
58+
</div>
59+
</AzureMapsProvider>
60+
);
61+
}
62+
63+
export default AccessiblePopups;

src/stories/MapAnnotations/Popup/Interactive/InteractivePopup.stories.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import type { Meta, StoryObj } from '@storybook/react';
22
import InteractivePopup from './InteractivePopupExample';
33

44
const meta: Meta<typeof InteractivePopup> = {
5-
title: 'Map Annotations/Interactive Popup',
5+
title: 'Map Annotations/Popup/Interactive Popup',
66
component: InteractivePopup,
77
args: {
88
isVisible: true,

0 commit comments

Comments
 (0)