geo_json_painter
Library for parsing the GeoJson format based on the RCF 7946 specification and displaying GeoJson on canvas.
All the main features described in the RCF 7946 specification have been implemented.
Getting started
The library provides two main entities that allow you to perform GeoJson rendering and processing tasks:
- GeoJson - сlass for parsing and configuring painter operation
- GeoJsonCustomPainter - class that controls rendering GeoJson data in accordance with a given configuration
Also, thanks to the GeoJson class, you can, if necessary, override both the Paint class for each individual GeoJson feature, and the entire drawing method using built-in methods:
//Draw method overriding
void addDrawMethodOverriding(GeoJsonFeatureType type, DrawFunction fn);
//Paint class overriding
void addPainterOverriding(GeoJsonFeatureType type, Paint paint)
This can be useful when you want to replace the default implementation with your own. For example, to replace the point drawn by the Point feature with an svg image. To get started, you can check out the code snippets below:
GeoJson parsing, paint and draw method overriding
final json = GeoJson()
..addPainterOverriding(
GeoJsonFeatureType.Point,
Paint()
..color = Colors.green
..strokeWidth = 10,
)
..addDrawMethodOverriding(GeoJsonFeatureType.Point, (canvas, feature) {
final point = feature.geometry as GeoJsonPoint;
canvas.drawRect(
Rect.fromCenter(
center: Offset(point.coordinates[1], point.coordinates[0]),
width: 10,
height: 25),
Paint()
..color = Colors.green
..strokeWidth = 10);
})
..parseGeoJson({
"type": "FeatureCollection",
"features": [
{
"type": "Feature",
"id": "1",
"properties": {
"prop0": "val0",
},
"geometry": {
"type": "Polygon",
"coordinates": [
[
[33.531650, 746.086982],
[467.606602, 746.086982],
[467.606602, 1160.930231],
[33.531650, 1160.930231],
[33.531650, 746.086982]
]
]
}
},
{
"type": "Feature",
"id": "2",
"properties": {
"prop0": "val0",
},
"geometry": {
"type": "Point",
"coordinates": [100.531650, 100.086982],
}
},
],
});
Example of using a widget
@override
Widget build(BuildContext context) {
return Scaffold(
body: ColoredBox(
color: Colors.white54,
child: InteractiveViewer(
child: CustomPaint(
size: Size(
MediaQuery.of(context).size.width,
MediaQuery.of(context).size.height,
),
painter: GeoJsonCustomPainter(
geoJson: json, //GeoJson instance
),
),
),
),
);
}
Info and documentation HERE
Libraries
- geo_json/exports/geo_json
- geo_json/exports/geo_json_custom_painter
- geo_json/exports/index
- geo_json/feature/geo_json_feature
- geo_json/feature/geo_json_feature_collection
- geo_json/feature/index
- geo_json/geometries/geo_json_geometry_collection
- geo_json/geometries/geo_json_geometry_fabric
- geo_json/geometries/geo_json_line_string
- geo_json/geometries/geo_json_multi_line_string
- geo_json/geometries/geo_json_multi_point
- geo_json/geometries/geo_json_multi_polygon
- geo_json/geometries/geo_json_point
- geo_json/geometries/geo_json_polygon
- geo_json/geometries/index
- geo_json/models/callbacks
- geo_json/models/drawable
- geo_json/models/geo_json_coordinate_pair
- geo_json/models/geo_json_coordinate_pair_list
- geo_json/models/geo_json_feature_type
- geo_json/models/geo_json_geometry_object
- geo_json/models/geo_json_object
- geo_json/models/index
- geo_json/models/paint_props
- geo_json_painter