패키지, 저장소 및 앱 카테고리 검색

패키지 상세v0.9.0

map_controller

Flutter 지도용 맵 컨트롤러입니다. 마커, 선 및 다각형을 관리합니다.

30일 다운로드
64
좋아요
25
Pub 점수
40

패키지 설치

flutter pub add map_controller

패키지 개요

공개 정보를 바탕으로 생성한 선택 가이드입니다.

map_controller는 마커, 선, 다각형과 같은 지도 요소를 관리하는 것을 간편하게 만드는 Flutter 패키지입니다. 지도 콘텐츠의 상호작용, 업데이트 및 상태 변경을 처리하기 위해 중앙 컨트롤러를 제공하여 코드 구조와 성능을 향상시킵니다. 동적 지도 시각화가 필요한 애플리케이션에 적합하며, Flutter의 지도 위젯과 원활하게 통합됩니다. 이 패키지는 'here'에서 유지보수되며 pub.dev를 통해 이용할 수 있습니다. 소스 코드는 GitHub에서 오픈되어 있어 투명성과 커뮤니티 기여를 가능하게 합니다.

사용 사례

  • 다이나믹 마커 관리
  • 실시간 경로 시각화
  • 인터랙티브 다각형 오버레이
  • 지도 데이터 동기화
  • 위치 기반 UI 구성 요소

주요 기능

  • 중앙 집중식 지도 상태 제어
  • 마커, 선 및 다각형 지원
  • 효율적인 업데이트 메커니즘
  • Flutter 지도와의 간편한 통합
  • 오픈소스이며 지속적으로 유지 관리되고 있습니다

적합한 대상

  • 인터랙티브 지도를 개발하는 개발자
  • 실시간 위치 추적 기능이 있는 애플리케이션
  • 복잡한 지도 레이어를 필요로 하는 프로젝트
  • 클린하고 유지보수 가능한 코드를 우선시하는 팀
  • 지리공간 데이터를 갖춘 Flutter 앱

고려 사항

  • 호환되는 지도 위젯 구현이 필요합니다
  • 제한된 플랫폼별 사용자 지정
  • 내장된 지도 렌더링 없음(외부 지도 위젯에 의존)
  • 고급 기능을 사용하려면 추가 종속성이 필요할 수 있습니다
  • 문서가 더 자세해야 합니다

원본 README

연결된 소스 저장소의 README 원문 스냅샷입니다. 최신 내용은 저장소에서 확인하세요.

Map controller

pub package

Stateful map controller for Flutter Map. Manage markers, lines and polygons.

View the web demo

Usage

import 'dart:async';
import 'package:flutter/material.dart';
import 'package:flutter_map/flutter_map.dart';
import 'package:latlong/latlong.dart';
import 'package:map_controller/map_controller.dart';

class _MapPageState extends State<MapPage> {
  MapController mapController;
  StatefulMapController statefulMapController;
  StreamSubscription<StatefulMapControllerStateChange> sub;

  @override
  void initState() {
    // intialize the controllers
    mapController = MapController();
    statefulMapController = StatefulMapController(mapController: mapController);

    // wait for the controller to be ready before using it
    statefulMapController.onReady.then((_) => print("The map controller is ready")));

    /// [Important] listen to the changefeed to rebuild the map on changes:
    /// this will rebuild the map when for example addMarker or any method 
    /// that mutates the map assets is called
    sub = statefulMapController.changeFeed.listen((change) => setState(() {}));
    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: SafeArea(
          child: Stack(children: <Widget>[
        FlutterMap(
          mapController: mapController,
          options: MapOptions(center: LatLng(48.853831, 2.348722), zoom: 11.0),
          layers: [
            MarkerLayerOptions(markers: statefulMapController.markers),
            PolylineLayerOptions(polylines: statefulMapController.lines),
            PolygonLayerOptions(polygons: statefulMapController.polygons)
          ],
        ),
        // ...
      ])),
    );
  }

  @override
  void dispose() {
    sub.cancel();
    super.dispose();
  }
}

class MapPage extends StatefulWidget {
  @override
  _MapPageState createState() => _MapPageState();
}

Api

Api for the StatefulMapController class

Map controls
Zoom

zoom: get the current zoom value

zoomIn(): increase the zoom level by 1

zoomOut(): decrease the zoom level by 1

zoomTo(Double value): zoom to the provided value

Center

center: get the current center LatLng value

centerOnPoint(LatLng point): center on the LatLng value

Map assets
Markers

addMarker(String name, Marker marker): add a named marker on the map

addMarkers(Map<String, Marker> markers): add several named markers on the map

removeMarker(String name, Marker marker): remove a named marker from the map

removeMarkers(Map<String, Marker> markers): remove several named markers from the map

markers: get the markers that are on the map

namedMarkers: get the markers with their names that are on the map

Stateful markers

New in 0.7: the stateful makers hold their own state and can be mutated

statefulMapController.addStatefulMarker(
   name: "some marker",
   statefulMarker: StatefulMarker(
      height: 80.0,
      width: 120.0,
      state: <String, dynamic>{"showText": false},
      point: LatLng(48.853831, 2.348722),
      builder: (BuildContext context, Map<String, dynamic> state) {
         Widget w;
         final markerIcon = IconButton(
            icon: const Icon(Icons.location_on),
            onPressed: () => statefulMapController.mutateMarker(
                  name: "some marker",
                  property: "showText",
                  value: !(state["showText"] as bool)));
         if (state["showText"] == true) {
            w = Column(children: <Widget>[
            markerIcon,
            Container(
                  color: Colors.white,
                  child: Padding(
                     padding: const EdgeInsets.all(5.0),
                     child: Text(place.name, textScaleFactor: 1.3))),
            ]);
         } else {
            w = markerIcon;
         }
         return w;
      })
   );
Lines

addLine(String name, List<LatLng> points, double width = 1.0, Color color = Colors.green, bool isDotted = false): add a line on the map

lines: get the lines that are on the map

Polygons

addPolygon(String name, List<LatLng> points, double width = 1.0, Color color = const Color(0xFF00FF00), double borderWidth = 0.0, Color borderColor = const Color(0xFFFFFF00)): add a polygon on the map

polygons: get the polygons that are on the map

On ready callback

Execute some code right after the map is ready:

@override
void initState() {
   statefulMapController.onReady.then((_) {
      setState((_) =>_ready = true);
   });
   super.initState();
}
Changefeed

A changefeed is available: it's a stream with all state changes from the map controller. Use it to update the map when a change occurs:

statefulMapController.onReady.then((_) {
    statefulMapController.changeFeed.listen((change) => setState(() {}));
   });
}
Geojson data

The map controller can draw on the map from geojson data:

void loadData() async {
  print("Loading geojson data");
  final data = await rootBundle.loadString('assets/airports.geojson');
  await statefulMapController.fromGeoJson(data,
    markerIcon: Icon(Icons.local_airport), verbose: true);
}

@override
void initState() {
  mapController = MapController();
  statefulMapController = StatefulMapController(mapController: mapController);
  statefulMapController.onReady.then((_) => loadData());
  sub = statefulMapController.changeFeed.listen((change) => setState(() {}));
  super.initState();
}

Tile layer management

Some predefined tile layers are available.

FlutterMap(
   mapController: mapController,
   options: MapOptions(
      center: LatLng(48.853831, 2.348722), zoom: 11.0),
   layers: [
      // Use the map controller's tile layer
      statefulMapController.tileLayer,
      MarkerLayerOptions(markers: statefulMapController.markers),
      // ...
   ],
)

To switch tile layers at runtime use:

statefulMapController.switchTileLayer(TileLayerType.monochrome);

Available layers:

TileLayerType.normal
TileLayerType.topography
TileLayerType.monochrome
TileLayerType.hike

A tile layers bar is available:

Stack(children: <Widget>[
   FlutterMap(
      mapController: mapController,
      options: MapOptions(center: LatLng(48.853831, 2.348722), zoom: 11.0),
      layers: [
      statefulMapController.tileLayer,
      MarkerLayerOptions(markers: statefulMapController.markers),
      ],
   ),
   Positioned(
      top: 15.0,
      right: 15.0,
      child: TileLayersBar(controller: statefulMapController))
])

카테고리

의존성

의존성 목록 7 개

소스 저장소

이 패키지를 사용하는 프로젝트

아직 데이터가 없습니다.