GalliMapController
animateCamera
Starts an animated change of the map camera position. Duration is the amount of time, that the transition animation should take. The returned [Future] completes after the change has been started on the platform side. It returns true if the camera was successfully moved and false if the movement was canceled. Note: this currently always returns immediately with a value of null on iOS
LatLng? myLocation =await controller!.requestMyLocationLatLng(); controller!.animateCamera(CameraUpdate.newLatLng(myLocation!),duration: const Duration(milliseconds: 500)); controller!.animateCamera(CameraUpdate.newLatLngZoom(myLocation, 18)); controller!.animateCamera(CameraUpdate.bearingTo(0.0)); //animates to north controller!.animateCamera(CameraUpdate.tiltTo(60)); // 3d view controller!.animateCamera(CameraUpdate.newCameraPosition(CameraPosition(target: myLocation, bearing: 40, tilt: 30, zoom: 12))); controller!.animateCamera(CameraUpdate.zoomTo(50.0)); controller!.animateCamera(CameraUpdate.zoomBy(-0.5));//Zoom out in .5 controller!.animateCamera(CameraUpdate.zoomIn());/// Returns a camera update that zooms the camera in, bringing the camera /// closer to the surface of the Earth. /// Equivalent to the result of calling `zoomBy(1.0)`
moveCamera
Instantaneously re-position the camera. The returned [Future] completes after the change has been made on the platform side. It returns true if the camera was successfully moved and false if the movement was canceled. Note: this currently always returns immediately with a value of null on iOS. moveCamera() quickly moves the camera, which can be visually jarring for a user. Strongly consider using the animateCamera() methods instead because it's less abrupt
controller!.moveCamera(CameraUpdate.newLatLngZoom(myLocation, 18)); controller!.moveCamera(CameraUpdate.newCameraPosition(CameraPosition(target: myLocation, bearing: 40, tilt: 30, zoom: 12))); controller!.moveCamera(CameraUpdate.bearingTo(45.0));///// Returns a camera update that sets the camera bearing. controller!.moveCamera(CameraUpdate.tiltTo(35.0));///// Returns a camera update that sets the camera bearing. controller!.moveCamera(CameraUpdate.scrollBy(50, 75));/// Returns a camera update that moves the camera target the specified screen /// distance. /// /// For a camera with bearing 0.0 (pointing north), scrolling by 50,75 moves /// the camera's target to a geographical location that is 50 to the east and /// 75 to the south of the current location, measured in screen coordinates. controller!.moveCamera( CameraUpdate.newLatLngBounds(LatLngBounds(southwest: const LatLng(28, 50), northeast: const LatLng(84.982446, 53.823821),),left: 10,top: 5, bottom: 25,),);/// Returns a camera update that transforms the camera so that the specified /// geographical bounding box is centered in the map view at the greatest /// possible zoom level. A non-zero [left], [top], [right] and [bottom] padding /// insets the bounding box from the map view's edges. /// The camera's new tilt and bearing will both be 0.0.
addGeoJsonSource
Adds a new geojson source The json in [geojson] has to comply with the schema for FeatureCollection as specified in https://datatracker.ietf.org/doc/html/rfc7946#section-3.3 [promoteId] can be used on web to promote an id from properties to be the id of the feature. This is useful because by default mapbox-gl-js does not support string ids The returned [Future] completes after the change has been made on the platform side.
const _points = { "type": "FeatureCollection", "features": [ { "type": "Feature", "id": 2, "properties": { "type": "restaurant", }, "geometry": { "type": "Point", "coordinates": [151.184913929732943, -33.874874486427181] } }, { "type": "Feature", "id": 3, "properties": { "type": "airport", }, "geometry": { "type": "Point", "coordinates": [151.215730044667879, -33.874616048776858] } }, { "type": "Feature", "id": 4, "properties": { "type": "bakery", }, "geometry": { "type": "Point", "coordinates": [151.228803547973598, -33.892188026142584] } }, { "type": "Feature", "id": 5, "properties": { "type": "college", }, "geometry": { "type": "Point", "coordinates": [151.186470299174118, -33.902781145804774] } } ] }; await controller.addGeoJsonSource("points", _points);
setGeoJsonSource
Sets new geojson data to and existing source This only works as exected if the source has been created with [addGeoJsonSource] before. This is very useful if you want to update and existing source with modified data. The json in [geojson] has to comply with the schema for FeatureCollection as specified in https://datatracker.ietf.org/doc/html/rfc7946#section-3.3. The returned [Future] completes after the change has been made on the platform side.
const _points = { "type": "FeatureCollection", "features": [ { "type": "Feature", "id": 2, "properties": { "type": "restaurant", }, "geometry": { "type": "Point", "coordinates": [151.184913929732943, -33.874874486427181] } }, { "type": "Feature", "id": 3, "properties": { "type": "airport", }, "geometry": { "type": "Point", "coordinates": [151.215730044667879, -33.874616048776858] } }, { "type": "Feature", "id": 4, "properties": { "type": "bakery", }, "geometry": { "type": "Point", "coordinates": [151.228803547973598, -33.892188026142584] } }, { "type": "Feature", "id": 5, "properties": { "type": "college", }, "geometry": { "type": "Point", "coordinates": [151.186470299174118, -33.902781145804774] } } ] }; Map<String, dynamic> buildFeatureCollection( List<Map<String, dynamic>> features) { return {"type": "FeatureCollection", "features": features}; } await controller.setGeoJsonSource( "points", buildFeatureCollection( [for (final l in _idToAnnotation.values) l.toGeoJson()]));
setGeoJsonSource
Sets new geojson data to and existing source This only works as exected if the source has been created with [addGeoJsonSource] before. This is very useful if you want to update and existing source with modified data. The json in [geojson] has to comply with the schema for FeatureCollection as specified in https://datatracker.ietf.org/doc/html/rfc7946#section-3.3. The returned [Future] completes after the change has been made on the platform side.
const _points = { "type": "FeatureCollection", "features": [ { "type": "Feature", "id": 2, "properties": { "type": "restaurant", }, "geometry": { "type": "Point", "coordinates": [151.184913929732943, -33.874874486427181] } }, { "type": "Feature", "id": 3, "properties": { "type": "airport", }, "geometry": { "type": "Point", "coordinates": [151.215730044667879, -33.874616048776858] } }, { "type": "Feature", "id": 4, "properties": { "type": "bakery", }, "geometry": { "type": "Point", "coordinates": [151.228803547973598, -33.892188026142584] } }, { "type": "Feature", "id": 5, "properties": { "type": "college", }, "geometry": { "type": "Point", "coordinates": [151.186470299174118, -33.902781145804774] } } ] }; Map<String, dynamic> buildFeatureCollection( List<Map<String, dynamic>> features) { return {"type": "FeatureCollection", "features": features}; } await controller.setGeoJsonSource( "points", buildFeatureCollection( [for (final l in _idToAnnotation.values) l.toGeoJson()]));
addFill
Draw a polygon shape
The shape of the polygon depends on the geometry value where we pass the LatLng value. The fillColor, fillOpacity, fillOutlined defines the color ,opacity and the outlined border of the polygon. The value of draggable true means we can drag the polygon shape anywhere as our needs. fill is the type of Polygon, and it will hold a reference to the polygon you added to the map.
fill = await controller!.addFill( FillOptions( geometry:[ [ const LatLng(27.67716169091915, 85.32351400940793), const LatLng(27.686905357153325, 85.29121975636747), const LatLng(27.678255189059094, 85.32130244340281), const LatLng(27.676677989274484, 85.32005253409616), const LatLng(27.67649922688999, 85.32053625519644), ], [ const LatLng(27.67784997449824, 85.31975107971293), const LatLng(27.677681826553137, 85.32105401182574), const LatLng(27.678113449844247, 85.3216138824787), const LatLng(27.678398466065133, 85.32168961069732), ] ]; fillColor: "#FF0000", fillOutlineColor: "#FF0000", fillOpacity: 0.25, draggable: true, ),
addFills
Draw a multiple fills
Multiple fills will appear as per there define geometry where we can change the color,opacity,outlinecolor,pattern as described below. we can add as many as addfills .
final List<FillOptions> FillOptionList = [ FillOptions( geometry: _defaultGeometry, fillColor: "#FF0000", fillOutlineColor: "#FF0000", fillOpacity: 0.75, draggable: true, fillPattern: 'assets/images/bank.png', ), ]; await controller!.addFills(FillOptionList);
clearFills
It clear all the fills at once which has been created.
await controller!.clearFills();
updateFills
we can update the fills as per there requirement as mentioned below with there geometry,color,opacity.outlineColor.
final FillOptions changes = FillOptions( geometry: _defaultGeometry, fillColor: "#FF0000", fillOutlineColor: "#FF0000", fillOpacity: 0.75, draggable: true, fillPattern: 'assets/images/bank.png', ); await controller!.updateFill(fill!, changes);
removeFill
It will remove the polygon if there is any polygon lie.
controller!.removeFill(fill!);
removeFills
It will remove the fills which have been created .The _fills which have been mentioned below was stored in the list.
await controller!.removeFills(_fills);
addCircle
Draw a Circle Shape
The location of the circle lies according to the geometry which is LatLng . The radius of the circle will be formed on given location as per given radius . The circleColor, circleOpacity, circleStrokeColor, circleStrokeWidth, cricleStrokeOpacity, defines the color, opacity , strokecolor,width of stroke and stroke opacity. Draggable true means we can drag the circle on the map.
_selectedCircle is of type Circle, and it will hold a reference to the circle you added to the map.
//fill is of type Circle, and it will hold a reference to the circle you added to the map. _selectedCircle = await controller!.addCircle( circleRadius: 60, geometry: LatLng(27.67649922688999, 85.32053625519644), circleColor: "#FF0000", circleOpacity: .25, circleStrokeColor: "#0000FF", circleStrokeWidth: 2.0, circleStrokeOpacity: .5, circleBlur: 1, draggable: true), );
UpdateCircle
It will update the circles as per the mentioned changes. The update circle can be mentioned with their own radius, opacity,stroke,strokewidth, ad mentioned below.
controller!.animateCamera(CameraUpdate.newLatLng( LatLng(27.67784997449824, 85.31975107971293))); final CircleOptions changes = CircleOptions( geometry: LatLng(27.67784997449824, 85.31975107971293), circleRadius: 30, circleColor: "#0000FF", circleStrokeOpacity: .2, circleStrokeColor: "#FF0000", circleStrokeWidth: 3, circleOpacity: .8); await controller!.updateCircle(_selectedCircle!, changes);
addCircles
Multiple circles can be add with their define properties like radius, color,strokecolor,strokewidth. we can add as many circle as we want from given example of code.
final List<CircleOptions> circleOptionsList = [ CircleOptions( geometry: LatLng(27.67784997449824, 85.31975107971293), circleRadius: 30, circleColor: "#0000FF", circleStrokeOpacity: .2, circleStrokeColor: "#FF0000", circleStrokeWidth: 3, circleOpacity: .8, draggable: true), ]; await controller!.addCircles(circleOptionsList);
removeCircle
It will remove the circle if there is any circle lie.
controller!.removeCircle(_selectedcircle!);
removeCircles
It will remove the circles which have been created .The _circles which have been mentioned below was stored in the list.
await controller!.removeCircles(_circles);
getCircleLatLng
we can get the circle Latitude Longitude which has been created of the _selectedCircle.
await controller!.getCircleLatLng(_selectedCircle!)
clearCircles
It will clear all the circle which have been created at once
await controller!.clearCircles();
addLine
Draw a Line
The line appears on the map depends on the geometry provided by the user which is LatLng. The lineColor ,lineWidth, lineOpacity, means color, width, opacity. The lineJoin means the shape at the join on different geometry. The lineGapwidth means the gap in the middle of the line. The draggable true means we can drag the line.
_selectedLine is of type Line, and it will hold a reference to the Line you added to the map.
_selectedLine = await controller!.addLine(LineOptions( geometry: [ LatLng(27.6746453246322, 85.33441614189833), LatLng(27.675822921057367, 85.32545000104156), LatLng(27.6829891627444, 85.32609586712023), LatLng(27.68292187627674, 85.3320986224396), ], lineColor: "#ff0000", lineWidth: 15.0, lineOpacity: 0.5, draggable: true, lineJoin: 'round', lineGapWidth: 2, lineBlur: 3, lineOffset: 2, ));
updateLine
It will update the Lines from the start and end point. The line will be update as pert the mentioned condition.
final currentStart = _selectedLine!.options.geometry![0]; final currentEnd = _selectedLine!.options.geometry![1]; // Calculate the new coordinates for the start and end points final end = LatLng( currentEnd.latitude + 0.001, currentEnd.longitude + 0.001); final start = LatLng(currentStart.latitude - 0.001, currentStart.longitude - 0.001); // Update the line's geometry with the new start and end points await controller!.updateLine( _selectedLine!, LineOptions(geometry: [start, end]));
addLines
Multiple lines can be added . The added line can have their own properties like color,geometry,opacity,blur, offset as mentioned below.
final List<LineOptions> LineOptionsList = [ LineOptions( geometry: [ LatLng(27.6746453246322, 85.33441614189833), LatLng(27.675822921057367, 85.32545000104156), LatLng(27.6829891627444, 85.32609586712023), LatLng(27.68292187627674, 85.3320986224396), ], lineColor: "#ff0000", lineWidth: 15.0, lineOpacity: 0.5, draggable: true, lineJoin: 'round', lineGapWidth: 2, lineBlur: 3, lineOffset: 2, ) ]; await controller!.addLines(LineOptionsList);
removeLine
It will reomve the line if there is any line.
controller!.removeLine(_selectedLine);
removeLines
It will removes the line which has been creates .The _lines is the list in which created line is stored.
await controller!.removeLines(_lines);
clearLines
It will clear all the lines at once which has been created.
await controller!.clearLines();
getLineLatLngs
we can get the line Latitude Longitude which has been created of the _selectedLine.
await controller!.getLineLatLngs(_selectedLine!)
addGalliMarker
Add a marker
The marker appear on the map depends on the geometry provided by the user which is LatLng. The iconSize, iconOpacity,iconImage,iconColor means size,opacity,image,color of the icons . The other properties we can used can be shown on the below example.
_selectedMarker is of type Marker,and it will hold a reference to the Marker you added to the map.
if (_selectedMarker == null) { _selectedMarker = await controller!.addGalliMarker(const GalliMarkerOptions( geometry: LatLng(27.679532173752087, 85.31970941996086), iconAnchor: 'center ', iconSize: 0.5, iconHaloBlur: 10, iconHaloWidth: 2, iconOpacity: 0.9, iconOffset: Offset(0, 0.8), iconColor: '#0077FF', iconHaloColor: '#FFFFFF', iconImage: 'assets/images/bank.png', draggable: true, ));
removeGalliMarker
It will reomve the markers if there is any marker.
await controller!.removeGalliMarker(_selectedMarker!);
addGalliMarkers
We can added the multiple markers with the properties like geometry,iconSize,iconOpacity,iconColor,iconImage as mentioned below.
// Create a list of LatLng coordinates List<LatLng> markerCoordinates = [ LatLng(27.679532173752087, 85.31970941996086), LatLng(27.678398466065133, 85.32168961069732), LatLng(27.67686348105365, 85.32227904529707), // Add more coordinates as needed ]; // Create a list of GalliMarkerOptions using the LatLng coordinates List<GalliMarkerOptions> markerOptionsList = markerCoordinates.map((LatLng latLng) { return GalliMarkerOptions( geometry: latLng, iconAnchor: 'center', iconSize: 0.5, iconHaloBlur: 10, iconHaloWidth: 2, iconOpacity: 0.9, iconOffset: Offset(0, 0.8), iconColor: '#0077FF', iconHaloColor: '#FFFFFF', iconImage: 'assets/images/bank.png', draggable: true, ); }).toList(); await controller!.addGalliMarkers(markerOptionsList);
clearGalliMarkers
It will clear all the markers at once .
await controller!.clearGalliMarkers();
getGalliMarkerLatLng
we can get the longitude and latitude of the selected markers.
await controller!.getGalliMarkerLatLng(_selectedMarker!);
addImage
we can add image on the map in the given geometry.
final ByteData bytes = await rootBundle.load('assets/images/doctor-2.jpg'); final Uint8List list = bytes.buffer.asUint8List(); final GalliMarkerOptions markerOptions = GalliMarkerOptions( geometry: LatLng(27.67784997449824, 85.31975107971293), // Change to the desired coordinates iconImage: 'assetImage', iconSize: 0.1, ); await controller!.addImage('assetImage', list); await controller!.addGalliMarker(markerOptions);
getVisibleRegion
This method returns the boundaries of the region currently displayed in the map.
try { LatLngBounds visibleRegion = await controller!.getVisibleRegion(); print("Visible Region:"); print("Southwest: ${visibleRegion.southwest}"); print("Northeast: ${visibleRegion.northeast}"); } catch (e) { print("Error: $e"); }
requestMyLocationLatLng
This methods returns the user location.
if (controller != null) { // Request the user's current location LatLng? myLocation = await controller!.requestMyLocationLatLng(); // Move the camera to the user's location controller!.animateCamera(CameraUpdate.newLatLng(myLocation!)); }
toScreenLocation
This method allows you to convert a geograpahical location to its corresponding screen coordinates on the map. The latlLng is the geographical location.
LatLng latLng = LatLng(27.67649922688999, 85.32053625519644); try { var screenPosMap = await controller!.toScreenLocation(latLng); // Print the screen position print( "Screen Position - X: ${screenPosMap.x}, Y: ${screenPosMap.y}"); } catch (e) { print("Error: $e"); }
toScreenLocationBatch
This method allows you to convert multiple geographical locations into screen coordinates in a batch. This can be useful when you have multiple points of interest on a map and need to work with their screen positions for various purposes, such as placing markers or annotations at specific positions on the map based on geographic coordinates. The latLngsBatch is the multiple geographical coordinates.
List<LatLng> latLngsBatch = [ LatLng(27.67649922688999, 85.32053625519644), LatLng(27.678398466065133, 85.32168961069732), LatLng(27.678113449844247, 85.3216138824787), // Add more LatLng coordinates as needed ]; LatLng latLng = LatLng(27.67649922688999, 85.32053625519644); try { List<Point> screenPositions = await controller!.toScreenLocationBatch(latLngsBatch); // Print the screen position for (int i = 0; i < latLngsBatch.length; i++) { print( "LatLng: ${latLngsBatch[i]}, Screen Position: ${screenPositions[i]}"); } } catch (e) { print("Error: $e"); }
getMetersPerPixelAtLatitude
It returns the distance spanned by one pixel at the specified [latitude] and current zoom level. The distance between pixels decreases as the latitiude approaches the poles. This relationship parallels the relationship between longitudinal coordinates at different latitudes.
LatLng latLng = LatLng(27.67649922688999, 85.32053625519644); double metersPerPixel = await controller!.getMetersPerPixelAtLatitude(latLng.latitude); debugPrint( "Map long press The distance measured in meters at latitude ${latLng.latitude} is $metersPerPixel m");
toLatLng
It returns the geographic location (as [LatLng]) that corresponds to a point on the screen. The screen location is specified in screen pixels (not display pixels) relative to the top left of the map (not the top left of the whole screen).
LatLng convertedLatLng = await controller!.toLatLng(Point(462.92, 1048.57)); debugPrint( "Bottom press converted: ${convertedLatLng.latitude}/${convertedLatLng.longitude}");
setCameraBounds
It is used to restrict the camera view of the map to a specific geographic area defined by the coordinates (west, north, south, east), with an optional padding to improve the map's visual appearance and user experience. By setting camera bounds, you can control which area of the map is visible to the user and prevent them from panning outside of this region.
double west = 85.31975107971293; double north = 27.678113449844247; double south = 27.677681826553137; double east = 85.32168961069732; int padding = 25; controller!.setCameraBounds( west: west, north: north, south: south, east: east, padding: padding);
getLayerIds
It is used to fetch and display the layer IDs present in the Mapbox map controller. It can be helpful for debugging and understanding the structure of layers in a Mapbox map, as it provides a list of the IDs associated with various map elements like markers, polygons, or other map features.
List<String> layerIds = []; await controller!.getLayerIds().then((value) { for (dynamic data in value) { layerIds.add(data.toString()); } for (String layerId in layerIds) { print("Layer ID: $layerId"); }
getSourceIds
Retrieve every source ids of the map as a [String] list, including the ones added internally
List<String> sourceIds = []; await controller!.getSourceIds().then((value) { for (dynamic data in value) { sourceIds.add(data.toString()); } for (String sourceId in sourceIds) { print("Source ID: $sourceId"); } });
queryRenderedFeatures
It is used to query for and print information about features on a map at a specific screen coordinate, using layer IDs to filter the results. It's a common operation in map-based applications to retrieve information about objects or features displayed on the map at a particular location.
try { List<dynamic> dynamicLayerIds = await controller!.getLayerIds(); // Convert dynamicLayerIds to List<String> List<String> layerIds = dynamicLayerIds .map((dynamicId) => dynamicId.toString()) .toList(); // Define the screen coordinates double screenX = 462.92; double screenY = 1048.57; // Create a Point<double> from screenX and screenY Point<double> screenPoint = Point<double>(screenX, screenY); // Query for rendered features at the screen coordinate for the current layer List features = await controller! .queryRenderedFeatures(screenPoint, layerIds, null); if (features.isNotEmpty) { // Convert the feature to a string and then print it String featureString = features[0].toString(); print("\nFeature: $featureString"); } } catch (e) { // Handle any errors that may occur print("Error: $e"); }
queryRenderedFeaturesInRect
It allows you to query for features
It is used to query for and print information about features on a map within a defined rectangular region , using layer IDs to filter the results. It's a common operation in map-based applications to retrieve information about objects or features displayed on the map at a particular location.
try { List<dynamic> dynamicLayerIds = await controller!.getLayerIds(); // Convert dynamicLayerIds to List<String> List<String> layerIds = dynamicLayerIds .map((dynamicId) => dynamicId.toString()) .toList(); // Define the Rect for the region you want to query Rect rect = Rect.fromLTRB(0, 0, 100, 500); // Query for rendered features at the screen coordinate for the current layer List features = await controller! .queryRenderedFeaturesInRect(rect, layerIds, null); log("feautres: $features"); if (features.isNotEmpty) { // Convert the feature to a string and then print it String featureString = features[0].toString(); print("\nFeature: $featureString"); } } catch (e) { // Handle any errors that may occur print("Error: $e"); }
querySourceFeatures
It is designed to interact with a map controller, retrieve features from a specific data source based on defined criteria and process . It provides flexibility to choose the data source, source layer, and apply filters as needed.
try { // Get a list of source IDs List<String> sourceIds = []; await controller!.getSourceIds().then((value) { for (dynamic data in value) { sourceIds.add(data.toString()); } for (String sourceId in sourceIds) { print("Source ID: $sourceId"); } }); // Choose the specific source ID and source layer ID based on the feature properties String sourceId = 'mapbox-location-source'; // Replace with the actual source ID you want to use String? sourceLayerId; // Set to null or specify the source layer ID if applicable // Define a filter if you want to filter the features, set to null if not needed List<Object>? filter = null; // Replace with your filter criteria if needed // Query source features for the chosen source ID and source layer ID List<dynamic> features = await controller! .querySourceFeatures(sourceId, sourceLayerId, filter); if (features.isNotEmpty) { // Loop through the features and process them as needed for (var feature in features) { // Convert the feature to a string and then print it String featureString = feature.toString(); print("\nFeature from Source ID $sourceId: $featureString"); } } } catch (e) { // Handle any errors that may occur print("Error: $e"); }
setLayerVisibility
It retrieves and prints the layer IDs from the Mapbox controller, and then sets the visibility of each layer to true. If the setlayerVisibility is set to false it will disappears all the layer.
List<String> layerIds = []; try { List<dynamic> dynamicLayerIds = await controller!.getLayerIds(); layerIds = dynamicLayerIds .map((dynamicId) => dynamicId.toString()) .toList(); for (String layerId in layerIds) { print("Layer ID: $layerId"); await controller!.setLayerVisibility(layerId, true); } } catch (e) { // Handle any errors that may occur print("Error: $e"); }
getFilter
It is used to inspect the filters applied to layers on your Mapbox map, excluding the 'background' layer. It's useful for debugging and understanding how data is filtered and displayed on the map.
try { List<String> layerIds = []; List<dynamic> dynamicLayerIds = await controller!.getLayerIds(); layerIds = dynamicLayerIds .map((dynamicId) => dynamicId.toString()) .toList(); for (String layerId in layerIds) { // Skip layers that are not suitable for filtering if (layerId != 'background') { print("Layer ID: $layerId"); // Fetch the filter for the current layer dynamic filter = await controller!.getFilter(layerId); // Print the filter to the console print('Filter for layer ID $layerId: $filter'); } } } catch (e) { // Handle any errors that may occur print("Error: $e"); }
setFilter
It apply filters to layers on your Mapbox map while skipping specified layers. It provides flexibility in customizing how data is displayed on the map based on your filtering criteria.The LayedIdsToSkip is the layer which skip and and apply filter to all the layer.
try { List<String> layerIdsToSkip = [ 'background', 'mapbox-location-background-layer', 'mapbox-location-shadow-layer', 'boundary', 'amenity_point' ]; // Add the layer IDs you want to skip to this list List<String> layerIds = []; List<dynamic> dynamicLayerIds = await controller!.getLayerIds(); layerIds = dynamicLayerIds .map((dynamicId) => dynamicId.toString()) .toList(); for (String layerId in layerIds) { // Skip layers that are not suitable for filtering if (!layerIdsToSkip.contains(layerId)) { print("Layer ID: $layerId"); // Define your filter criteria dynamic filter = ['==', 'osm_subtype', 'nature_reserve']; // Set the filter for the current layer await controller!.setFilter(layerId, filter); } } } catch (e) { // Handle any errors that may occur print("Error: $e"); }
updateMyLocationTrackingMode
It enables continuous tracking of the user's location on the map and prints their current location to the console as they move.
controller!.updateMyLocationTrackingMode( MyLocationTrackingMode.tracking); print( 'Current Location: Latitude=${myLocation.latitude}, Longitude=${myLocation.longitude}');
updateContentInsets
It is used to update the content insets of a UI element with specified padding values and provides error handling to handle any potential issues that may arise during the update. Content insets are often used to control the spacing or margins around UI elements to achieve a desired layout and appearance.
EdgeInsets newInsets = EdgeInsets.only( top: 16.0, bottom: 16.0, left: 18.0, right: 28.0, ); try { await controller!.updateContentInsets(newInsets, true); print('Content insets updated successfully.'); } catch (e) { print('Error updating content insets: $e'); }
invalidateAmbientCache
It is used to invalidate an ambient cache, typically to ensure that any cached data related to the ambient context is updated or cleared as needed.
try { // Invalidate the ambient cache await controller!.invalidateAmbientCache(); print('Ambient cache invalidated successfully.'); } catch (e) { // Handle any errors that may occur print('Error invalidating ambient cache: $e'); }
removeLayer
It retrieves a list of dynamic layer IDs, converts them to strings, and then removes each layer from the map using the Mapbox controller. It provides a way to dynamically clear all layers from the map as needed, which can be useful in various map-related applications.
try { List<dynamic> dynamicLayerIds = await controller!.getLayerIds(); layerIds = dynamicLayerIds .map((dynamicId) => dynamicId.toString()) .toList(); // Print the list of layer IDs for (String layerId in layerIds) { print("Layer ID: $layerId"); } } catch (e) { print("Error getting layer IDs: $e"); } // Remove each layer for (String layerId in layerIds) { await controller!.removeLayer(layerId); }
setGalliMarkerIconAllowOverlap
It sets a configuration option for marker icons on the map, allowing them to overlap when they are close to each other.
await controller!.setGalliMarkerIconAllowOverlap(true);
setGalliMarkerIconIgnorePlacement
It configures a setting for marker icons on the map, indicating that they should not ignore placement rules and should adhere to positioning constraints.
await controller!.setGalliMarkerIconIgnorePlacement(false);
reverGeoCoding
It performs reverse geocoding to convert latitude and longitude coordinates into a location name.
String? locationString = await controller! .reverGeoCoding(LatLng(27.67686348105365, 85.32227904529707)); if (locationString != null) { print("Reverse Geocoded Location: $locationString"); } else { print("Reverse Geocoding failed or no location found."); }