Skip to content

Commit ec31fc1

Browse files
committed
Create Feature Layer
1 parent dfc95c6 commit ec31fc1

File tree

1 file changed

+56
-3
lines changed

1 file changed

+56
-3
lines changed

example/lib/main.dart

Lines changed: 56 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,10 @@ class _ExampleMapState extends State<ExampleMap> {
4242
final LatLng _firstPinCoordinates = const LatLng(52.9, 13.2);
4343
static const String _pinId2 = '456';
4444
final LatLng _secondPinCoordinates = const LatLng(51, 11);
45+
static const String _pinFeatureId = '789';
46+
final LatLng _pinFeatureCoordinates = const LatLng(50.945, 6.965);
4547
static const String _pinLayerId = 'PinLayer';
48+
static const String _featureLayerId = 'FeatureLayer';
4649
static const String _polygon1 = 'polygon1';
4750
static const String _polygon2 = 'polygon2';
4851
static const String _polyLayerId = 'PolygonLayer';
@@ -61,6 +64,7 @@ class _ExampleMapState extends State<ExampleMap> {
6164
bool _subscribedToBounds = false;
6265
bool _isFirstPinInView = false;
6366
bool _isSecondPinInView = false;
67+
bool _isFeatureInView = false;
6468
bool _subscribedToCenterPosition = false;
6569
bool _subscribedToGraphicsInView = false;
6670
bool _subscribedToZoom = false;
@@ -124,6 +128,10 @@ class _ExampleMapState extends State<ExampleMap> {
124128
elevationMode: ElevationMode.onTheGround,
125129
);
126130

131+
await _createFeatureLayer(
132+
layerId: _featureLayerId,
133+
);
134+
127135
// Create GraphicsLayer with Lines
128136
await _createGraphicLayer(
129137
layerId: _lineLayerId,
@@ -327,6 +335,24 @@ class _ExampleMapState extends State<ExampleMap> {
327335
_controller?.removeGraphic(layerId: layerId, objectId: objectId);
328336
}
329337

338+
Future<FeatureLayer?> _createFeatureLayer({
339+
required String layerId,
340+
}) async {
341+
final layer = await _controller?.addFeatureLayer(
342+
layerId: layerId,
343+
options: FeatureLayerOptions(
344+
fields: <Field>[
345+
Field(name: 'oid', type: 'oid'),
346+
Field(name: 'id', type: 'string'),
347+
Field(name: 'family', type: 'string'),
348+
Field(name: 'name', type: 'string'),
349+
],
350+
symbol: _markerSymbol,
351+
),
352+
);
353+
return layer;
354+
}
355+
330356
void _makePolylineVisible({required List<LatLng> points}) {
331357
_controller?.moveCameraToPoints(
332358
points: points,
@@ -568,9 +594,36 @@ class _ExampleMapState extends State<ExampleMap> {
568594
});
569595
}
570596
},
571-
child: _isSecondPinInView
572-
? const Text('Remove second Pin')
573-
: const Text('Add second Pin'),
597+
child: _isSecondPinInView ? const Text('Remove second Pin') : const Text('Add second Pin'),
598+
),
599+
ElevatedButton(
600+
onPressed: () {
601+
if (_isFeatureInView) {
602+
_removeGraphic(
603+
layerId: _featureLayerId,
604+
objectId: _pinFeatureId,
605+
);
606+
setState(() {
607+
_isFeatureInView = false;
608+
});
609+
} else {
610+
_addPin(
611+
layerId: _featureLayerId,
612+
objectId: _pinFeatureId,
613+
location: _pinFeatureCoordinates,
614+
);
615+
_controller?.moveCamera(
616+
point: _pinFeatureCoordinates,
617+
zoomLevel: 15,
618+
);
619+
setState(() {
620+
_isFeatureInView = true;
621+
});
622+
}
623+
},
624+
child: _isFeatureInView
625+
? const Text('Remove FeatureLayer Pin')
626+
: const Text('Add FeatureLayer Pin'),
574627
),
575628
ElevatedButton(
576629
onPressed: () {

0 commit comments

Comments
 (0)