livemap 0.5.0 copy "livemap: ^0.5.0" to clipboard
livemap: ^0.5.0 copied to clipboard

outdated

A map widget with live position updates. Provides a controller to manage the map state.

Livemap #

pub package

A map widget with live position updates. Based on Flutter map and Geolocator. Provides a controller api to handle map state changes.

Screenshot

Map controller #

Api for the LiveMapController class

Basic map controls #

For basic map controls like center, zoom, add an asset on the map see the Map controller documentation

Livemap controls #

Center

centerOnPosition(Position position ): center the map on a Position

centerOnLiveMarker(): recenter the map on the live position marker

toggleAutoCenter(): toggle the value of autocenter

autoCenter: get the current value of autocenter: used when the position updates are on

Rotation #

autoRotate: automatically rotate the map from bearing

rotate(double degrees): rotate the map

Position stream #

togglePositionStreamSubscription(): enable or disable the live position stream

On ready callback #

Execute code right after the map is ready:

@override
void initState() {
   liveMapController.onLiveMapReady.then((_) {
      liveMapController.togglePositionStreamSubscription();
   });
   super.initState();
}

Use the LiveMapSideBar widget or compose your own sidebar:

/// in a [Stack] widget
Positioned(
   top: 35.0,
   right: 15.0,
   child: Column(children: <Widget>[
      MapCenterOnLiveMarker(liveMapController: liveMapController),
      MapToggleAutoCenter(liveMapController: liveMapController),
      MapTogglePositionStream(liveMapController: liveMapController),
      MapZoomIn(liveMapController: liveMapController),
      MapZoomOut(liveMapController: liveMapController),
   ])
)

Tile layers #

Some open tile layers and a tile switcher bar are available:

@override
Widget build(BuildContext context) {
 return Scaffold(
     body: Stack(
   children: <Widget>[
     LiveMap(
       /// defaults the [tileLayer] property to [TileLayerType.normal]
       controller: liveMapController,
       center: LatLng(51.0, 0.0),
       zoom: 17.0),
     Positioned(
       top: 35.0,
       right: 20.0,
       child: TileLayersBar(controller: liveMapController)),
   ],
 ));
}

Available layers:

enum TileLayerType { normal, topography, monochrome, hike }

Custom tile layers bar:

Positioned(
   top: 35.0,
   right: 15.0,
   child: Column(children: <Widget>[
      // .. other buttons
      MapTileLayerNormal(liveMapController: livemapController),
      MapTileLayerMonochrome(liveMapController: livemapController),
      MapTileLayerTopography(liveMapController: livemapController),
      MapTileLayerHike(liveMapController: livemapController),
   ])
)

Example #

import 'package:flutter/material.dart';
import 'package:flutter_map/flutter_map.dart';
import 'package:geolocator/geolocator.dart';
import 'package:livemap/livemap.dart';
import 'package:latlong/latlong.dart';

class LiveMapPage extends StatelessWidget {
  LiveMapPage() () {
    liveMapController = LiveMapController(
      mapController:   MapController(),
      autoCenter: true);
  }

  LiveMapController liveMapController;

  @override
  Widget build(BuildContext context) {
    return Scaffold(
        body: LiveMap(
          controller: liveMapController,
          center: LatLng(51.0, 0.0),
          zoom: 13.0,
          titleLayer: TileLayerOptions(
              urlTemplate: "https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png",
              subdomains: ['a', 'b', 'c']),
        ));
  }

  @override
  void dispose() {
    liveMapController.dispose();
    super.dispose();
  }
}

Changefeed #

A changefeed is available: it's a stream with all state changes from the map controller. Ex:

import 'dart:async';

StreamSubscription _changefeed;
int _myzoom;

liveMapController.onReady.then((_) {
    _myzoom = liveMapController.zoom;
    _changefeed = liveMapController.changeFeed.listen((change) {
     if (change.name == "zoom") {
       print("New zoom value: ${change.value}")
     }
   });
}

// dispose: _changefeed.cancel();
13
likes
40
pub points
8%
popularity

Publisher

unverified uploader

A map widget with live position updates. Provides a controller to manage the map state.

Repository (GitHub)
View/report issues

License

MIT (LICENSE)

Dependencies

cupertino_icons, extra_pedantic, flutter, fluttertoast, fluxmap, geopoint_location, map_controller, pedantic

More

Packages that depend on livemap