### Basic TileLayer Setup Source: https://docs.fleaflet.dev/layers/tile-layer.md This is a basic example of how to set up a TileLayer with a URL template for fetching map tiles. Ensure you replace the placeholder with your app's identifier. ```dart TileLayer( urlTemplate: 'https://tile.openstreetmap.org/{z}/{x}/{y}.png', userAgentPackageName: /*'com.example.app'*/, // Add your app identifier // + many other options ) ``` -------------------------------- ### Query Documentation with GET Request Source: https://docs.fleaflet.dev/layers/polygon-layer.md Use this HTTP GET request to query the documentation dynamically. Include your specific question in the 'ask' query parameter to receive a direct answer and relevant excerpts. ```http GET https://docs.fleaflet.dev/layers/polygon-layer.md?ask= ``` -------------------------------- ### Query Documentation via HTTP GET Source: https://docs.fleaflet.dev/getting-started/installation.md To get more information not present on the current page, make an HTTP GET request to the page URL with the 'ask' query parameter. The question should be specific and in natural language. ```bash GET https://docs.fleaflet.dev/getting-started/installation.md?ask= ``` -------------------------------- ### Query Documentation Dynamically Source: https://docs.fleaflet.dev/thanks/supporters.md Use this GET request to ask questions about the documentation. The response will include direct answers and relevant excerpts. ```http GET https://docs.fleaflet.dev/thanks/supporters.md?ask= ``` -------------------------------- ### Query Documentation with GET Request Source: https://docs.fleaflet.dev/readme.md Use this method to ask questions about the documentation. The response includes direct answers and relevant excerpts. ```http GET https://docs.fleaflet.dev/readme.md?ask= ``` -------------------------------- ### Query Documentation with GET Request Source: https://docs.fleaflet.dev/layers/polyline-layer.md To get additional information not directly available on a page, perform an HTTP GET request to the page URL with the `ask` query parameter. The question should be specific and self-contained. ```http GET https://docs.fleaflet.dev/layers/polyline-layer.md?ask= ``` -------------------------------- ### Basic Polygon Layer Example Source: https://docs.fleaflet.dev/layers/polygon-layer.md Demonstrates how to create a simple PolygonLayer with a single Polygon. Ensure LatLng is imported. ```dart PolygonLayer( polygons: [ Polygon( points: [LatLng(30, 40), LatLng(20, 50), LatLng(25, 45)], color: Colors.blue, ), ], ), ``` -------------------------------- ### Query Documentation Dynamically Source: https://docs.fleaflet.dev/getting-started/new-in-v8.md Perform an HTTP GET request to query the documentation dynamically. The question should be specific and self-contained. ```bash GET https://docs.fleaflet.dev/getting-started/new-in-v8.md?ask= ``` -------------------------------- ### Query Documentation with HTTP GET Source: https://docs.fleaflet.dev/plugins Use this method to ask specific questions about the documentation. The response includes a direct answer and relevant excerpts. ```http GET https://docs.fleaflet.dev/plugins.md?ask= ``` -------------------------------- ### Using a Custom MapCachingProvider Source: https://docs.fleaflet.dev/layers/tile-layer/caching.md Example of initializing a TileLayer with a custom caching provider. Ensure the custom provider is correctly implemented and imported. ```dart TileLayer( urlTemplate: '...', userAgentPackageName: '...', tileProvider: NetworkTileProvider( cachingProvider: CustomMapCachingProvider(), ), ); ``` -------------------------------- ### Querying Documentation Dynamically Source: https://docs.fleaflet.dev/tile-servers/offline-mapping.md Perform an HTTP GET request to the current page URL with the 'ask' query parameter to ask questions about the documentation. The question should be specific and self-contained. ```http GET https://docs.fleaflet.dev/tile-servers/offline-mapping.md?ask= ``` -------------------------------- ### Query Documentation via HTTP GET Source: https://docs.fleaflet.dev/layers/layer-interactivity.md Use this method to ask specific questions about the documentation. The response includes direct answers and relevant excerpts. ```http GET https://docs.fleaflet.dev/layers/layer-interactivity.md?ask= ``` -------------------------------- ### Basic PolylineLayer Example Source: https://docs.fleaflet.dev/layers/polyline-layer.md This snippet shows how to create a PolylineLayer with a single Polyline. Ensure LatLng and Colors are imported. ```dart PolylineLayer( polylines: [ Polyline( points: [LatLng(30, 40), LatLng(20, 50), LatLng(25, 45)], color: Colors.blue, ), ], ), ``` -------------------------------- ### Querying Documentation Dynamically Source: https://docs.fleaflet.dev/plugins/create.md To get additional information not explicitly present on a page, you can query the documentation dynamically. Perform an HTTP GET request to the page URL with the 'ask' query parameter. ```http GET https://docs.fleaflet.dev/plugins/create.md?ask= ``` -------------------------------- ### Decode and Unpack Polyline Example Source: https://docs.fleaflet.dev/layers/polyline-layer.md Example of how to use the decodePolyline function and the unpackPolyline extension to get a List from an encoded polyline string. ```dart import 'unpack_polyline.dart'; decodePolyline('').unpackPolyline(); // Returns `List` for a map polyline ``` -------------------------------- ### Query Documentation with GET Request Source: https://docs.fleaflet.dev/layers/tile-layer/caching.md Use this method to ask specific questions about the documentation when the answer is not explicitly present. The question should be self-contained and in natural language. ```http GET https://docs.fleaflet.dev/layers/tile-layer/caching.md?ask= ``` -------------------------------- ### SimpleAttributionWidget Example Source: https://docs.fleaflet.dev/layers/attribution-layer.md Use SimpleAttributionWidget for a classic attribution box, similar to web maps. This example displays 'OpenStreetMap contributors' as the source. ```dart children: [ SimpleAttributionWidget( source: Text('OpenStreetMap contributors'), ), ], ``` -------------------------------- ### Querying Documentation API Source: https://docs.fleaflet.dev/plugins/create/layers.md To get information not directly on the page, make a GET request to the page URL with an 'ask' query parameter. The question should be specific and in natural language. ```http GET https://docs.fleaflet.dev/plugins/create/layers.md?ask= ``` -------------------------------- ### Query Documentation Dynamically Source: https://docs.fleaflet.dev/tile-servers/using-openstreetmap-direct.md Perform an HTTP GET request on the current page URL with the `ask` query parameter to retrieve dynamic information. The question should be specific and self-contained. ```http GET https://docs.fleaflet.dev/tile-servers/using-openstreetmap-direct.md?ask= ``` -------------------------------- ### Querying Documentation Source: https://docs.fleaflet.dev/tile-servers/using-google-maps.md You can query this documentation dynamically by asking a question. Perform an HTTP GET request on the current page URL with the 'ask' query parameter. ```http GET https://docs.fleaflet.dev/tile-servers/using-google-maps.md?ask= ``` -------------------------------- ### RichAttributionWidget Example Source: https://docs.fleaflet.dev/layers/attribution-layer.md Use RichAttributionWidget to display attributions with logos and text. This example shows how to include a TextSourceAttribution for OpenStreetMap contributors. ```dart children: [ RichAttributionWidget( attributions: [ // Suggested attribution for the OpenStreetMap public tile server TextSourceAttribution( 'OpenStreetMap contributors', onTap: () => launchUrl(Uri.parse('https://openstreetmap.org/copyright')), ), ], ), ], ``` -------------------------------- ### Proj4 Definition String Example Source: https://docs.fleaflet.dev/usage/options/custom-crss.md An example of a Proj4 definition string for EPSG:3413, used to define a custom projection. ```dart +proj=stere +lat_0=90 +lat_ts=70 +lon_0=-45 +k=1 +x_0=0 +y_0=0 +datum=WGS84 +units=m +no_defs ``` -------------------------------- ### Stadia Maps Static Map URL Example Source: https://docs.fleaflet.dev/tile-servers/using-stadia-maps-1.md Example of a Stadia Maps static map URL for a specific style. Ensure to replace placeholders with your actual API key and desired style. ```text https://tiles.stadiamaps.com/tiles/stamen_toner/{z}/{x}/{y}{r}.png?api_key=YOUR_API_KEY ``` -------------------------------- ### Query Documentation with HTTP GET Source: https://docs.fleaflet.dev/getting-started Use this method to ask questions about the documentation when the answer is not explicitly present on the current page. The response includes a direct answer and relevant excerpts. ```http GET https://docs.fleaflet.dev/getting-started.md?ask= ``` -------------------------------- ### Stadia Maps Retina Tile URL Example Source: https://docs.fleaflet.dev/tile-servers/using-stadia-maps-1.md Example of a Stadia Maps URL for retina (high-DPI) tiles. Use URLs containing '@2x' for higher resolution map displays. ```text https://tiles.stadiamaps.com/tiles/stamen_toner_retina/{z}/{x}/{y}{r}.png?api_key=YOUR_API_KEY ``` -------------------------------- ### Query Documentation via HTTP GET Source: https://docs.fleaflet.dev/usage/options/custom-crss.md Use this method to ask questions about the documentation when the answer is not explicitly present on the page. The question should be specific and in natural language. ```http GET https://docs.fleaflet.dev/usage/options/custom-crss.md?ask= ``` -------------------------------- ### Query Documentation with HTTP GET Source: https://docs.fleaflet.dev/why-and-how Use this method to ask specific questions about the documentation when the answer is not explicitly present on the page. The question should be self-contained and in natural language. ```http GET https://docs.fleaflet.dev/why-and-how.md?ask= ``` -------------------------------- ### Create Proj4Crs from Factory Source: https://docs.fleaflet.dev/usage/options/custom-crss.md Example of creating a Proj4Crs object using the fromFactory constructor, specifying projection, resolutions, bounds, and origins. ```dart var epsg3413 = proj4.Projection.add('EPSG:3413', '+proj=stere +lat_0=90 +lat_ts=70 +lon_0=-45 +k=1 +x_0=0 +y_0=0 +datum=WGS84 +units=m +no_defs'); final resolutions = [ 32768, 16384, 8192, 4096, 2048, 1024, 512, 256, 128, ]; final epsg3413Bounds = Bounds( Point(-4511619.0, -4511336.0), Point(4510883.0, 4510996.0), ); var maxZoom = (resolutions.length - 1).toDouble(); var epsg3413CRS = Proj4Crs.fromFactory( code: 'EPSG:3413', proj4Projection: epsg3413, resolutions: resolutions, bounds: epsg3413Bounds, origins: [Point(0, 0)], scales: null, transformation: null, ); ``` -------------------------------- ### Query Documentation via HTTP GET Source: https://docs.fleaflet.dev/thanks Use this method to ask questions about the documentation when the answer is not explicitly present on the page. The response includes a direct answer, relevant excerpts, and sources. ```HTTP GET https://docs.fleaflet.dev/thanks.md?ask= ``` -------------------------------- ### Ask a Question via Documentation API Source: https://docs.fleaflet.dev/llms.txt Use this GET request to query the documentation index with a natural language question. The response includes a direct answer and relevant excerpts. ```http GET https://docs.fleaflet.dev/plugins/list.md?ask= ``` -------------------------------- ### Basic Flutter Map Setup Source: https://docs.fleaflet.dev/readme.md This snippet shows how to set up a basic Flutter Map with a center, zoom level, tile layer, and attribution. Ensure you replace the user agent package name with your app's identifier and be mindful of the OpenStreetMap tile server usage policy. ```dart import 'package:flutter_map/flutter_map.dart'; import 'package:latlong2/latlong.dart'; @override Widget build(BuildContext context) { return FlutterMap( options: MapOptions( initialCenter: LatLng(51.509364, -0.128928), // Center the map over London, UK initialZoom: 9.2, ), children: [ TileLayer( // Bring your own tiles urlTemplate: 'https://tile.openstreetmap.org/{z}/{x}/{y}.png', // For demonstration only userAgentPackageName: /*'com.example.app'*/, // And many more recommended properties! ), RichAttributionWidget( // Include a stylish prebuilt attribution widget that meets all requirments attributions: [ TextSourceAttribution( 'OpenStreetMap contributors', onTap: () => launchUrl(Uri.parse('https://openstreetmap.org/copyright')), // (external) ), // Also add images... ], ), ], ); } ``` -------------------------------- ### Basic Flutter Map Setup with Raster Tiles Source: https://docs.fleaflet.dev/ This snippet demonstrates how to set up a simple Flutter map using raster tiles from OpenStreetMap. Ensure you replace the userAgentPackageName with your app's identifier. Note that the OpenStreetMap tile servers are not free for all uses. ```dart import 'package:flutter_map/flutter_map.dart'; import 'package:latlong2/latlong.dart'; @override Widget build(BuildContext context) { return FlutterMap( options: MapOptions( initialCenter: LatLng(51.509364, -0.128928), // Center the map over London, UK initialZoom: 9.2, ), children: [ TileLayer( // Bring your own tiles urlTemplate: 'https://tile.openstreetmap.org/{z}/{x}/{y}.png', // For demonstration only userAgentPackageName: /*'com.example.app'*/, // Add your app identifier // And many more recommended properties! ), RichAttributionWidget( // Include a stylish prebuilt attribution widget that meets all requirments attributions: [ TextSourceAttribution( 'OpenStreetMap contributors', onTap: () => launchUrl(Uri.parse('https://openstreetmap.org/copyright')), // (external) ), // Also add images... ], ), ], ); } ``` -------------------------------- ### Query Documentation Dynamically Source: https://docs.fleaflet.dev/layers Use this method to ask questions about the documentation. The response includes direct answers and relevant excerpts. ```http GET https://docs.fleaflet.dev/layers.md?ask= ``` -------------------------------- ### Using FileTileProvider for Filesystem Maps Source: https://docs.fleaflet.dev/layers/tile-layer.md Configure `FileTileProvider` and set the `urlTemplate` to the path of tiles on the filesystem. Ensure the app has necessary read permissions. ```dart TileLayer( tileProvider: FileTileProvider(), urlTemplate: '/path/to/your/tiles/{z}/{x}/{y}.png', ) ``` -------------------------------- ### Configuring WMSTileLayerOptions Source: https://docs.fleaflet.dev/layers/tile-layer.md Create a `WMSTileLayerOptions` object, defining the `baseUrl` and a list of `layers` to fetch WMS tiles. Refer to the full API documentation for other options. ```dart WMSTileLayerOptions( baseUrl: 'https://tileserver.example.com/wms/', layers: ['layer1', 'layer2'], ) ``` -------------------------------- ### Extend TileProvider Class Source: https://docs.fleaflet.dev/plugins/create/tile-providers.md Create a custom TileProvider by extending the abstract class and initializing its constructor with super.headers. ```dart class CustomTileProvider extends TileProvider { CustomTileProvider({ // Suitably initialise your own custom properties super.headers, // Accept a `Map` of custom HTTP headers }) } ``` -------------------------------- ### Disabling Built-in Caching Source: https://docs.fleaflet.dev/layers/tile-layer/caching.md Example of disabling the default caching for a TileLayer by using DisabledMapCachingProvider. This is not needed for web platforms. Always check tile server terms of service before disabling. ```dart TileLayer( urlTemplate: '...', userAgentPackageName: '...', tileProvider: NetworkTileProvider( cachingProvider: const DisabledMapCachingProvider(), ), ); ``` -------------------------------- ### Implement Tile Retrieval without Cancel Loading Support Source: https://docs.fleaflet.dev/plugins/create/tile-providers.md Override `getImage` to provide an ImageProvider for tiles when cancel loading support is not required or available. ```dart @override ImageProvider getImage(TileCoordinates coordinates, TileLayer options) => CustomImageProvider( url: getTileUrl(coordinates, options), fallbackUrl: getTileFallbackUrl(coordinates, options), tileProvider: this, ); ``` -------------------------------- ### Accessing Camera and Controller within a Map Layer Source: https://docs.fleaflet.dev/usage/programmatic-interaction.md Use `MapCamera.of(context)` and `MapController.of(context)` within a map layer to get the current camera and controller. This automatically subscribes the widget to updates, causing it to rebuild when the camera changes. ```dart return FlutterMap( // ... children: [ Builder( builder: (context) { // This is a map layer final camera = MapCamera.of(context); final controller = MapController.of(context); // This will automatically update to display the current zoom level return Text(camera.zoom.toString()); }, ), ], ); ``` -------------------------------- ### Import Proj4dart Library Source: https://docs.fleaflet.dev/usage/options/custom-crss.md Import the proj4dart library to define custom projections. ```dart import 'package:proj4dart/proj4dart.dart' as proj4; ``` -------------------------------- ### Basic Overlay Image Source: https://docs.fleaflet.dev/layers/overlay-image-layer.md Use `OverlayImageLayer` with `OverlayImage` to display an unrotated image on the map. Provide the image bounds and a valid `ImageProvider`. ```dart OverlayImageLayer( overlayImages: [ OverlayImage( // Unrotated bounds: LatLngBounds( LatLng(45.3367881884556, 14.159452282322459), LatLng(45.264129635422826, 14.252585831779033), ), imageProvider: NetworkImage(), ), ], ), ``` -------------------------------- ### Implement Tile Retrieval with Cancel Loading Support Source: https://docs.fleaflet.dev/plugins/create/tile-providers.md Override `getImageWithCancelLoadingSupport` to provide an ImageProvider that can cancel tile loading. Listen to the `cancelLoading` future to trigger cancellation. ```dart @override bool get supportsCancelLoading => true; @override ImageProvider getImageWithCancelLoadingSupport( TileCoordinates coordinates, TileLayer options, Future cancelLoading, ) => CustomCancellableImageProvider( url: getTileUrl(coordinates, options), fallbackUrl: getTileFallbackUrl(coordinates, options), cancelLoading: cancelLoading, tileProvider: this, ); ``` -------------------------------- ### TileLayer with Fallback URL Source: https://docs.fleaflet.dev/layers/tile-layer.md This snippet demonstrates how to configure a fallback URL template for a TileLayer. This is used if fetching a tile from the primary URL template fails. Use fallback URLs sparingly as they can impact performance. ```dart TileLayer( urlTemplate: 'https://tile.openstreetmap.org/{z}/{x}/{y}.png', fallbackUrl: 'https://tile.openstreetmap.org/{z}/{x}/{y}.png', // Example fallback URL userAgentPackageName: 'com.example.app', ) ``` -------------------------------- ### Using onMapReady to Ensure Controller is Ready Source: https://docs.fleaflet.dev/usage/programmatic-interaction.md Use `MapOptions.onMapReady` to hook into the event when the controller is attached to the map. This ensures the controller is safe to use for map manipulation. Avoid using controller methods directly in `onMapReady`; configure initial map position in `MapOptions` instead. ```dart final _mapControllerReady = Completer(); return FlutterMap( mapController: _mapController, options: MapOptions( onMapReady: () { // `_mapController` safe to use _mapControllerReady.complete(); }, ), ); ``` -------------------------------- ### Set User-Agent for Tile Servers Source: https://docs.fleaflet.dev/layers/tile-layer.md Identify your app to tile servers using the HTTP 'User-Agent' header. Set the `userAgentPackageName` parameter to your app's package name or another unique identifier. ```dart TileLayer( urlTemplate: 'https://tile.openstreetmap.org/{z}/{x}/{y}.png', userAgentPackageName: 'com.example.app', ) ``` -------------------------------- ### Configure Built-in Cache Provider Source: https://docs.fleaflet.dev/layers/tile-layer/caching.md Configure the BuiltInMapCachingProvider by providing arguments to its getOrCreateInstance factory constructor. This is typically done when constructing the TileLayer or TileProvider. ```dart TileLayer( urlTemplate: '...', userAgentPackageName: '...', tileProvider: NetworkTileProvider( cachingProvider: BuiltInMapCachingProvider.getOrCreateInstance( maxCacheSize: 1_000_000_000, // 1 GB is the default ), ), ); ``` -------------------------------- ### Implement Custom Caching Provider Source: https://docs.fleaflet.dev/plugins/create/caching-providers.md Implement the MapCachingProvider interface to create a custom caching solution. Ensure your implementation provides logic for isSupported, getTile, and putTile. ```dart class CustomCachingProvider implements MapCachingProvider { @override bool get isSupported => throw UnimplementedError(); @override Future<({Uint8List bytes, CachedMapTileMetadata metadata})?> getTile( String url, ) { throw UnimplementedError(); } @override Future putTile({ required String url, required CachedMapTileMetadata metadata, Uint8List? bytes, }) { throw UnimplementedError(); } } ``` -------------------------------- ### Enabling TMS for TileLayer Source: https://docs.fleaflet.dev/layers/tile-layer.md To use TMS tile servers, follow the instructions for XYZ sources and enable the `TileLayer.tms` setting. ```dart TileLayer( urlTemplate: 'https://tileserver.example.com/tms/{z}/{x}/{y}.png', tms: true, ) ``` -------------------------------- ### Configuring TileDimension for Larger Tiles Source: https://docs.fleaflet.dev/layers/tile-layer.md Set `tileDimension` to the actual tile size (e.g., 512) and adjust `zoomOffset` to ensure correct tile placement. The `{d}` placeholder can also be used in the URL. ```dart TileLayer( urlTemplate: 'https://tile.openstreetmap.org/{z}/{x}/{y}.png', tileDimension: 512, zoomOffset: -1, ) ``` -------------------------------- ### Enable Network Client Entitlement for macOS Source: https://docs.fleaflet.dev/getting-started/installation.md Add the com.apple.security.network.client entitlement to your macOS app's Release.entitlements file to allow network connections. ```xml ... ... com.apple.security.network.client ... ... ``` -------------------------------- ### Using AssetTileProvider for Offline Maps Source: https://docs.fleaflet.dev/layers/tile-layer.md Configure `AssetTileProvider` and set the `urlTemplate` to the path of tiles within the app's assets directory. Ensure assets are listed in `pubspec.yaml`. ```dart TileLayer( tileProvider: AssetTileProvider(), urlTemplate: 'assets/map/{z}/{x}/{y}.png', ) ``` -------------------------------- ### Enable Internet Permission for Android Source: https://docs.fleaflet.dev/getting-started/installation.md Add the INTERNET permission to your AndroidManifest.xml to allow network access for tile loading. ```xml ... ... ``` -------------------------------- ### Handling Simple Map Events Source: https://docs.fleaflet.dev/usage/programmatic-interaction.md Use callbacks like onTap and onPositionChanged within MapOptions to react to user interactions and map movements. The onTap callback provides screen and coordinate information, while onPositionChanged provides camera details and a flag indicating user gesture. ```dart return FlutterMap( options: MapOptions( // ... onTap: (tapPosition, point) { final screenTapped = tapPosition.global; final coordinatesTapped = point; }, onPositionChanged: (camera, hasGesture) { if (hasGesture) { disableUserLocationFollow(); } print(camera.center); }, ), // ... ); ``` -------------------------------- ### Setting User-Agent for TileLayer Source: https://docs.fleaflet.dev/tile-servers/using-openstreetmap-direct.md This snippet demonstrates how to set a specific user-agent for the TileLayer, which is a requirement of the OpenStreetMap Tile Usage Policy. This helps identify your client and is crucial for compliance. Note that this is not applicable when running solely on the web. ```javascript const tileLayer = new TileLayer({ // ... other options userAgentPackageName: 'your-package-name' }); ```