forked from Esri/arcgis-js-vscode-snippets
-
Notifications
You must be signed in to change notification settings - Fork 0
/
typescriptreact.json
157 lines (156 loc) · 4.11 KB
/
typescriptreact.json
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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
{
"Widget Starter": {
"prefix": "widgetStarter",
"body": [
"",
"import {subclass, property} from \"esri/core/accessorSupport/decorators\";",
"",
"import Widget from\"esri/widgets/Widget\";",
"",
"import { tsx } from \"esri/widgets/support/widget\";",
"",
"const CSS = {",
" base: \"esri-${1:hello-world}\"",
"};",
"",
"@subclass(\"esri.widgets.${2:HelloWorld}\")",
"class ${2:HelloWorld} extends (Widget) {",
"",
" //--------------------------------------------------------------------------",
" //",
" // Properties",
" //",
" //--------------------------------------------------------------------------",
"",
"",
" //--------------------------------------------------------------------------",
" //",
" // Public Methods",
" //",
" //--------------------------------------------------------------------------",
"",
"",
" render() {",
" ",
" return (",
" <div class={CSS.base}>",
" ",
" </div>",
" );",
" }",
"",
" //--------------------------------------------------------------------------",
" //",
" // Private Methods",
" //",
" //--------------------------------------------------------------------------",
"",
"}",
"",
"export = ${2:HelloWorld};"
],
"description": "Widget Starter"
},
"Property": {
"prefix": "property",
"body": [
"@property()",
"view: ${1:propertyName};"
],
"description": "Property"
},
"Constructor": {
"prefix": "Constructor",
"body": [
" constructor(params) {",
" super(params);",
" }",
""
],
"description": "Constructor"
},
"ReactViewComponent": {
"prefix": "reactmap",
"body": [
"import React, { Component, createRef } from \"react\";",
"",
"import MapView from \"@arcgis/core/views/MapView\";",
"import SceneView from \"@arcgis/core/views/SceneView\";",
"",
"import \"./View.scss\";",
"",
"interface ViewProps {",
" map: __esri.WebMap | __esri.WebScene;",
"}",
"",
"const CSS = {",
" base: \"esri-view\"",
"};",
"",
"const WEB_MAP = \"Web Map\";",
"const WEB_SCENE = \"Web Scene\";",
"",
"class View extends Component<ViewProps, null> {",
" container = createRef() as React.RefObject<HTMLDivElement>;",
" view: __esri.MapView | __esri.SceneView = null;",
"",
" constructor(props: ViewProps) {",
" super(props);",
" }",
"",
" componentDidMount(): void {",
" this.init();",
" }",
"",
" componentWillUnmount(): void {",
" this.view.destroy();",
" this.view = null;",
" }",
"",
" render(): JSX.Element {",
" return <div className={CSS.base} ref={this.container} />;",
" }",
"",
" async init(): Promise<void> {",
" const { map } = this.props;",
"",
" if (!map) {",
" console.error(\"ERROR: NO MAP FOUND\");",
" return;",
" }",
"",
" const { loaded } = map;",
"",
" if (!loaded) {",
" await map.load();",
" }",
"",
" this.createView();",
" }",
"",
" createView(): void {",
" const { map } = this.props;",
" const { type } = map.portalItem;",
" const viewConfig = { map, container: this.container.current };",
" const view =",
" type === WEB_MAP",
" ? new MapView(viewConfig)",
" : type === WEB_SCENE",
" ? new SceneView(viewConfig)",
" : null;",
"",
" if (!view) {",
" console.error(\"ERROR: UNABLE TO CREATE VIEW\");",
" return;",
" }",
"",
" this.view = view;",
" }",
"}",
"",
"export default View;",
""
],
"description": "react component "
}
}