diff --git a/example/lib/main.dart b/example/lib/main.dart index dc5e48b1..235775f2 100644 --- a/example/lib/main.dart +++ b/example/lib/main.dart @@ -42,7 +42,10 @@ class _ExampleMapState extends State { final LatLng _firstPinCoordinates = const LatLng(52.9, 13.2); static const String _pinId2 = '456'; final LatLng _secondPinCoordinates = const LatLng(51, 11); + static const String _pinFeatureId = '789'; + final LatLng _pinFeatureCoordinates = const LatLng(50.945, 6.965); static const String _pinLayerId = 'PinLayer'; + static const String _featureLayerId = 'FeatureLayer'; static const String _polygon1 = 'polygon1'; static const String _polygon2 = 'polygon2'; static const String _polyLayerId = 'PolygonLayer'; @@ -61,6 +64,7 @@ class _ExampleMapState extends State { bool _subscribedToBounds = false; bool _isFirstPinInView = false; bool _isSecondPinInView = false; + bool _isFeatureInView = false; bool _subscribedToCenterPosition = false; bool _subscribedToGraphicsInView = false; bool _subscribedToZoom = false; @@ -124,6 +128,10 @@ class _ExampleMapState extends State { elevationMode: ElevationMode.onTheGround, ); + await _createFeatureLayer( + layerId: _featureLayerId, + ); + // Create GraphicsLayer with Lines await _createGraphicLayer( layerId: _lineLayerId, @@ -327,6 +335,24 @@ class _ExampleMapState extends State { _controller?.removeGraphic(layerId: layerId, objectId: objectId); } + Future _createFeatureLayer({ + required String layerId, + }) async { + final layer = await _controller?.addFeatureLayer( + layerId: layerId, + options: FeatureLayerOptions( + fields: [ + Field(name: 'oid', type: 'oid'), + Field(name: 'id', type: 'string'), + Field(name: 'family', type: 'string'), + Field(name: 'name', type: 'string'), + ], + symbol: _markerSymbol, + ), + ); + return layer; + } + void _makePolylineVisible({required List points}) { _controller?.moveCameraToPoints( points: points, @@ -568,9 +594,36 @@ class _ExampleMapState extends State { }); } }, - child: _isSecondPinInView - ? const Text('Remove second Pin') - : const Text('Add second Pin'), + child: _isSecondPinInView ? const Text('Remove second Pin') : const Text('Add second Pin'), + ), + ElevatedButton( + onPressed: () { + if (_isFeatureInView) { + _removeGraphic( + layerId: _featureLayerId, + objectId: _pinFeatureId, + ); + setState(() { + _isFeatureInView = false; + }); + } else { + _addPin( + layerId: _featureLayerId, + objectId: _pinFeatureId, + location: _pinFeatureCoordinates, + ); + _controller?.moveCamera( + point: _pinFeatureCoordinates, + zoomLevel: 15, + ); + setState(() { + _isFeatureInView = true; + }); + } + }, + child: _isFeatureInView + ? const Text('Remove FeatureLayer Pin') + : const Text('Add FeatureLayer Pin'), ), ElevatedButton( onPressed: () {