flutter_map_geojson 1.0.1 copy "flutter_map_geojson: ^1.0.1" to clipboard
flutter_map_geojson: ^1.0.1 copied to clipboard

This package parses GeoJson formatted spatial data. It prepares three lists of objects defined in flutter_map package - Markers, Polylines and Polygons. These object are created by default callbacks w [...]

GeoJson is becoming defacto standard for retrieving spatial data like points, lines and polygons. GeoJson Format specification is defined in RFC7964 - see https://www.rfc-editor.org/rfc/rfc7946 This package parses GeoJson data and creates spatial objects like [Marker]s, [Polyline]s and [Polygon]s, which are defined in [flutter_map] package.

The ceration of these objects is done by default callback functions. However, one can and probably should write his own callback functions which are implementing the necessary customization of creating spatial objects by specifying the color, stroke, label text and other parameters.

Features #

The GeoJson parser creates three lists of spatial objects - separate lists of [Marker]s, [Polyline]s and [Polygon]s which are input parameters for creating layers in flutter_map. The parser supports parsing the following geometries:

  • Point - transformed into [Marker]s
  • Multipoint - transformed into multiple [Marker]s with same ID property
  • LineString - tranformed in [Polyline]
  • MultiLineString - transformed into multiple [Polyline]s
  • Polygon - transformed into [Polygon]
  • MultiPolygon - transformed into multiple [Polygon]s with same ID property

Getting started #

Add the package in pubspec.yaml file:

flutter_map_geojson ^1.0.0

Import it in the code:

import 'package:flutter_map_geojson/flutter_map_geojson.dart';

Usage #

 // initiate parser 
 GeoJsonParser myGeoJson = GeoJsonParser();
 
 // parse GeoJson data - GeoJson is stored as [String]
 myGeoJson.parseGeoJsonAsString(testGeoJson);

 // after parsing the results are stored in 
 // myGeoJson.markers -> List<Marker>
 // myGeoJson.polylines -> List<Polyline>
 // myGeoJson.ploygons -> List<Polygon>

 // now create flutter_map layers

 FlutterMap(
          mapController: MapController(),
          options: MapOptions(
            center: LatLng(45.993807, 14.483972),
            zoom: 14,
          ),
          children: [
            TileLayer(
                urlTemplate:
                    "https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png",
                subdomains: const ['a', 'b', 'c']),
            PolygonLayer(polygons: myGeoJson.polygons),
            PolylineLayer(polylines: myGeoJson.polylines),
            MarkerLayer(markers: myGeoJson.markers)
          ],
        ));

The default [Marker], [Polyline] and [Polygon] creation callback functions can be replaced with user-defined highly customized functions. A good starting point are default callback functions which can be custimized to the needs of the project. The default callback functions have only basic functionality to display the spatial objects on the map. The default callback functions support changing the colors, stroke and fill color and marker icon. All these can be defined in default constructor or via setters.

For creating tappable polylines one can use package flutter_map_tappable_polyline.

22
likes
0
pub points
94%
popularity

Publisher

verified publisherdbprof.si

This package parses GeoJson formatted spatial data. It prepares three lists of objects defined in flutter_map package - Markers, Polylines and Polygons. These object are created by default callbacks which can be replaced by user-defined callback function which can be customized according to the requirements.

Repository (GitHub)
View/report issues

License

unknown (license)

Dependencies

flutter, flutter_map, latlong2

More

Packages that depend on flutter_map_geojson