MapZoneManager 是一个 Flutter 包,旨在简化在 Google 地图上创建、标记和管理区域的过程。它支持多个区域,允许自定义地图样式,并提供精确的相机控制以实现流畅导航。适用于需要空间区域可视化的应用,例如配送区域、活动区域或地理围栏。该包可无缝集成到 Android、iOS 和 Web 平台,为开发者提供强大的交互式地图功能解决方案。
适合场景
配送区域可视化
地理围栏应用
事件区域规划
交互式地图注释
基于位置的服务
实时区域跟踪
主要特点
多区域支持
可自定义地图样式
相机控制工具
区域创建工具
交互区域标记
跨平台兼容性
适合对象
开发位置感知应用程序的开发者
需要基于区域的地图交互的团队
使用地理围栏或配送区域的应用程序
Web 和移动地图集成
需要动态地图注释的项目
使用建议
需要 Google Maps API 密钥
仅限 Google 地图集成
可能需要对大量区域进行性能调优
依赖稳定的互联网连接进行地图渲染
Web 平台需要额外设置
原始 README
以下为关联源码仓库的 README 原文快照,最新内容请访问源码仓库。
MapZoneManager
MapZoneManager is a Flutter package that provides a widget and controller to manage zones on a Google Map. It allows you to create, update, and manage multiple zones, with features for handling map markers, polygons, and custom actions like adding or resetting zones. It supports both single and multi-zone management and is highly customizable with features like custom buttons and map styles.
Features
Zone Creation: Create zones by tapping on the map and adding coordinates to form a polygon.
Multiple Zones: Supports managing multiple zones on the map.
Customizable: Customize zone colors, border colors, and border width.
View-Only Mode: Ability to display zones in a read-only mode (no zone creation).
Custom Buttons: Option to replace the default add/reset zone buttons with custom widgets.
Markers & Polygons: Displays markers and polygons for each zone created on the map.
Zoom Controls: Enable/disable zoom controls and gestures.
Location Services: Enable location tracking and display of the user's current location.
Map Styles: Apply different map styles to customize the appearance of the map.
Installation
To add the package to your Flutter project, update your pubspec.yaml file:
Run flutter pub get to install the dependencies.
dependencies:
map_zone_manager: ^0.0.1
Usage
Basic Usage
To use the MapZoneManager widget, you need to add it to your widget tree. Here's a basic example:
initialCameraPosition: The initial camera position for the map (optional).
markerIcon: The icon for the markers (optional).
multiZone: Whether multiple zones can be added (default is true).
showAddButton: Whether to show the button to add a zone (default is true).
showResetButton: Whether to show the button to reset the zone (default is true).
viewOnly: Whether the map is in view-only mode (default is false).
addButtonWidget: Custom widget for the add button (optional).
resetButtonWidget: Custom widget for the reset button (optional).
zones: A list of initial zones to display on the map (optional).
onZoneAdded: A callback triggered when a new zone is added (optional).
mapStyle: The map style to apply (optional, defaults to MapStyle.standard).
mapZoneManagerController: A controller to manage map zones (optional).
minimumCoordinatesForAdding: The minimum number of coordinates required to create a zone (default is 2).
defaultZoneColor: The default fill color for zones (default is Colors.yellow).
defaultBorderColor: The default border color for zones (default is Colors.black).
defaultBorderWidth: The default border width for zones (default is 2).
currentZoneColor: The color for the current zone being created (default is Colors.red).
currentBorderColor: The color for the current zone's border (default is Colors.black).
currentBorderWidth: The width of the current zone's border (default is 2).
onTap: A callback triggered when the map is tapped (optional).
onLongPress: A callback triggered when the map is long-pressed (optional).
zoomControlsEnabled: Whether zoom controls are enabled (default is true).
zoomGesturesEnabled: Whether zoom gestures are enabled (default is true).
myLocationEnabled: Whether the user's current location is displayed (default is false).
myLocationButtonEnabled: Whether the "My Location" button is enabled (default is true).
MapZoneManagerController
The MapZoneManagerController is a controller class for managing zones and map-related operations. You can use this controller to manage zones, add coordinates, and move the camera to fit a zone.