network static method

Widget network(
  1. String url, {
  2. Client? client,
  3. Map<String, String>? headers,
  4. List<int> statusCodes = const <int>[200],
  5. Widget builder(
    1. BuildContext context,
    2. MarkerProperties markerProperties,
    3. Map<String, dynamic>? map
    )?,
  6. required MarkerProperties markerProperties,
  7. MapController? mapController,
  8. Key? key,
  9. Widget fallback(
    1. int? statusCode
    )?,
  10. PowerMarkerClusterOptions? powerClusterOptions,
})

Fetches and renders markers from a network source using GeoJSON data.

The network method fetches GeoJSON data from the specified url and renders markers on the map based on the GeoJSON feature collection. You can customize the appearance of the markers using markerProperties and provide a custom marker builder function builder.

Example Usage:

// Fetch and render markers from a network source
Widget networkMarkers = PowerGeoJSONMarkers.network(
  'https://example.com/markers.geojson',
  markerProperties: MarkerProperties(height: 48, width: 48),
  builder: (context, markerProperties, properties) {
    // Custom marker builder logic
    return MyCustomMarkerWidget(markerProperties: markerProperties, data: properties);
  },
  mapController: myMapController,
  key: UniqueKey(),
);

Parameters:

  • url: The URL of the GeoJSON data source.
  • client: (Optional) A custom HTTP client for making the network request.
  • headers: (Optional) Additional HTTP headers for the network request.
  • builder: (Optional) A custom marker builder function that takes context, marker properties, and properties map as arguments.
  • markerProperties: The properties to customize the appearance of the markers.
  • mapController: (Optional) The map controller used to adjust the map view based on marker bounds.
  • key: (Optional) A unique key for the widget.

Returns a Widget representing the fetched and rendered markers.

Implementation

static Widget network(
  String url, {
  Client? client,
  Map<String, String>? headers,
  List<int> statusCodes = const <int>[200],
  Widget Function(
    BuildContext context,
    MarkerProperties markerProperties,
    Map<String, dynamic>? map,
  )?
  builder,
  required MarkerProperties markerProperties,
  MapController? mapController,
  Key? key,
  Widget Function(int? statusCode)? fallback,
  PowerMarkerClusterOptions? powerClusterOptions,
}) {
  Uri uriString = url.toUri();
  return EnhancedFutureBuilder<Widget>(
    future: _networkMarkers(
      uriString,
      powerClusterOptions: powerClusterOptions,
      headers: headers,
      client: client,
      statusCodes: statusCodes,
      markerLayerProperties: markerProperties,
      builder: builder,
      mapController: mapController,
      fallback: fallback,
      key: key,
    ),
    rememberFutureResult: true,
    whenDone: (Widget snapshotData) => snapshotData,
    whenNotDone: const Center(child: CupertinoActivityIndicator()),
  );
}