GalliMap for Flutter

Galli Map is a Flutter package that provides a customizable map widget for displaying Map with custom markers, lines, circles, and polygons. The widget supports zooming in and out, tapping on the map, and showing the user's current location.
To install and start using this package in your Flutter project, you need to add "galli_map" as a dependency in your project's pubspec.yaml file. You can follow the installation guide provided in the "galli_map" package on pub.dev or use this link (https://pub.dev/packages/galli_map) to access the package page on pub.dev.

GalliMap Widget

A map widget for Flutter. To use this widget import and add the Galli Map widget to the project.

Properties:

height A double value that specifies the height of the map.
width A double value that specifies the width of the map.
zoom A double value that specifies the initial zoom level of the map
maxZoom A double value that specifies the maximum zoom level of the map.
minZoom A double value that specifies the minimum zoom level of the map.
showCurrentLocation A boolean value that determines whether to show the current location or not.
currentLocationMarker A widget that specifies the marker to be used for the current location.
markers A list of GalliMarker objects that specify the markers to be displayed on the map.
lines A list of GalliLine objects that specify the lines to be displayed on the map.
circles A list of GalliCircle objects that specify the circles to be displayed on the map.
polygons A list of GalliPolygon objects that specify the polygons to be displayed on the map.
showSearch A boolean value that determines whether to show the search feature or not.
show360Button A boolean value that determines whether to show the 360 button or not.
three60Widget A widget that specifies the 360 widget to be displayed on the map.
showLocationButton A boolean value that determines whether to show the location button or not.
currentLocationWidget A widget that specifies the location widget to be displayed on the map.
searchHint A string value that specifies the hint text to be displayed in the search bar.
controller A GalliController object that controls the behavior of the map.
onTapAutoComplete A function that is called when an autocomplete item is tapped.
onTap A function that is called when the map is tapped. It receives a LatLng object that represents the tapped location.
children A list of widgets that will be displayed on top of the map but below other overlays.
initialPosition A LatLng value that specifies where the camera will be at the start of the map widget.
three60MarkerSize A double value that determines the size of markers.
on360MarkerTap A function that specifies the actions on 360 marker click. Originally a 360 image will display on marker click. To not display a 360 image return null on360MarkerTap.
onMapLoadComplete A function that returns a controller and lets the user controller the map and display its attributes.
onMapUpdate A function that returns current map state and lets the user display and use those states and events.
markerClusterWidget A list of GalliMarker which will be clustered.
show360ImageOnMarkerClick A boolean value which determines whether to show 360 Image on marker click. It is true by default.
viewer A 360 viewer widget, if not specified a default widget will be displayed on 360 marker click.
viewerPosition An offset value that determines the position of 360 viewer widget within the context. It only works if the user passes a custom 360 viewer widget.
authKey Access Token key provided by GalliExpress.

Example Usage :

Basic Map with markers, circles, lines ,polygons and 360 viewer

import 'dart:convert';
import 'dart:developer';
import 'package:flutter/material.dart';
import 'package:galli_map/galli_map.dart';
	
void main() {
	runApp(const MyApp());
}
	
class MyApp extends StatelessWidget {
const MyApp({super.key});
	
// This widget is the root of your application.
@override
Widget build(BuildContext context) {
	return MaterialApp(
	title: 'Flutter Demo',
	debugShowCheckedModeBanner: false,
	theme: ThemeData(
	primarySwatch: Colors.blue,
	),
	home: const MyHomePage(),
	);
	}
}
	
class MyHomePage extends StatefulWidget {
const MyHomePage({super.key});
	
@override
	State createState() => _MyHomePageState();
}
	
class _MyHomePageState extends State with TickerProviderStateMixin {
	final GalliController controller = GalliController();
	final GalliMethods galliMethods =
	GalliMethods("YOUR-ACCESS-TOKEN");
	
@override
	void initState() {
	super.initState();
}
	
@override
Widget build(BuildContext context) {
	return Scaffold(
	body: SafeArea(
	child: Column(
		children: [
		SizedBox(
		height: MediaQuery.of(context).size.height * 0.8,
		width: MediaQuery.of(context).size.width,
		child: GalliMap(
		onTapAutoComplete: (AutoCompleteModel model) async {
		FeatureModel? feature = await galliMethods.search(
		model.name!, controller.map.center);
		if (feature != null) {
		await galliMethods.getRoute(
		source: controller.map.center,
		destination: feature.geometry!.coordinates!.first);
		}
	},
	onMapLoadComplete: (controller) async {
	galliMethods.animateMapMove(LatLng(27.709857, 85.339195), 18,
	this, mounted, controller);
},
	authKey: "YOUR-ACCESS-TOKEN",
	controller: controller,
	zoom: 16,
	initialPosition: LatLng(27.672905, 85.312215),
	showCurrentLocation: true,
	viewer: Viewer(
		accessToken: "YOUR-ACCESS-TOKEN",
		pinIcon: Icon(
			Icons.abc,
			size: 48,
		),
		animSpeed: 2,
		height: 300,
		width: 300,
		onSaved: (x, y) {
		print("$x,$y");
	}),
		onTap: (tap) {
		galliMethods.reverse(tap);
	},
		on360MarkerTap: () {},
		onMapUpdate: (event) {},
		circles: [
		GalliCircle(
		center: LatLng(27.684222, 85.303778),
		radius: 54,
		color: Colors.white,
		borderStroke: 3,
		borderColor: Colors.black)
	],
		lines: [
		GalliLine(
		line: [
		LatLng(27.684222, 85.303778),
		LatLng(27.684246, 85.303780),
		LatLng(27.684222, 85.303790),
		LatLng(27.684230, 85.303778),
	],
		borderColor: Colors.blue,
		borderStroke: 2,
		lineColor: Colors.white,
		lineStroke: 2)
	],
		polygons: [
		GalliPolygon(
		polygon: [
		LatLng(27.684222, 85.303778),
		LatLng(27.684246, 85.303780),
		LatLng(27.684222, 85.303790),
		LatLng(27.684290, 85.303754),
	],
	    borderColor: Colors.red,
		borderStroke: 2,
		color: Colors.green,
		),
	],
		children: [
		Positioned(
		top: 64,
		right: 64,
		child: Container(
		width: 32,
		height: 32,
		color: Colors.yellow,
		)
	],
		markerClusterWidget: (context, list) {
		return Container(
		width: 20,
		height: 20,
		color: Colors.red,
		child: Center(
			child: Text(list.length.toString()),
			),
		);
	},
		viewerPosition: Offset(32, 32),
		markers: [
		
		GalliMarker(
		latlng: LatLng(27.684222, 85.30134),
		anchor: Anchor.top,
		markerWidget: const Icon(
		Icons.location_history,
		color: Colors.black,
		size: 48,
		)),
		
		GalliMarker(
		latlng: LatLng(27.684222, 85.30134),
		anchor: Anchor.top,
		markerWidget: const Icon(
		Icons.location_history,
		color: Colors.black,
		size: 48,
		)),
		
		GalliMarker(
		latlng: LatLng(27.684222, 85.30134),
		anchor: Anchor.top,
		markerWidget: const Icon(
		Icons.location_history,
		color: Colors.black,
		size: 48,
		)),
		
		GalliMarker(
		latlng: LatLng(27.684222, 85.30134),
		anchor: Anchor.top,
		markerWidget: const Icon(
		Icons.location_history,
		color: Colors.black,
		size: 48,
		))
	],
		),
	  ),
	 ],
    ),
   ),
  ),
 );
}
}

AutoComplete Model

The AutoCompleteModel class represents a suggestion item for an autocomplete field. It has the following properties:

Properties:

name (String) The name of the suggestion item.
fclass (String) The functional class of the suggestion item.
geometryString (String) A string representation of the geometry of the suggestion item.

The class has the following methods:

AutoCompleteModel({this.name, this.fclass, this.geometryString}) A constructor for creating a new instance of the AutoCompleteModel class.
AutoCompleteModel.fromJson(Map<String, dynamic> json) A constructor for creating a new instance of the AutoCompleteModel class from a JSON map.
toJson() A method for converting an instance of the AutoCompleteModel class to a JSON map.
// Create a new AutoCompleteModel
	AutoCompleteModel suggestion = AutoCompleteModel(
	name: 'Patan Hospital',
	fclass: 'hospital',
	geometryString: 'POINT',
	);
					
// Convert the object to JSON
	Map json = suggestion.toJson();
	print(json);
					
// Create an AutoCompleteModel from JSON
	String jsonString = '{"name": "Patan Hospital", "fclass": "hospital", 
						"geometryString": "POINT"}';
	AutoCompleteModel fromJson = AutoCompleteModel.fromJson(jsonDecode(jsonString));
	print(fromJson.name);

This example creates a new AutoCompleteModel object with the name "Patan Hospital", fclass "hospital", and a geometryString representing a point in Lalitpur. It then converts the object to JSON and prints the resulting string. Next, it creates a new AutoCompleteModel object from JSON and prints the name property.

Feature Model

The FeatureModel class has the following properties:

Properties:

type A nullable String property that represents the type of feature.
properties A nullable Properties object representing the properties of the feature.
geometry A nullable Geometry object representing the geometry of the feature.

The class also has a constructor that takes these properties as arguments, as well as a fromJson method that creates a FeatureModel object from a JSON object, and a toJson method that creates a JSON object from a FeatureModel object.
FeatureType FeatureType is an enum with four possible values: point, multilinestring, multipolygon, and other. The stringToFeatureType function maps a string to its corresponding FeatureType enum value.

Properties

The Properties class has the following properties:

distance A nullable double property representing the distance of the feature.
category A nullable String property representing the category of the feature.

The class also has a constructor that takes these properties as arguments, as well as a fromJson method that creates a Properties object from a JSON object, and a toJson method that creates a JSON object from a Properties object.

Geometry

The Geometry class has the following properties:

type A nullable FeatureType enum property representing the type of geometry.
coordinates A nullable List of LatLng objects representing the coordinates of the feature if the type is "point".
listOfCoordinates A nullable List of LatLng objects representing the list of coordinates of the feature if the type is not a "point".

The class also has a constructor that takes these properties as arguments, as well as a fromJson method that creates a Geometry object from a JSON object, and a toJson method that creates a JSON object from a Geometry object.

Example Usage

Map jsonMap = {
	"type": "point",
	"properties": {
	"distance": 10.0,
	"category": "hospital"
	},
	"geometry": {
	"type": "point",
	"coordinates": [27.668185, 85.320856]
	}
	};
				  
	FeatureModel featureFromJson = FeatureModel.fromJson(jsonMap);
				  
	Map featureJson = feature.toJson();

House Model

The HouseModel class has the following properties:

Properties:

id An integer representing the ID of the house.
featurecode A string representing the feature code of the house.
number An integer representing the number of the house.
houseCode A string representing the code of the house.
maxlat A string representing the maximum latitude of the house.
minlat A string representing the minimum latitude of the house.
maxlong A string representing the maximum longitude of the house.
minlong A string representing the minimum longitude of the house.
uniqueId A string representing the unique ID of the house.
streetCode A string representing the code of the street where the house is located.
ward A string representing the ward where the house is located.
streetNameEn A string representing the English name of the street where the house is located.
center A LatLng object representing the center of the house.
address An Address object representing the address of the house.
coordinate A list of LatLng objects representing the coordinates of the house.

The HouseModel class has the following methods:

HouseModel.fromFeature() A constructor that takes a FeatureModel object and a string as parameters and sets the streetNameEn and center properties of the HouseModel object.
HouseModel.fromFeatureString() A constructor that takes a map as a parameter and sets the properties of the HouseModel object.
HouseModel.fromJson() A constructor that takes a map as a parameter and sets the properties of the HouseModel object.
toJson() A method that returns a map representing the HouseModel object.

The Address class has the following properties:

id An integer representing the ID of the address.
statecode An integer representing the code of the state where the address is located.
district A string representing the district where the address is located.
municipal A string representing the municipality where the address is located.
ward An integer representing the ward where the address is located.
state A StatePlace object representing the state where the address is located.

The StatePlace class has the following properties:

id An integer representing the ID of the state.
stateCode A string representing the code of the state.
name A string representing the name of the state.

Image Model

The ImageModel class has the following properties:

Properties:

image A string representing the image path or name.
lat A double representing the latitude value of the image location.
lng A double representing the longitude value of the image location.
folder A string representing the folder location where the image is stored.
location A string representing the location where the image was taken.

The class has a default constructor that takes all five properties as optional named parameters. It also has a named constructor fromJson that takes a JSON map and uses it to create an ImageModel object, and a method toJson that converts an ImageModel object to a JSON map.

The fromJson method uses the values from the JSON map to initialize the properties of the ImageModel object. The lat and lng properties can be either numbers or strings representing numbers, so the method checks the type of these properties and converts them to numbers if they are strings.

The toJson method creates a new map and adds the properties of the ImageModel object to it, converting the lat and lng properties to strings.

Example Usage

ImageModel myImage = ImageModel(
	image: "myImage.jpg",
	lat: 27.669930, 
	lng: 85.321624,
	folder: "myFolder",
	location: "Lalitpur"
  );
  
  String jsonString = '{"image": "myImage.jpg", "lat": 27.669930, 
  	"lng": 85.321624, "folder": "myFolder", "location": "Lalitpur"}';
  ImageModel myImage = ImageModel.fromJson(jsonDecode(jsonString));
  
  
  String jsonString = jsonEncode(myImage.toJson());
  

RouteInfo Model

The RouteInfo class is a model class that represents information about a route, including its distance, duration, and list of LatLng coordinates. It has a constructor that can take in these properties as arguments, as well as a fromJson method that can be used to construct an instance of the class from a JSON object, and a toJson method that can be used to serialize an instance of the class to a JSON object.

Properties:

distance (double?) The distance of the route, in kilometers. This property is nullable.
duration (int?) The duration of the route, in minutes. This property is nullable.
latlngs (List<LatLng>?) A list of LatLng objects that represent the coordinates of the route. This property is nullable.

Constructors:

RouteInfo({this.distance, this.duration, this.latlngs}) Constructs a RouteInfo object with the given distance, duration, and list of LatLng coordinates. All properties are optional and nullable.
RouteInfo.fromJson(Map<String, dynamic> json) Constructs a RouteInfo object from a JSON object. The JSON object must have the following properties: distance (double), the distance of the route in meters, duration (int), the duration of the route in seconds, and latlngs (List<dynamic>), a list of coordinate pairs where each pair is a list of two numbers representing the latitude and longitude of a point on the route.
Map<String, dynamic> toJson() Serializes a RouteInfo object to a JSON object with the following properties: distance (double), the distance of the route in kilometers, duration (int), the duration of the route in minutes, and latlngs (List<dynamic>), a list of coordinate pairs where each pair is a list of two numbers representing the latitude and longitude of a point on the route.

Example Usage

final routeInfo = RouteInfo(
distance: 10.5,
duration: 30,
latlngs: [
    LatLng(27.657980, 85.322459),
    LatLng(27.678730, 85.349415),
    LatLng(27.686634, 85.343160),
],
 );  

GalliCircle Model

The GalliCircle class represents a circle with a center point and a radius. It has the following properties:

radius (double) The radius of the circle in meters.
center (LatLng) The center point of the circle.
color (Color) The fill color of the circle.
borderColor (Color) The border color of the circle.
borderStroke (double) The width of the border of the circle.

The class has the following methods:

containsPoint(LatLng point) A method for determining whether a given point is inside the circle. Returns true if the point is inside the circle, false otherwise.

Example Usage

GalliMap(
authKey: ............,
controller:............,
............,
............,
circles: [
GalliCircle(
	center: LatLng(27.67723, 85.32217),
	radius: 32,
	color: Colors.white,
	borderStroke: 3,
	borderColor: Colors.black)
 	],
),

GalliMarker Model

GalliMarker is used to represent a marker on a map. The class contains information about the location of the marker as well as the widget to be used as the marker.
The class has the following properties:

latlng A required LatLng object representing the location of the marker.
markerWidget A required Widget representing the marker itself.
anchor An optional Anchor enum value representing the anchor point of the marker. It has five possible values representing the five anchor positions: top, center, bottom, right, and left.

The anchorToAnchorPos function is a helper function that maps an Anchor enum value to its corresponding AnchorPos object from the package. If the anchor parameter is null, the function returns null.

GalliPolygon Model

GalliPolygon represents a polygon on a map. It has the following properties:

polygon A list of LatLng points that define the vertices of the polygon.
color The fill color of the polygon.
borderColor The color of the polygon border.
borderStroke The width of the polygon border.
isFilled A boolean indicating whether the polygon should be filled.

The class has the following methods:

containsPoint(LatLng point) Returns a boolean indicating whether the given LatLng point is within the bounds of the polygon.

GalliLine Model

GalliLine represents a polyline on a map. The class contains information about the points that make up the polyline, as well as the color, border color, and stroke width of the line.
The class has the following properties:

line A required list of LatLng objects representing the points that make up the polyline.
lineColor An optional Color object representing the color of the polyline.
borderColor An optional Color object representing the color of the polyline's border.
borderStroke An optional double representing the stroke width of the polyline's border.
lineStroke An optional double representing the stroke width of the polyline.

When the toPolyline method is called, it returns a Polyline object with the specified properties, which can be added to a map using the PolylineLayerOptions class.

Galli Methods

Galli Methods are part of the GalliMap flutter package that allows developers to retrieve necessary data based on the parameters and functions called. This class contains several functions related to maps, location services, and APIs. The following documentation details each of these functions and their respective purposes:

GETautoComplete(String query)


var getAutoComplete(String query) async{
String results = await galliMap.autoComplete(query);
return results;
}

This function takes a query as a parameter and returns a list of AutoCompleteModel objects. It sends a request to an API endpoint that provides autocomplete suggestions for the query. The response is a JSON string that is converted into a list of AutoCompleteModel objects.

GETsearch(String query, LatLng location)


var getSearchResults(String query, LatLng location) async{
String results = await galliMap.search(query, location);
return results;
}

This function takes a query and a LatLng object as parameters and returns a FeatureModel object. It sends a request to an API endpoint that searches for a feature (e.g., a city or a landmark) that matches the query and is close to the provided location. The response is a JSON string that is converted into a FeatureModel object.

GETreverse(LatLng point)


var getReverseGeocodingResults(LatLng point) async{
String results = await galliMap.reverse(point);
return results;
}

This function takes a LatLng object as a parameter and returns a HouseModel object. It sends a request to an API endpoint that provides reverse geocoding information (i.e., it returns information about the address of a location). The response is a JSON string that is converted into a HouseModel object.

GETgetRoute({required LatLng source, required LatLng destination})


var getRoute(LatLng source, LatLng destination) async{
String results = await galliMap.getRoute(source, destination);
return results;
}

This function takes two LatLng objects as parameters (a source and a destination) and returns a RouteInfo object. It sends a request to an API endpoint that calculates the route between the two locations. The response is a JSON string that is converted into a RouteInfo object.

GETget360ImagePoints(MapController mapController)


var get360ImagePoints(MapController mapController) async{
String results = await galliMap.get360ImagePoints(mapController);
return results;
}

This function takes a MapController object as a parameter and returns a list of ImageModel objects. It sends a request to an API endpoint that provides 360-degree image points that are visible on the map. The response is a JSON string that is converted into a list of ImageModel objects.

GETgetCurrentLocation()


var getCurrentLocation() async{
String result = await galliMap.getCurrentLocation();
return result;
}

This function returns a Position object that represents the device's current location. It uses the Geolocator package to obtain the device's location. If the device is located in Nepal, the function returns the actual location; otherwise, it returns a default location.

STREAM streamCurrentLocation()


var streamCurrentLocation() async{
String result = await galliMap.streamCurrentLocation();
return result;
}

This function returns a Stream of Position objects that represent the device's location over time. It uses the Geolocator package to obtain the device's location.

ANIMATE animateMapMove(LatLng destLocation, double destZoom, Object vsync, bool mounted, MapController mapController)


animateMapMove(destLocation, destZoom, vsync, mounted, mapController);

This function takes a destination location, a destination zoom level, a vsync object, a boolean indicating whether the component is still mounted, and a MapController object as parameters. It animates the map to move to the destination location and zoom level.

ROTATE rotateMap(Object vsync, bool mounted, MapController mapController)


rotateMap(vsync, mounted, mapController);

This function takes a vsync object, a boolean indicating whether the component is still mounted, and a MapController object as parameters. It animates the map to rotate back to the default orientation (0 degrees).