Skip to content

Commit 48a7370

Browse files
authored
Apply Common Design to Add Feature Collection Layer from Table Sample (#89)
* Update the sample * Add README * Add screen capture * Generate metadata * regenerate samples list * Update add_feature_collection_layer_from_table.png * use cascade * Update README.md * ArcGISPoint
1 parent ae661f9 commit 48a7370

File tree

5 files changed

+173
-77
lines changed

5 files changed

+173
-77
lines changed

assets/generated_samples_list.json

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,33 @@
33
"category": "Layers",
44
"description": "Create a Feature Collection Layer from a Feature Collection Table, and add it to a map.",
55
"ignore": false,
6-
"images": [],
7-
"keywords": [],
6+
"images": [
7+
"add_feature_collection_layer_from_table.png"
8+
],
9+
"keywords": [
10+
"collection",
11+
"feature",
12+
"layers",
13+
"table",
14+
"Feature",
15+
"FeatureCollection",
16+
"FeatureCollectionLayer",
17+
"FeatureCollectionTable",
18+
"Field",
19+
"SimpleRenderer"
20+
],
821
"redirect_from": [],
9-
"relevant_apis": [],
10-
"snippets": [],
22+
"relevant_apis": [
23+
"Feature",
24+
"FeatureCollection",
25+
"FeatureCollectionLayer",
26+
"FeatureCollectionTable",
27+
"Field",
28+
"SimpleRenderer"
29+
],
30+
"snippets": [
31+
"add_feature_collection_layer_from_table_sample.dart"
32+
],
1133
"title": "Add feature collection layer from table",
1234
"key": "add_feature_collection_layer_from_table"
1335
},
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# Add feature collection layer from table
2+
3+
Create a Feature Collection Layer from a Feature Collection Table, and add it to a map.
4+
5+
![Image of add feature collection layer from table](add_feature_collection_layer_from_table.png)
6+
7+
## Use case
8+
9+
A Feature Collection allows easily importing external data (such as CSV files), as well as creating custom schema for data that is in non-standardized format. This data can then be used to populate a Feature Collection Table, and displayed in a Feature Collection Layer using the attributes and geometries provided in the external data source. For example, an electricity supplier could use this functionality to visualize existing location data of coverage areas (polygons), power stations (points), transmission lines (polylines), and others.
10+
11+
## How to use the sample
12+
13+
When launched, this sample displays a `FeatureCollectionLayer` with a `ArcGISPoint`, `Polyline` and `Polygon` geometry. Pan and zoom to explore the scene.
14+
15+
## How it works
16+
17+
1. Create a `FeatureCollectionTable` for the `GeometryType`s `ArcGISPoint`, `Polyline`, and `Polygon`, using `FeatureCollectionTable(fields, geometryType, spatialReference)`, passing in a list of `Field` objects to represent the table's schema, the `GeometryType`, and a `SpatialReference`.
18+
2. Assign a `SimpleRenderer` to each table to render any `Feature`s from that table using the `Symbol` that was set.
19+
3. Use the `FeatureCollectionTable.createFeature(attributes, geometry)` method to create a feature from the feature collection table, passing an attribute and geometry for that feature.
20+
4. Add new features to the table, `FeatureCollectionTable.addFeature(feature)`.
21+
5. Add the feature collection table to the feature collection, `FeatureCollection.tables.add(featureCollectionTable)`.
22+
6. Create a `FeatureCollectionLayer` using the feature collection, `FeatureCollectionLayer.withFeatureCollection(featureCollection)`.
23+
7. Add the feature collection layer to the map, `ArcGISMap.operationalLayers.add(featureCollectionLayer)`.
24+
25+
## Relevant API
26+
27+
* Feature
28+
* FeatureCollection
29+
* FeatureCollectionLayer
30+
* FeatureCollectionTable
31+
* Field
32+
* SimpleRenderer
33+
34+
## Tags
35+
36+
collection, feature, layers, table

lib/samples/add_feature_collection_layer_from_table/README.metadata.json

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,32 @@
22
"category": "Layers",
33
"description": "Create a Feature Collection Layer from a Feature Collection Table, and add it to a map.",
44
"ignore": false,
5-
"images": [],
6-
"keywords": [],
5+
"images": [
6+
"add_feature_collection_layer_from_table.png"
7+
],
8+
"keywords": [
9+
"collection",
10+
"feature",
11+
"layers",
12+
"table",
13+
"Feature",
14+
"FeatureCollection",
15+
"FeatureCollectionLayer",
16+
"FeatureCollectionTable",
17+
"Field",
18+
"SimpleRenderer"
19+
],
720
"redirect_from": [],
8-
"relevant_apis": [],
9-
"snippets": [],
21+
"relevant_apis": [
22+
"Feature",
23+
"FeatureCollection",
24+
"FeatureCollectionLayer",
25+
"FeatureCollectionTable",
26+
"Field",
27+
"SimpleRenderer"
28+
],
29+
"snippets": [
30+
"add_feature_collection_layer_from_table_sample.dart"
31+
],
1032
"title": "Add feature collection layer from table"
1133
}
275 KB
Loading

lib/samples/add_feature_collection_layer_from_table/add_feature_collection_layer_from_table_sample.dart

Lines changed: 85 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -29,55 +29,63 @@ class AddFeatureCollectionLayerFromTableSample extends StatefulWidget {
2929
class _AddFeatureCollectionLayerFromTableSampleState
3030
extends State<AddFeatureCollectionLayerFromTableSample>
3131
with SampleStateSupport {
32-
final _featureCollection = FeatureCollection();
32+
// Create a controller for the map view.
3333
final _mapViewController = ArcGISMapView.createController();
3434

35-
_AddFeatureCollectionLayerFromTableSampleState() {
36-
createPointTable();
37-
createPolylineTable();
38-
createPolygonTable();
39-
}
40-
41-
@override
42-
void initState() {
43-
super.initState();
44-
45-
final map = ArcGISMap.withBasemapStyle(BasemapStyle.arcGISOceans);
46-
47-
map.initialViewpoint = Viewpoint.fromTargetExtent(
48-
Envelope.fromXY(
49-
xMin: -8917856.590171767,
50-
yMin: 903277.583136797,
51-
xMax: -8800611.655131537,
52-
yMax: 1100327.8941287803,
53-
spatialReference: SpatialReference(wkid: 102100),
54-
),
55-
);
56-
57-
map.operationalLayers
58-
.add(FeatureCollectionLayer.withFeatureCollection(_featureCollection));
59-
60-
_mapViewController.arcGISMap = map;
61-
}
62-
6335
@override
6436
Widget build(BuildContext context) {
6537
return Scaffold(
38+
// Add a map view to the widget tree and set a controller.
6639
body: ArcGISMapView(
6740
controllerProvider: () => _mapViewController,
41+
onMapViewReady: onMapViewReady,
6842
),
6943
);
7044
}
7145

72-
void createPointTable() {
46+
void onMapViewReady() {
47+
// Create a feature collection table for each of the geometry types Point, Polyline, and Polygon.
48+
final pointTable = createPointTable();
49+
final polylineTable = createPolylineTable();
50+
final polygonTable = createPolygonTable();
51+
52+
// Create a new feature collection and add the feature collection tables.
53+
final featureCollection = FeatureCollection()
54+
..tables.addAll([pointTable, polylineTable, polygonTable]);
55+
56+
// Create a feature collection layer from the feature collection.
57+
final featureCollectionLayer =
58+
FeatureCollectionLayer.withFeatureCollection(featureCollection);
59+
60+
// Create a map with a basemap style and initial viewpoint.
61+
final map = ArcGISMap.withBasemapStyle(BasemapStyle.arcGISOceans)
62+
..initialViewpoint = Viewpoint.fromTargetExtent(
63+
Envelope.fromXY(
64+
xMin: -8917856.590171767,
65+
yMin: 903277.583136797,
66+
xMax: -8800611.655131537,
67+
yMax: 1100327.8941287803,
68+
spatialReference: SpatialReference(wkid: 102100),
69+
),
70+
);
71+
72+
// Add the feature collection layer to the map's operational layers.
73+
map.operationalLayers.add(featureCollectionLayer);
74+
75+
// Set the map to the map view controller.
76+
_mapViewController.arcGISMap = map;
77+
}
78+
79+
// Create a feature collection table using a point geometry.
80+
FeatureCollectionTable createPointTable() {
81+
// Create a feature collection table for the geometry type with a list of fields and a spatial reference.
7382
final pointTable = FeatureCollectionTable(
74-
fields: [
75-
Field.text(name: 'Place', alias: 'Place Name', length: 50),
76-
],
83+
fields: [Field.text(name: 'Place', alias: 'Place Name', length: 50)],
7784
geometryType: GeometryType.point,
7885
spatialReference: SpatialReference(wkid: 4326),
7986
);
8087

88+
// Set a simple renderer to style features from the table.
8189
pointTable.renderer = SimpleRenderer(
8290
symbol: SimpleMarkerSymbol(
8391
style: SimpleMarkerSymbolStyle.triangle,
@@ -86,75 +94,82 @@ class _AddFeatureCollectionLayerFromTableSampleState
8694
),
8795
);
8896

97+
// Create a point.
98+
final point = ArcGISPoint(
99+
x: -79.497238,
100+
y: 8.849289,
101+
spatialReference: SpatialReference.wgs84,
102+
);
103+
104+
// Create a feature with the point and add it to the table.
89105
final feature = pointTable.createFeature(
90-
attributes: {
91-
'Place': 'Current location',
92-
},
93-
geometry: ArcGISPoint(
94-
x: -79.497238,
95-
y: 8.849289,
96-
spatialReference: SpatialReference.wgs84,
97-
),
106+
attributes: {'Place': 'Current location'},
107+
geometry: point,
98108
);
99109
pointTable.addFeature(feature);
100110

101-
_featureCollection.tables.add(pointTable);
111+
return pointTable;
102112
}
103113

104-
void createPolylineTable() {
105-
final linesTable = FeatureCollectionTable(
114+
// Create a feature collection table using a polyline geometry.
115+
FeatureCollectionTable createPolylineTable() {
116+
// Create a feature collection table for the geometry type with a list of fields and a spatial reference.
117+
final polylineTable = FeatureCollectionTable(
106118
fields: [
107-
Field.text(name: 'Boundary', alias: 'Boundary Name', length: 50),
119+
Field.text(name: 'Boundary', alias: 'Boundary Name', length: 50)
108120
],
109121
geometryType: GeometryType.polyline,
110122
spatialReference: SpatialReference(wkid: 4326),
111123
);
112124

113-
linesTable.renderer = SimpleRenderer(
125+
// Set a simple renderer to style features from the table.
126+
polylineTable.renderer = SimpleRenderer(
114127
symbol: SimpleLineSymbol(
115128
style: SimpleLineSymbolStyle.dash,
116129
color: Colors.green,
117130
width: 3,
118131
),
119132
);
120133

121-
final builder =
134+
// Build a polyline.
135+
final polylineBuilder =
122136
PolylineBuilder.fromSpatialReference(SpatialReference(wkid: 4326));
123-
builder.addPoint(
137+
polylineBuilder.addPoint(
124138
ArcGISPoint(
125139
x: -79.497238,
126140
y: 8.849289,
127141
spatialReference: SpatialReference.wgs84,
128142
),
129143
);
130-
builder.addPoint(
144+
polylineBuilder.addPoint(
131145
ArcGISPoint(
132146
x: -80.035568,
133147
y: 9.432302,
134148
spatialReference: SpatialReference.wgs84,
135149
),
136150
);
151+
final polyline = polylineBuilder.toGeometry();
137152

138-
final feature = linesTable.createFeature(
139-
attributes: {
140-
'Boundary': 'AManAPlanACanalPanama',
141-
},
142-
geometry: builder.toGeometry(),
153+
// Create a feature using the polyline and add it to the table.
154+
final feature = polylineTable.createFeature(
155+
attributes: {'Boundary': 'AManAPlanACanalPanama'},
156+
geometry: polyline,
143157
);
144-
linesTable.addFeature(feature);
158+
polylineTable.addFeature(feature);
145159

146-
_featureCollection.tables.add(linesTable);
160+
return polylineTable;
147161
}
148162

149-
void createPolygonTable() {
163+
// Create a feature collection table using a polygon geometry.
164+
FeatureCollectionTable createPolygonTable() {
165+
// Create a feature collection table for the geometry type with a list of fields and a spatial reference.
150166
final polygonTable = FeatureCollectionTable(
151-
fields: [
152-
Field.text(name: 'Area', alias: 'Area Name', length: 50),
153-
],
167+
fields: [Field.text(name: 'Area', alias: 'Area Name', length: 50)],
154168
geometryType: GeometryType.polygon,
155169
spatialReference: SpatialReference(wkid: 4326),
156170
);
157171

172+
// Set a simple renderer to style features from the table.
158173
polygonTable.renderer = SimpleRenderer(
159174
symbol: SimpleFillSymbol(
160175
style: SimpleFillSymbolStyle.diagonalCross,
@@ -167,38 +182,39 @@ class _AddFeatureCollectionLayerFromTableSampleState
167182
),
168183
);
169184

170-
final builder =
185+
// Build a polygon.
186+
final polygonBuilder =
171187
PolygonBuilder.fromSpatialReference(SpatialReference(wkid: 4326));
172-
builder.addPoint(
188+
polygonBuilder.addPoint(
173189
ArcGISPoint(
174190
x: -79.497238,
175191
y: 8.849289,
176192
spatialReference: SpatialReference.wgs84,
177193
),
178194
);
179-
builder.addPoint(
195+
polygonBuilder.addPoint(
180196
ArcGISPoint(
181197
x: -79.337936,
182198
y: 8.638903,
183199
spatialReference: SpatialReference.wgs84,
184200
),
185201
);
186-
builder.addPoint(
202+
polygonBuilder.addPoint(
187203
ArcGISPoint(
188204
x: -79.11409,
189205
y: 8.895422,
190206
spatialReference: SpatialReference.wgs84,
191207
),
192208
);
209+
final polygon = polygonBuilder.toGeometry();
193210

211+
// Create a feature using the polygon and add it to the table.
194212
final feature = polygonTable.createFeature(
195-
attributes: {
196-
'Area': 'Restricted area',
197-
},
198-
geometry: builder.toGeometry(),
213+
attributes: {'Area': 'Restricted area'},
214+
geometry: polygon,
199215
);
200216
polygonTable.addFeature(feature);
201217

202-
_featureCollection.tables.add(polygonTable);
218+
return polygonTable;
203219
}
204220
}

0 commit comments

Comments
 (0)