### Flutter createState Method Example Source: https://pub.dev/documentation/flutter_map_heatmap/latest/flutter_map_heatmap/HeatMapPaint/createState Demonstrates how to override the createState method in a Flutter StatefulWidget. This method is essential for creating the mutable state object associated with the widget. It's crucial to return a new instance of your custom State subclass. ```dart @override State createState() => _SomeWidgetState(); ``` ```dart @override _HeatMapPaintState createState() => _HeatMapPaintState(); ``` -------------------------------- ### Integrate Heatmap Layer in FlutterMap Source: https://pub.dev/documentation/flutter_map_heatmap/latest/index This Dart code demonstrates how to integrate the `HeatMapLayer` into a `FlutterMap` widget. It shows the basic setup with `MapOptions`, a `TileLayer`, and the conditional rendering of the `HeatMapLayer` using `InMemoryHeatMapDataSource` and `HeatMapOptions`. ```dart Widget build(BuildContext context) { return FlutterMap( options: new MapOptions(initialCenter: new LatLng(57.8827, -6.0400), initialZoom: 8.0), children: [ TileLayer( urlTemplate: "https://tile.openstreetmap.org/{z}/{x}/{y}.png"), if (data.isNotEmpty) HeatMapLayer( heatMapDataSource: InMemoryHeatMapDataSource(data: data), heatMapOptions: HeatMapOptions(gradient: this.gradients[this.index], minOpacity: 0.1), reset: _rebuildStream.stream, ) ], ); } ``` -------------------------------- ### Bitmap Constructors Source: https://pub.dev/documentation/flutter_map_heatmap/latest/flutter_map_heatmap/Bitmap-class Provides details on how to create a Bitmap object from raw RGBA data. ```APIDOC ## Bitmap.fromHeadless ### Description Creates a Bitmap object from raw RGBA data by adding bitmap header information. ### Method Constructor ### Endpoint N/A ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body - **width** (int) - Required - The width of the bitmap. - **height** (int) - Required - The height of the bitmap. - **content** (Uint8List) - Required - The raw RGBA data of the bitmap. ### Request Example ```dart final bitmap = Bitmap.fromHeadless(100, 150, Uint8List.fromList([...])); ``` ### Response #### Success Response (N/A - Constructor) Returns a Bitmap object. #### Response Example N/A ``` -------------------------------- ### HeatMap Constructor and Properties - Dart Source: https://pub.dev/documentation/flutter_map_heatmap/latest/flutter_map_heatmap/HeatMap-class Demonstrates the instantiation of a HeatMap object using its constructor and highlights key properties like options, dimensions, and data. This is fundamental for setting up a heatmap layer in a Flutter map. ```dart final HeatMapOptions options; final double width; final double height; final List data; HeatMap.new(this.options, this.width, this.height, this.data); ``` -------------------------------- ### Bitmap Methods Source: https://pub.dev/documentation/flutter_map_heatmap/latest/flutter_map_heatmap/Bitmap-class Lists and describes the methods available for the Bitmap class, such as building images and cloning bitmaps. ```APIDOC ## Bitmap Methods ### Description Provides functionality to build a headed image from the bitmap data, create a future Image object, and create a copy of the bitmap. ### Methods - **buildHeaded() → Uint8List** Builds the bitmap data with header information. - **buildImage() → Future** Asynchronously builds an Image object from the bitmap data. - **cloneHeadless() → Bitmap** Creates a new Bitmap object that is a headless copy of the current one. ``` -------------------------------- ### AltBaseCirclePainter Class Overview Source: https://pub.dev/documentation/flutter_map_heatmap/latest/flutter_map_heatmap/AltBaseCirclePainter-class Details about the AltBaseCirclePainter class, including its inheritance, constructors, properties, and methods. ```APIDOC ## AltBaseCirclePainter Class ### Description A custom painter class used for drawing circles with a gradient blur effect. It extends `CustomPainter` and provides properties to control the radius and blur factor. ### Inheritance * Object * Listenable * CustomPainter * AltBaseCirclePainter ### Constructors #### `AltBaseCirclePainter.new({required double radius, double blurFactor = 0.5})` Creates a new instance of `AltBaseCirclePainter`. * **radius** (double) - Required - The radius of the circle to be painted. * **blurFactor** (double) - Optional - The radius of the gradient applied to the painted circle. Defaults to 0.5. ### Properties * **`blurFactor`** (double) - The radius of the gradient applied to the painted circle. * **`hashCode`** (int) - The hash code for this object. * **`radius`** (double) - The radius of the circle to be painted. * **`runtimeType`** (Type) - A representation of the runtime type of the object. * **`semanticsBuilder`** (SemanticsBuilderCallback?) - Returns a function that builds semantic information for the picture drawn by this painter. ### Methods * **`addListener(VoidCallback listener)`** - Register a closure to be notified when it is time to repaint. * **`hitTest(Offset position)`** - Called whenever a hit test is being performed on an object that is using this custom paint delegate. * **`noSuchMethod(Invocation invocation)`** - Invoked when a nonexistent method or property is accessed. * **`paint(Canvas canvas, Size size)`** - Called whenever the object needs to paint. The given Canvas has its coordinate space configured such that the origin is at the top left of the box. The area of the box is the size of the `size` argument. * **`removeListener(VoidCallback listener)`** - Remove a previously registered closure from the list of closures that the object notifies when it is time to repaint. * **`shouldRebuildSemantics(covariant CustomPainter oldDelegate)`** - Called whenever a new instance of the custom painter delegate class is provided to the RenderCustomPaint object, or any time that a new CustomPaint object is created with a new instance of the custom painter delegate class. * **`shouldRepaint(covariant AltBaseCirclePainter oldDelegate)`** - Called whenever a new instance of the custom painter delegate class is provided to the RenderCustomPaint object, or any time that a new CustomPaint object is created with a new instance of the custom painter delegate class. * **`toString()`** - A string representation of this object. ### Operators * **`operator ==(Object other)`** - The equality operator. ``` -------------------------------- ### HeatMapPainter Constructor and Paint Method Source: https://pub.dev/documentation/flutter_map_heatmap/latest/flutter_map_heatmap/HeatMapPainter-class Demonstrates the constructor for HeatMapPainter, which takes an Image, and the essential paint method for drawing on a Canvas. The paint method is overridden to handle the actual rendering logic for the heatmap. ```dart class HeatMapPainter extends CustomPainter { final Image heatMapImage; HeatMapPainter(this.heatMapImage); @override void paint(Canvas canvas, Size size) { // Implementation for drawing the heatmap using canvas and size // Example: canvas.drawImage(heatMapImage, Offset.zero, Paint()); } @override bool shouldRepaint(covariant HeatMapPainter oldDelegate) { // TODO: implement shouldRepaint return false; } } ``` -------------------------------- ### HeatMapTilesProvider Constructor - Dart Source: https://pub.dev/documentation/flutter_map_heatmap/latest/flutter_map_heatmap/HeatMapTilesProvider-class Initializes a new instance of the HeatMapTilesProvider. It requires a HeatMapDataSource to fetch data and HeatMapOptions to configure the heatmap's appearance and behavior. ```dart HeatMapTilesProvider.new({ required HeatMapDataSource dataSource, required HeatMapOptions heatMapOptions }) ``` -------------------------------- ### GrayScaleHeatMapPainter Constructor - Dart Source: https://pub.dev/documentation/flutter_map_heatmap/latest/flutter_map_heatmap/GrayScaleHeatMapPainter-class Initializes a GrayScaleHeatMapPainter to create a grayscale heatmap. Requires a base image and a list of data points. Optional parameters include buffer, minOpacity, min, and max for customization. ```dart GrayScaleHeatMapPainter.new({ required Image baseCircle, double buffer = 0, required List data, dynamic minOpacity = 0.5, double? min, double? max }) ``` -------------------------------- ### HeatMapPaint Constructor Source: https://pub.dev/documentation/flutter_map_heatmap/latest/flutter_map_heatmap/HeatMapPaint-class This constructor initializes a new instance of the HeatMapPaint widget. It requires a Key, HeatMapOptions, width, height, and a list of DataPoint objects. The Key is used for widget identification, options configure the heatmap's appearance, dimensions define its size, and data provides the points to be visualized. ```dart HeatMapPaint.new({ Key? key, required HeatMapOptions options, required double width, required double height, required List data }) ``` -------------------------------- ### RGBA32BitmapHeader Constructor and Properties (Dart) Source: https://pub.dev/documentation/flutter_map_heatmap/latest/flutter_map_heatmap/RGBA32BitmapHeader-class Demonstrates the creation of an RGBA32BitmapHeader object and access to its core properties like contentSize, fileLength, and headerIntList. It highlights the getter/setter functionalities for modifiable properties. ```dart import 'dart:typed_data'; class RGBA32BitmapHeader { int contentSize; final int fileLength; Uint8List headerIntList; RGBA32BitmapHeader.new(int contentSize, int width, int height) : this.contentSize = contentSize, this.fileLength = width * height * 4, // Assuming 4 bytes per pixel (RGBA) this.headerIntList = Uint8List(contentSize); // Other methods and properties would go here... } void main() { var header = RGBA32BitmapHeader.new(100, 10, 5); print('Content Size: ${header.contentSize}'); print('File Length: ${header.fileLength}'); print('Header Int List length: ${header.headerIntList.length}'); // Example of setting headerIntList (if needed, though typically managed internally) header.headerIntList = Uint8List(120); print('New Header Int List length: ${header.headerIntList.length}'); } ``` -------------------------------- ### Initialize HeatMapOptions - Dart Source: https://pub.dev/documentation/flutter_map_heatmap/latest/flutter_map_heatmap/HeatMapOptions-class Constructs a HeatMapOptions object to customize heatmap visualization. Accepts parameters for radius, minimum opacity, blur factor, layer opacity, and a custom color gradient. ```dart HeatMapOptions( radius: 20.0, minOpacity: 0.5, blurFactor: 0.8, layerOpacity: 0.9, gradient: { 0.0: Colors.blue, 0.5: Colors.green, 1.0: Colors.red } ) ``` -------------------------------- ### Add Dependencies for flutter_map_heatmap Source: https://pub.dev/documentation/flutter_map_heatmap/latest/index This code snippet shows how to add the necessary dependencies for flutter_map and flutter_map_heatmap to your project's pubspec.yaml file. Ensure you use the latest compatible versions. ```yaml dependencies: flutter_map: ^6.0.0 flutter_map_heatmap: any # or the latest version on Pub latlong2: ^0.9.0 ``` -------------------------------- ### GriddedHeatMapDataSource Constructor - Dart Source: https://pub.dev/documentation/flutter_map_heatmap/latest/flutter_map_heatmap/GriddedHeatMapDataSource-class Initializes a new GriddedHeatMapDataSource with essential data and a radius. Requires a list of WeightedLatLng objects and a double value for the radius. This is the primary way to create an instance of this data source. ```dart GriddedHeatMapDataSource.new({ required List data, required double radius }) ``` -------------------------------- ### HeatMapLayer Constructor Definition and Implementation (Dart) Source: https://pub.dev/documentation/flutter_map_heatmap/latest/flutter_map_heatmap/HeatMapLayer/HeatMapLayer Defines the constructor for the HeatMapLayer widget, specifying its parameters and their default values or requirements. The implementation initializes the widget with provided or default options. ```dart HeatMapLayer({ 1. Key? key, 2. HeatMapOptions? heatMapOptions, 3. required HeatMapDataSource heatMapDataSource, 4. List? initialData, 5. Stream? reset, 6. TileDisplay tileDisplay = const TileDisplay.fadeIn(), 7. double maxZoom = 18.0, }) ## Implementation ``` HeatMapLayer( {super.key, HeatMapOptions? heatMapOptions, required this.heatMapDataSource, List? initialData, this.reset, this.tileDisplay = const TileDisplay.fadeIn(), this.maxZoom = 18.0}) : heatMapOptions = heatMapOptions ?? HeatMapOptions(); ``` ``` -------------------------------- ### DataPoint Class Constructors (Dart) Source: https://pub.dev/documentation/flutter_map_heatmap/latest/flutter_map_heatmap/DataPoint-class This snippet shows the constructors for the DataPoint class in Dart. The `DataPoint.new` constructor takes x, y, and z (intensity) values, while `DataPoint.fromOffset` creates a DataPoint from a Flutter Offset object. ```dart DataPoint.new(double x, double y, double z) DataPoint.fromOffset(Offset offset) ``` -------------------------------- ### Bitmap Constructor: fromHeadless Source: https://pub.dev/documentation/flutter_map_heatmap/latest/flutter_map_heatmap/Bitmap-class Creates a Bitmap object from raw RGBA data without a header. Requires width, height, and the raw byte content. Returns a Bitmap instance. ```dart Bitmap.fromHeadless(int width, int height, Uint8List content) ``` -------------------------------- ### Bitmap Method: buildHeaded Source: https://pub.dev/documentation/flutter_map_heatmap/latest/flutter_map_heatmap/Bitmap-class Builds the Bitmap with its header information. This method processes the raw content and adds the necessary header to create a complete bitmap. Returns a Uint8List representing the headed bitmap. ```dart buildHeaded() → Uint8List ``` -------------------------------- ### HeatMapTilesProvider Methods - Dart Source: https://pub.dev/documentation/flutter_map_heatmap/latest/flutter_map_heatmap/HeatMapTilesProvider-class Provides methods for retrieving heatmap tiles. `getImage` and `getImageWithCancelLoadingSupport` fetch tile images, while `getTileUrl` generates the URL for a tile. `tile2Lat` and `tile2Lon` are utility methods for coordinate conversion. ```dart getImage(TileCoordinates coordinates, TileLayer options) → ImageProvider getImageWithCancelLoadingSupport(TileCoordinates coordinates, TileLayer options, Future cancelLoading) → ImageProvider getTileUrl(TileCoordinates coordinates, TileLayer options) → String tile2Lat(num y, num z) → double tile2Lon(num x, num z) → double ``` -------------------------------- ### RGBA32BitmapHeader applyContent Method (Dart) Source: https://pub.dev/documentation/flutter_map_heatmap/latest/flutter_map_heatmap/RGBA32BitmapHeader-class Illustrates the usage of the applyContent method within the RGBA32BitmapHeader class. This method is designed to populate or update the header's internal data using a provided Uint8List. ```dart import 'dart:typed_data'; class RGBA32BitmapHeader { int contentSize; final int fileLength; Uint8List headerIntList; RGBA32BitmapHeader.new(int contentSize, int width, int height) : this.contentSize = contentSize, this.fileLength = width * height * 4, this.headerIntList = Uint8List(contentSize); void applyContent(Uint8List contentIntList) { if (contentIntList.length > this.contentSize) { throw ArgumentError('Content size exceeds header capacity.'); } this.headerIntList = contentIntList; // Potentially update contentSize if it represents the actual data size rather than capacity // this.contentSize = contentIntList.length; } // Other methods and properties would go here... } void main() { var header = RGBA32BitmapHeader.new(100, 10, 5); var myContent = Uint8List.fromList([1, 2, 3, 4, 5]); header.applyContent(myContent); print('Header Int List after applyContent: ${header.headerIntList}'); // Example of error handling for oversized content try { var tooLargeContent = Uint8List(150); header.applyContent(tooLargeContent); } catch (e) { print('Error: ${e.message}'); } } ``` -------------------------------- ### HeatMapState Constructor - Dart Source: https://pub.dev/documentation/flutter_map_heatmap/latest/flutter_map_heatmap/HeatMapState-class Initializes a new instance of the HeatMapState class with the specified HeatMapOptions. This constructor is essential for creating and configuring a heatmap. ```dart HeatMapState.new(HeatMapOptions options) ``` -------------------------------- ### RGBA32BitmapHeader Constructor Implementation - Dart Source: https://pub.dev/documentation/flutter_map_heatmap/latest/flutter_map_heatmap/RGBA32BitmapHeader/RGBA32BitmapHeader This Dart code implements the RGBA32BitmapHeader constructor. It initializes a Uint8List for the header and uses ByteData to set various fields, including file length, header size, image dimensions, pixel depth, compression method, and color masks for RGBA channels. ```dart RGBA32BitmapHeader(this.contentSize, int width, int height) { headerIntList = Uint8List(fileLength); final ByteData bd = headerIntList.buffer.asByteData(); bd.setUint8(0x0, 0x42); bd.setUint8(0x1, 0x4d); bd.setInt32(0x2, fileLength, Endian.little); bd.setInt32(0xa, rgba32HeaderSize, Endian.little); bd.setUint32(0xe, 108, Endian.little); bd.setUint32(0x12, width, Endian.little); bd.setUint32(0x16, -height, Endian.little); bd.setUint16(0x1a, 1, Endian.little); bd.setUint32(0x1c, 32, Endian.little); // pixel size bd.setUint32(0x1e, 3, Endian.little); //BI_BITFIELDS bd.setUint32(0x22, contentSize, Endian.little); bd.setUint32(0x36, 0x000000ff, Endian.little); bd.setUint32(0x3a, 0x0000ff00, Endian.little); bd.setUint32(0x3e, 0x00ff0000, Endian.little); bd.setUint32(0x42, 0xff000000, Endian.little); } ``` -------------------------------- ### AltBaseCirclePainter Constructor and Properties Source: https://pub.dev/documentation/flutter_map_heatmap/latest/flutter_map_heatmap/AltBaseCirclePainter-class This snippet defines the constructor for AltBaseCirclePainter, allowing initialization with a required radius and an optional blurFactor. It also details the final properties 'radius' and 'blurFactor' which store the dimensions and gradient effect of the circle. ```dart class AltBaseCirclePainter extends CustomPainter { final double radius; final double blurFactor; AltBaseCirclePainter.new({required this.radius, this.blurFactor = 0.5}); // ... other methods and properties } ``` -------------------------------- ### Initialize InMemoryHeatMapDataSource with Data (Dart) Source: https://pub.dev/documentation/flutter_map_heatmap/latest/flutter_map_heatmap/InMemoryHeatMapDataSource-class Constructs an instance of InMemoryHeatMapDataSource, initializing it with a list of WeightedLatLng objects. This is the primary way to populate the data source with heatmap points. ```dart InMemoryHeatMapDataSource.new({ required List data }) ``` -------------------------------- ### HeatMapImage Constructor - Dart Source: https://pub.dev/documentation/flutter_map_heatmap/latest/flutter_map_heatmap/HeatMapImage-class Initializes a HeatMapImage object with data points, heatmap options, and the desired size of the image. This constructor is essential for creating a heatmap image provider. ```dart HeatMapImage.new(List data, HeatMapOptions heatmapOptions, double size) ``` -------------------------------- ### HeatMapTilesProvider Properties - Dart Source: https://pub.dev/documentation/flutter_map_heatmap/latest/flutter_map_heatmap/HeatMapTilesProvider-class Defines the properties of the HeatMapTilesProvider. Key properties include `dataSource` for data, `heatMapOptions` for configuration, and `headers` for custom HTTP headers used in tile requests. ```dart dataSource ↔ HeatMapDataSource griddedData ↔ Map> headers → Map heatMapOptions ↔ HeatMapOptions supportsCancelLoading → bool ``` -------------------------------- ### Implement obtainKey for Synchronous Image Loading Source: https://pub.dev/documentation/flutter_map_heatmap/latest/flutter_map_heatmap/HeatMapImage/obtainKey This implementation of the obtainKey method returns a SynchronousFuture containing the current object. This allows for synchronous image resolution during a frame, improving performance by avoiding delays in image loading. It takes an ImageConfiguration as input and returns a Future resolving to a HeatMapImage. ```dart @override Future obtainKey(ImageConfiguration configuration) { return SynchronousFuture(this); } ``` -------------------------------- ### HeatMapOptions Constructor - Dart Source: https://pub.dev/documentation/flutter_map_heatmap/latest/flutter_map_heatmap/HeatMapOptions/HeatMapOptions Defines the HeatMapOptions constructor for configuring heatmap layers. It initializes properties such as radius, minimum opacity, blur factor, layer opacity, and gradient, applying default values and basic validation. ```dart HeatMapOptions({ this.radius = 30, this.minOpacity = 0.3, double blurFactor = 0.5, double layerOpacity = 0.75, Map? gradient }) : gradient = gradient ?? defaultGradient, layerOpacity = layerOpacity >= 0 && layerOpacity <=1 ? layerOpacity : 0.75, blurFactor = blurFactor >= 0 && blurFactor <=1 ? blurFactor : 0.75; ``` -------------------------------- ### Implement loadImage for Heatmap Image Fetching (Dart) Source: https://pub.dev/documentation/flutter_map_heatmap/latest/flutter_map_heatmap/HeatMapImage/loadImage This snippet shows the implementation of the `loadImage` method, which is responsible for converting a `HeatMapImage` key into an `ImageStreamCompleter`. It utilizes `MultiFrameImageStreamCompleter` to handle image fetching and rendering, with a scale of 1. ```dart @override ImageStreamCompleter loadImage(HeatMapImage key, decode) { return MultiFrameImageStreamCompleter(codec: _generate(), scale: 1); } ``` -------------------------------- ### Bitmap Properties Source: https://pub.dev/documentation/flutter_map_heatmap/latest/flutter_map_heatmap/Bitmap-class Details the properties of the Bitmap class, including its raw content, dimensions, and size. ```APIDOC ## Bitmap Properties ### Description Provides access to the raw data, dimensions, and calculated size of the Bitmap object. ### Properties - **content** (Uint8List) - The raw RGBA data of the bitmap. - **height** (int) - The height of the bitmap. - **size** (int) - The total size of the bitmap data (width * height). - **width** (int) - The width of the bitmap. ``` -------------------------------- ### Implement getImageWithCancelLoadingSupport (Dart) Source: https://pub.dev/documentation/flutter_map_heatmap/latest/flutter_map_heatmap/HeatMapTilesProvider/getImageWithCancelLoadingSupport This is the base implementation of the `getImageWithCancelLoadingSupport` method. It's intended to be overridden by custom `TileProvider` implementations when `supportsCancelLoading` is set to true. If not overridden, it throws an `UnimplementedError`. ```dart ImageProvider getImageWithCancelLoadingSupport( TileCoordinates coordinates, TileLayer options, Future cancelLoading, ) { throw UnimplementedError( 'A `TileProvider` that overrides `supportsCancelLoading` to `true` must ' \ 'override `getImageWithCancelLoadingSupport`', ); } ``` -------------------------------- ### AltBaseCirclePainter paint Method Source: https://pub.dev/documentation/flutter_map_heatmap/latest/flutter_map_heatmap/AltBaseCirclePainter-class The paint method is crucial for custom painters. This snippet shows its signature, indicating it takes a Canvas and Size to perform the drawing operations. The actual drawing logic for the circle would be implemented within this method. ```dart @override void paint(Canvas canvas, Size size) { // TODO: implement paint // Drawing logic for the circle would go here. } ``` -------------------------------- ### Cancel Loading Tiles with dio's CancelToken (Dart) Source: https://pub.dev/documentation/flutter_map_heatmap/latest/flutter_map_heatmap/HeatMapTilesProvider/getImageWithCancelLoadingSupport This snippet demonstrates how to integrate `cancelLoading` with `dio`'s `CancelToken` to cancel in-flight HTTP requests when a tile is disposed. It shows the pattern for associating the `cancelLoading` future with the cancellation token. ```dart final cancelToken = CancelToken(); cancelLoading.then((_) => cancelToken.cancel()); ``` -------------------------------- ### HeatMapState Properties - Dart Source: https://pub.dev/documentation/flutter_map_heatmap/latest/flutter_map_heatmap/HeatMapState-class Details the properties of the HeatMapState class, including hashCode, imageSink, options, and runtimeType. These properties provide access to the heatmap's state and configuration. ```dart hashCode → int imageSink ↔ StreamController? options → HeatMapOptions runtimeType → Type ``` -------------------------------- ### Implement supportsCancelLoading in Flutter Map Source: https://pub.dev/documentation/flutter_map_heatmap/latest/flutter_map_heatmap/HeatMapTilesProvider/supportsCancelLoading This code snippet demonstrates the default implementation of the supportsCancelLoading getter. It indicates that cancelable loading is not supported by default. This property is crucial for web platform performance, allowing tile requests to be canceled if the tile is disposed before loading. ```dart bool get supportsCancelLoading => false; ``` -------------------------------- ### Bitmap Method: buildImage Source: https://pub.dev/documentation/flutter_map_heatmap/latest/flutter_map_heatmap/Bitmap-class Asynchronously builds an Image object from the Bitmap data. This is useful for rendering the bitmap within Flutter UI. Returns a Future. ```dart buildImage() → Future ``` -------------------------------- ### HeatMapOptions Properties - Dart Source: https://pub.dev/documentation/flutter_map_heatmap/latest/flutter_map_heatmap/HeatMapOptions-class Demonstrates setting and accessing properties of the HeatMapOptions class. Properties control visual aspects like point radius, opacity, blur intensity, and color gradients. ```dart final heatmapOptions = HeatMapOptions(); // Set properties heatmapOptions.radius = 25.0; heatmapOptions.layerOpacity = 0.8; heatmapOptions.gradient = { 0.2: Colors.yellow, 0.8: Colors.orange }; // Access properties print(heatmapOptions.radius); print(heatmapOptions.blurFactor); print(heatmapOptions.gradient); ``` -------------------------------- ### HeatMapDataSource Constructors and Properties - Flutter Source: https://pub.dev/documentation/flutter_map_heatmap/latest/flutter_map_heatmap/HeatMapDataSource-class This snippet details the constructors and properties of the `HeatMapDataSource` class. The primary constructor is `HeatMapDataSource.new()`. Key properties include `hashCode` and `runtimeType`, which are inherited and provide standard object introspection capabilities. ```dart // Constructors HeatMapDataSource.new(); // Properties /// The hash code for this object. //@override int get hashCode => super.hashCode; /// A representation of the runtime type of the object. //@override Type get runtimeType => super.runtimeType; ``` -------------------------------- ### Generate Replacement Map for Tile URLs - Dart Source: https://pub.dev/documentation/flutter_map_heatmap/latest/flutter_map_heatmap/HeatMapTilesProvider/generateReplacementMap This Dart method generates a map of string placeholders to their corresponding string replacements, used for populating tile URL templates. It calculates zoom levels, handles TMS coordinate transformations, selects subdomains based on coordinates, and applies retina mode indicators. It also merges custom additional options from the TileLayer. ```dart @visibleForOverriding Map generateReplacementMap( String urlTemplate, TileCoordinates coordinates, TileLayer options, ) { final zoom = (options.zoomOffset + (options.zoomReverse ? options.maxZoom - coordinates.z.toDouble() : coordinates.z.toDouble())) .round(); return { 'x': coordinates.x.toString(), 'y': (options.tms ? ((1 << zoom) - 1) - coordinates.y : coordinates.y) .toString(), 'z': zoom.toString(), 's': options.subdomains.isEmpty ? '' : options.subdomains[ (coordinates.x + coordinates.y) % options.subdomains.length], 'r': options.resolvedRetinaMode == RetinaMode.server ? '@2x' : '', 'd': options.tileSize.toString(), ...options.additionalOptions, }; } ``` -------------------------------- ### BaseCirclePainter Constructor (Dart) Source: https://pub.dev/documentation/flutter_map_heatmap/latest/flutter_map_heatmap/BaseCirclePainter-class Initializes a new instance of the BaseCirclePainter class. It requires a radius and optionally accepts a blurFactor for visual effects. This constructor is part of the Flutter framework's custom painting capabilities. ```dart BaseCirclePainter.new({ required double radius, double? blurFactor }) ``` -------------------------------- ### DataPoint Class Methods (Dart) Source: https://pub.dev/documentation/flutter_map_heatmap/latest/flutter_map_heatmap/DataPoint-class This snippet illustrates the methods available for the DataPoint class in Dart. The `merge` method allows updating the x, y, and intensity of an existing DataPoint. Inherited methods like `noSuchMethod` and `toString` are also noted. ```dart merge(double x, double y, double intensity) → void ``` -------------------------------- ### HeatMapState Methods - Dart Source: https://pub.dev/documentation/flutter_map_heatmap/latest/flutter_map_heatmap/HeatMapState-class Outlines the methods available in the HeatMapState class, such as dispose() and noSuchMethod(). The dispose() method is crucial for releasing resources associated with the heatmap. ```dart dispose() → void noSuchMethod(Invocation invocation) → dynamic tostring() → String ``` -------------------------------- ### WeightedLatLng Constructor with Intensity - Dart Source: https://pub.dev/documentation/flutter_map_heatmap/latest/flutter_map_heatmap/WeightedLatLng-class Initializes a WeightedLatLng object, associating a LatLng with a specific intensity for heatmap data. This is a core component for defining heatmap points. ```dart WeightedLatLng(LatLng latLng, double intensity) ``` -------------------------------- ### HeatMap Method - Generate Heatmap Data - Dart Source: https://pub.dev/documentation/flutter_map_heatmap/latest/flutter_map_heatmap/HeatMap-class Illustrates the `generate()` method of the HeatMap class, which is responsible for processing the heatmap data and returning it as a `Future`. This method is crucial for rendering the heatmap visualization. ```dart Future generate() { // Implementation to generate heatmap image data return Future.value(Uint8List(0)); } ``` -------------------------------- ### HeatMapPaint Properties Source: https://pub.dev/documentation/flutter_map_heatmap/latest/flutter_map_heatmap/HeatMapPaint-class These properties define the state and configuration of the HeatMapPaint widget. 'data' holds the points for the heatmap, 'width' and 'height' specify its dimensions, and 'options' control its visual styling. 'key' is used for widget management within the Flutter tree. ```dart data → List final options → HeatMapOptions final width → double final height → double final ``` -------------------------------- ### Implement getTileFallbackUrl for Fallback Tile URL Generation (Dart) Source: https://pub.dev/documentation/flutter_map_heatmap/latest/flutter_map_heatmap/HeatMapTilesProvider/getTileFallbackUrl This Dart method generates a fallback URL for a map tile using provided coordinates and TileLayer options. It first checks if a fallback URL template is available in the options and then uses `populateTemplatePlaceholders` to substitute placeholders. Ensure that `fallbackUrl` in `TileLayer` is correctly provided. ```dart String? getTileFallbackUrl(TileCoordinates coordinates, TileLayer options) { final urlTemplate = options.fallbackUrl; if (urlTemplate == null) return null; return populateTemplatePlaceholders(urlTemplate, coordinates, options); } ``` -------------------------------- ### Implement Heatmap Painting Logic in Flutter Source: https://pub.dev/documentation/flutter_map_heatmap/latest/flutter_map_heatmap/GrayScaleHeatMapPainter/paint This code implements the `paint` method for a Flutter heatmap. It initializes `min` and `max` values if they are null, sets up a black paint object, and iterates through data points. For each point, it calculates an alpha value based on the point's 'z' value relative to the max intensity and then draws a base circle image on the canvas. The offsets are calculated to center the base circle on the point's coordinates. ```dart @override void paint(Canvas canvas, Size size) { if (min == null || max == null) { min = 0; max = 2; } final paint = Paint()..color = const Color.fromRGBO(0, 0, 0, 1); // offsets for centering the baseCircle when painting final yOffset = baseCircle.height / 2; final xOffset = baseCircle.width / 2; for (final point in data) { final alpha = math.min(math.max(point.z / max!, minOpacity), 1.0); paint.color = Color.fromRGBO(0, 0, 0, alpha); canvas.drawImage( baseCircle, Offset(point.x + buffer - xOffset, point.y + buffer - yOffset), paint); } } ``` -------------------------------- ### Dart: HeatMapDataPoint Constructor and Properties Source: https://pub.dev/documentation/flutter_map_heatmap/latest/flutter_map_heatmap/HeatMapDataPoint-class Defines the HeatMapDataPoint class in Dart, used for creating heatmap data points. It includes a constructor to set x, y coordinates and intensity, and properties to access and modify these values. ```dart class HeatMapDataPoint { double x; double y; double intensity; HeatMapDataPoint(this.x, this.y, {this.intensity = 1}); // Properties are implicitly defined by the constructor parameters and can be accessed directly. // Example: // double get intensity => _intensity; // set intensity(double value) => _intensity = value; } ``` -------------------------------- ### Flutter AltBaseCirclePainter shouldRepaint Implementation Source: https://pub.dev/documentation/flutter_map_heatmap/latest/flutter_map_heatmap/AltBaseCirclePainter/shouldRepaint The `shouldRepaint` method is called when a new painter delegate is provided or a new `CustomPaint` object is created. It returns `true` if the new delegate represents different information than the old one, indicating a repaint is needed. Otherwise, it returns `false`, potentially optimizing away the paint call. The `oldDelegate` is never null. ```dart @override bool shouldRepaint(AltBaseCirclePainter oldDelegate) { return false; } ``` -------------------------------- ### Populate URL Template Placeholders in Dart Source: https://pub.dev/documentation/flutter_map_heatmap/latest/flutter_map_heatmap/HeatMapTilesProvider/populateTemplatePlaceholders This Dart method, populateTemplatePlaceholders, replaces placeholders within a given URL template. It uses a generated replacement map to substitute elements like {x}, {y}, and {z} with their corresponding values based on tile coordinates and layer options. It throws an ArgumentError if a placeholder is found without a corresponding value in the map. This method is intended for internal use by TileProvider subclasses. ```dart @visibleForOverriding String populateTemplatePlaceholders( String urlTemplate, TileCoordinates coordinates, TileLayer options, ) { final replacementMap = generateReplacementMap(urlTemplate, coordinates, options); return urlTemplate.replaceAllMapped( templatePlaceholderElement, (match) { final value = replacementMap[match.group(1)!]; if (value != null) return value; throw ArgumentError( 'Missing value for placeholder: {${match.group(1)}}', ); }, ); } ``` -------------------------------- ### Generate Tile URL in Flutter Source: https://pub.dev/documentation/flutter_map_heatmap/latest/flutter_map_heatmap/HeatMapTilesProvider/getTileUrl This Dart code implements the `getTileUrl` method for generating a primary URL for a map tile based on its coordinates and tile layer options. It prioritizes WMS options for URL generation and falls back to a URL template, throwing an error if neither is available. It also populates template placeholders. ```dart String getTileUrl(TileCoordinates coordinates, TileLayer options) => populateTemplatePlaceholders( options.wmsOptions?.getUrl( coordinates, options.tileSize.toInt(), options.resolvedRetinaMode == RetinaMode.simulation, ) ?? options.urlTemplate ?? (throw ArgumentError( '`wmsOptions` or `urlTemplate` must be provided to generate a tile URL`')), coordinates, options, ); ``` -------------------------------- ### HeatMapImage.loadBuffer Method - Dart Source: https://pub.dev/documentation/flutter_map_heatmap/latest/flutter_map_heatmap/HeatMapImage-class Loads the heatmap image from a buffer. This method is inherited from ImageProvider and is overridden to handle the specific loading of heatmap images. ```dart loadBuffer(HeatMapImage key, DecoderBufferCallback decode) → ImageStreamCompleter ``` -------------------------------- ### Generate Heatmap Image (Dart) Source: https://pub.dev/documentation/flutter_map_heatmap/latest/flutter_map_heatmap/HeatMap/generate The `generate` method creates a heatmap image. It first checks if data is available, returning a transparent image if not. It then generates a base shape for heatmap points, converts the image to grayscale, and finally colorizes it before returning the image bytes. ```dart Future generate() async { await ready.future; // if there is no data then return a transparent image if (data.isEmpty) { return kTransparentImage; } // generate shape to be used for all points on the heatmap final baseShape = await _getBaseShape(); final grayscale = await _grayscaleHeatmap(baseShape); final heatmapBytes = await _colorize(grayscale); return heatmapBytes; } ``` -------------------------------- ### DataPoint Class Properties (Dart) Source: https://pub.dev/documentation/flutter_map_heatmap/latest/flutter_map_heatmap/DataPoint-class This snippet details the properties of the DataPoint class in Dart. It includes getter and setter pairs for the x, y, and z (intensity) coordinates, along with inherited properties like hashCode, runtimeType, and toString. ```dart x ↔ double y ↔ double z ↔ double ``` -------------------------------- ### Paint Heatmap Layer with Radial Gradient (Dart) Source: https://pub.dev/documentation/flutter_map_heatmap/latest/flutter_map_heatmap/AltBaseCirclePainter/paint This Dart code implements the `paint` method for a Flutter custom painter. It draws a circular heatmap layer using a `RadialGradient` centered on the canvas. The gradient transitions from opaque black to transparent black, with the blur factor controlling the spread. Dependencies include `dart:math` for pi and `flutter/painting` for `Canvas`, `Size`, `Rect`, `Offset`, `Paint`, `RadialGradient`, `Path`, and `Colors`. ```dart @override void paint(Canvas canvas, Size size) { final _width = size.width; final _height = size.height; final r2 = radius; final rect = Rect.fromPoints(Offset(_width / 2 - r2, _height / 2 - r2), Offset(_width / 2 + r2, _height / 2 + r2)); var pointPaint = Paint()..color = Colors.black; pointPaint.strokeWidth = 4; final gradient = RadialGradient( colors: const [Color.fromRGBO(0, 0, 0, 1), Color.fromRGBO(0, 0, 0, 0)], stops: const [0, 1], radius: blurFactor) .createShader(rect); canvas.drawPath( Path() ..addArc(rect, 0, math.pi * 2) ..close(), Paint()..shader = gradient); } ``` -------------------------------- ### Bitmap Method: cloneHeadless Source: https://pub.dev/documentation/flutter_map_heatmap/latest/flutter_map_heatmap/Bitmap-class Creates a deep copy of the Bitmap object without its header. This allows for modification of the raw data without affecting the original object. Returns a new Bitmap instance. ```dart cloneHeadless() → Bitmap ``` -------------------------------- ### Drawing Circles with Radial Gradients in Flutter Source: https://pub.dev/documentation/flutter_map_heatmap/latest/flutter_map_heatmap/BaseCirclePainter/paint This code snippet demonstrates how to paint a circle on a Flutter canvas using a radial gradient. It calculates the center and dimensions of the circle based on the canvas size and applies a gradient to the `Paint` object before drawing the circle. Dependencies include the Flutter SDK's rendering and material libraries. ```dart @override void paint(Canvas canvas, Size size) { final _width = size.width; final _height = size.height; var pointPaint = Paint()..color = Colors.green; pointPaint.strokeWidth = 4; final circlePaint = Paint(); final rect = Rect.fromCircle( center: Offset(_width / 2, _height / 2), radius: radius); // create radial gradient final gradient = const RadialGradient( colors: [Color.fromRGBO(0, 0, 0, 1), Color.fromRGBO(0, 0, 0, 0)], stops: [0, 1], radius: 0.5, focalRadius: 0.85) .createShader(rect); circlePaint.shader = gradient; canvas.drawCircle(rect.center, radius, circlePaint); canvas.drawCircle(rect.center, radius, circlePaint); } ``` -------------------------------- ### HeatMapImage.obtainKey Method - Dart Source: https://pub.dev/documentation/flutter_map_heatmap/latest/flutter_map_heatmap/HeatMapImage-class Obtains a unique key for the heatmap image based on its configuration. This is crucial for caching and identification within the image provider system. ```dart obtainKey(ImageConfiguration configuration) → Future ``` -------------------------------- ### HeatMapImage.loadImage Method - Dart Source: https://pub.dev/documentation/flutter_map_heatmap/latest/flutter_map_heatmap/HeatMapImage-class Loads the heatmap image using a decoder callback. This method is overridden to provide custom image loading logic for HeatMapImage. ```dart loadImage(HeatMapImage key, ImageDecoderCallback decode) → ImageStreamCompleter ``` -------------------------------- ### HeatMapDataSource Operators and Inherited Methods - Flutter Source: https://pub.dev/documentation/flutter_map_heatmap/latest/flutter_map_heatmap/HeatMapDataSource-class This section covers the operators and inherited methods available for the `HeatMapDataSource` class. The `operator ==` is defined for equality comparison, and the `noSuchMethod` and `toString` methods are inherited, providing standard Dart object functionalities. ```dart // Operators /// The equality operator. //@override bool operator ==(Object other) => super == other; // Inherited Methods /// Invoked when a nonexistent method or property is accessed. //@override dynamic noSuchMethod(Invocation invocation) => super.noSuchMethod(invocation); /// A string representation of this object. //@override String toString() => super.toString(); ``` -------------------------------- ### AltBaseCirclePainter shouldRepaint Method Source: https://pub.dev/documentation/flutter_map_heatmap/latest/flutter_map_heatmap/AltBaseCirclePainter-class The shouldRepaint method is called by the framework to determine if the custom painter needs to repaint. This snippet shows its signature and override annotation. The implementation should return true if the painter's configuration has changed and a repaint is necessary. ```dart @override bool shouldRepaint(covariant AltBaseCirclePainter oldDelegate) { // TODO: implement shouldRepaint // Return true if properties like radius or blurFactor have changed. return radius != oldDelegate.radius || blurFactor != oldDelegate.blurFactor; } ``` -------------------------------- ### Implement getImage to Retrieve Tile Image - Dart Source: https://pub.dev/documentation/flutter_map_heatmap/latest/flutter_map_heatmap/HeatMapTilesProvider/getImage This Dart implementation of the getImage method retrieves a tile as an image using provided coordinates and TileLayer options. It filters data points based on the zoom level, calculates the radius, and returns a HeatMapImage instance. It does not support canceling tile loading. ```dart @override ImageProvider getImage(TileCoordinates coordinates, TileLayer options) { var tileSize = options.tileSize; // disable zoom level 0 for now. ned to refactor _filterData List filteredData = coordinates.z != 0 ? _filterData(coordinates, options) : []; var scale = coordinates.z / 22 * 1.22; final radius = heatMapOptions.radius * scale; var imageHMOptions = HeatMapOptions( radius: radius, minOpacity: heatMapOptions.minOpacity, gradient: heatMapOptions.gradient, ); return HeatMapImage(filteredData, imageHMOptions, tileSize); } ``` -------------------------------- ### shouldRepaint Method Implementation - Dart Source: https://pub.dev/documentation/flutter_map_heatmap/latest/flutter_map_heatmap/GrayScaleHeatMapPainter/shouldRepaint The `shouldRepaint` method is an override that determines if the custom painter needs to repaint. It compares the `data` property of the current painter with the `data` of the `oldDelegate`. If they differ, it returns `true`, indicating a repaint is required; otherwise, it returns `false`. ```dart @override bool shouldRepaint(GrayScaleHeatMapPainter oldDelegate) { return oldDelegate.data != data; } ``` -------------------------------- ### HeatMapPaint Methods - createState Source: https://pub.dev/documentation/flutter_map_heatmap/latest/flutter_map_heatmap/HeatMapPaint-class The createState() method is an essential part of a StatefulWidget. It is responsible for creating the mutable state object associated with this widget. The returned state object, typically a subclass of State, will hold the mutable state for the widget and is where the build() method resides. ```dart createState() → _HeatMapPaintState override ``` -------------------------------- ### Flutter HeatMapPainter shouldRepaint Implementation Source: https://pub.dev/documentation/flutter_map_heatmap/latest/flutter_map_heatmap/HeatMapPainter/shouldRepaint This snippet shows the implementation of the `shouldRepaint` method for a `HeatMapPainter` in Flutter. This method is called when the custom painter delegate is updated, and it returns `true` to indicate that a repaint is required, ensuring the heatmap is redrawn with new information. The `oldDelegate` parameter provides access to the previous delegate's state for comparison. ```dart @override bool shouldRepaint(HeatMapPainter oldDelegate) { return true; } ``` -------------------------------- ### GrayScaleHeatMapPainter.shouldRepaint Method - Dart Source: https://pub.dev/documentation/flutter_map_heatmap/latest/flutter_map_heatmap/GrayScaleHeatMapPainter-class Determines whether the painter should repaint. This method is called when a new instance of the painter is provided. It compares the current painter with the old one to optimize rendering by avoiding unnecessary repaints. ```dart @override bool shouldRepaint(covariant GrayScaleHeatMapPainter oldDelegate) ``` -------------------------------- ### Implement shouldRepaint in Flutter Custom Painter Source: https://pub.dev/documentation/flutter_map_heatmap/latest/flutter_map_heatmap/BaseCirclePainter/shouldRepaint The `shouldRepaint` method is called by Flutter to determine if a custom painter needs to redraw. It compares the current painter's delegate with the old one. Returning `true` indicates a repaint is needed, while `false` may allow for optimization. The `oldDelegate` is never null. ```dart @override bool shouldRepaint(BaseCirclePainter oldDelegate) { return false; } ``` -------------------------------- ### Implement hashCode for Object State - Dart Source: https://pub.dev/documentation/flutter_map_heatmap/latest/flutter_map_heatmap/HeatMapDataPoint/hashCode This snippet demonstrates how to implement the hashCode property in Dart. It overrides the default hash code to reflect the object's state, ensuring consistency with the operator ==. This is crucial for using objects in hash-based collections like Sets and Maps. ```dart @override int get hashCode => Object.hash(x, y, intensity); ``` -------------------------------- ### Paint Image on Canvas - Flutter Dart Source: https://pub.dev/documentation/flutter_map_heatmap/latest/flutter_map_heatmap/HeatMapPainter/paint This method demonstrates how to paint an image onto a Canvas in Flutter. It utilizes a Paint object and the Canvas.drawImage method to render the heatmap image at the origin (0,0). Ensure the heatmap image is properly loaded before calling this method. ```dart @override void paint(Canvas canvas, Size size) { final paint = Paint(); canvas.drawImage(heatMapImage, const Offset(0, 0), paint); } ``` -------------------------------- ### BaseCirclePainter.paint Method (Dart) Source: https://pub.dev/documentation/flutter_map_heatmap/latest/flutter_map_heatmap/BaseCirclePainter-class Implements the painting logic for the BaseCirclePainter. This method is overridden from the CustomPainter class and is called by the Flutter rendering engine to draw the circle on the provided Canvas. It utilizes the object's radius and blurFactor properties. ```dart @override void paint(Canvas canvas, Size size) { // Implementation to draw a circle with blur on the canvas } ``` -------------------------------- ### BaseCirclePainter.shouldRepaint Method (Dart) Source: https://pub.dev/documentation/flutter_map_heatmap/latest/flutter_map_heatmap/BaseCirclePainter-class Determines whether the custom painter should repaint. This method is crucial for performance optimization in Flutter. It compares the current painter's properties with the old painter's properties to decide if a repaint is necessary. ```dart @override bool shouldRepaint(covariant BaseCirclePainter oldDelegate) { // Compare properties like radius and blurFactor to determine if repaint is needed return radius != oldDelegate.radius || blurFactor != oldDelegate.blurFactor; } ``` -------------------------------- ### GrayScaleHeatMapPainter.paint Method - Dart Source: https://pub.dev/documentation/flutter_map_heatmap/latest/flutter_map_heatmap/GrayScaleHeatMapPainter-class Paints the grayscale heatmap onto the provided Canvas. This method is called by the Flutter framework whenever the painter needs to redraw. It uses the 'canvas' and 'size' arguments to render the visual representation based on the painter's properties. ```dart @override void paint(Canvas canvas, Size size) ```