@@ -42,7 +42,10 @@ class _ExampleMapState extends State<ExampleMap> {
42
42
final LatLng _firstPinCoordinates = const LatLng (52.9 , 13.2 );
43
43
static const String _pinId2 = '456' ;
44
44
final LatLng _secondPinCoordinates = const LatLng (51 , 11 );
45
+ static const String _pinFeatureId = '789' ;
46
+ final LatLng _pinFeatureCoordinates = const LatLng (50.945 , 6.965 );
45
47
static const String _pinLayerId = 'PinLayer' ;
48
+ static const String _featureLayerId = 'FeatureLayer' ;
46
49
static const String _polygon1 = 'polygon1' ;
47
50
static const String _polygon2 = 'polygon2' ;
48
51
static const String _polyLayerId = 'PolygonLayer' ;
@@ -61,6 +64,7 @@ class _ExampleMapState extends State<ExampleMap> {
61
64
bool _subscribedToBounds = false ;
62
65
bool _isFirstPinInView = false ;
63
66
bool _isSecondPinInView = false ;
67
+ bool _isFeatureInView = false ;
64
68
bool _subscribedToCenterPosition = false ;
65
69
bool _subscribedToGraphicsInView = false ;
66
70
bool _subscribedToZoom = false ;
@@ -124,6 +128,10 @@ class _ExampleMapState extends State<ExampleMap> {
124
128
elevationMode: ElevationMode .onTheGround,
125
129
);
126
130
131
+ await _createFeatureLayer (
132
+ layerId: _featureLayerId,
133
+ );
134
+
127
135
// Create GraphicsLayer with Lines
128
136
await _createGraphicLayer (
129
137
layerId: _lineLayerId,
@@ -327,6 +335,24 @@ class _ExampleMapState extends State<ExampleMap> {
327
335
_controller? .removeGraphic (layerId: layerId, objectId: objectId);
328
336
}
329
337
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
+
330
356
void _makePolylineVisible ({required List <LatLng > points}) {
331
357
_controller? .moveCameraToPoints (
332
358
points: points,
@@ -568,9 +594,36 @@ class _ExampleMapState extends State<ExampleMap> {
568
594
});
569
595
}
570
596
},
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' ),
574
627
),
575
628
ElevatedButton (
576
629
onPressed: () {
0 commit comments