-
Notifications
You must be signed in to change notification settings - Fork 24
/
Copy pathDrawingTool.tsx
85 lines (81 loc) · 2.54 KB
/
DrawingTool.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
import React, { useState } from 'react';
import {
AzureMap,
AzureMapDataSourceProvider,
AzureMapDrawingManagerProvider,
AzureMapFeature,
AzureMapLayerProvider,
AzureMapsProvider,
IAzureMapOptions,
} from 'react-azure-maps';
import { AuthenticationType } from 'azure-maps-control';
import { key } from '../../key';
import { control, drawing } from 'azure-maps-drawing-tools';
import Description from '../../Layout/Description';
import { Button } from '@material-ui/core';
import { wrapperStyles } from '../Options/ChangeOptionsWrapper';
const option: IAzureMapOptions = {
authOptions: {
authType: AuthenticationType.subscriptionKey,
subscriptionKey: key,
},
};
const drawingOptions = {
toolbar: new control.DrawingToolbar({
position: 'top-right',
style: 'dark',
}),
};
const mode = {
mode: drawing.DrawingMode.drawPolygon,
};
const DrawingTool: React.FC = () => {
const [options, setOptions] = useState<any>(drawingOptions);
return (
<div>
<Description>Change options in child</Description>
<div style={wrapperStyles.buttonContainer}>
<Button size="small" variant="contained" color="secondary" onClick={() => setOptions(mode)}>
Change Bounds
</Button>
</div>
<AzureMapsProvider>
<div style={{ height: '300px' }}>
<AzureMap options={option}>
<AzureMapDrawingManagerProvider options={options}>
<AzureMapDataSourceProvider
events={{
dataadded: (e: any) => {
console.log('Data on source added', e);
},
}}
id={'DrawingTool AzureMapDataSourceProvider'}
options={{}}
>
<AzureMapLayerProvider id={'DrawingTool AzureMapLayerProvider'} options={{}} type={'PolygonLayer'} />
<AzureMapFeature
id={'DrawingTool MapFeature'}
type="Polygon"
coordinates={[
[-50, -20],
[0, 40],
[50, -20],
[-50, -20],
]}
/>
</AzureMapDataSourceProvider>
</AzureMapDrawingManagerProvider>
</AzureMap>
</div>
</AzureMapsProvider>
<AzureMapsProvider>
<div style={{ height: '300px' }}>
<AzureMap options={option}>
<AzureMapDrawingManagerProvider options={options} />
</AzureMap>
</div>
</AzureMapsProvider>
</div>
);
};
export default DrawingTool;