app_map 0.0.2 copy "app_map: ^0.0.2" to clipboard
app_map: ^0.0.2 copied to clipboard

unlisted

map插件

example/lib/main.dart

import 'package:app_map/app_map.dart';
import 'package:app_map/app_map_controller.dart';
import 'package:app_map/app_map_setting.dart';
import 'package:app_map/app_map_view.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';

void main() {
  runApp(const MyApp());
}

class MyApp extends StatefulWidget {
  const MyApp({super.key});

  @override
  State<MyApp> createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  final _appMapPlugin = AppMap();
  late AppMapController appMapController;
  Uint8List? uint8list;
  bool isEnable = true;
  double zoom = 1;

  @override
  void initState() {
    _appMapPlugin.init();
    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        body: SafeArea(
          top: false,
          child: Column(
            children: [
              Expanded(
                child: AppMapView(
                  latitude: 37.112,
                  longitude: 110.123,
                  zoom: 8,
                  onMapViewCreated: (controller) {
                    appMapController = controller;
                  },
                  onMarkerClick: (index) {
                    print("onMarkerClick:$index");
                  },
                  onMapRegionChanged: (latitude, longitude, zoom) {
                    print("onMapRegionChanged:$latitude,$longitude,$zoom");
                  },
                ),
              ),
              const SizedBox(height: 20),
              if (uint8list != null) Image.memory(uint8list!, width: 400, height: 400),
              Wrap(
                spacing: 10,
                runSpacing: 10,
                children: [
                  buttonItem("设置卫星图", () {
                    appMapController.setMapType(MapType.hybrid.name);
                  }),
                  buttonItem("设置标准地图", () {
                    appMapController.setMapType(MapType.standard.name);
                  }),
                  buttonItem("设置日间模式", () {
                    appMapController.setMapStyle(MapStyle.light.name);
                  }),
                  buttonItem("设置夜间模式", () {
                    appMapController.setMapStyle(MapStyle.dark.name);
                  }),
                  buttonItem("设置位置", () {
                    appMapController.updateLocation(39.912, 112.423, true);
                  }),
                  buttonItem("设置缩放等级", () {
                    print("zoom:$zoom");
                    appMapController.setZoomLevel(zoom, 39.912, 112.423);
                    zoom++;
                  }),
                  buttonItem("设置缩放到显示所有点", () {
                    List<Map<String, double>> coordinates = [];
                    coordinates.add({"latitude": 39.912, "longitude": 112.423});
                    coordinates.add({"latitude": 39.812, "longitude": 112.423});
                    coordinates.add({"latitude": 39.712, "longitude": 112.423});
                    coordinates.add({"latitude": 39.612, "longitude": 112.423});
                    appMapController.setIncludeMarkers(coordinates, true);
                  }),
                  buttonItem("添加本地图片marker", () {
                    appMapController.addMarker(
                        latitude: 39.912,
                        longitude: 112.423,
                        imageAsset: "assets/images/location.png",
                        imageBytes: null,
                        index: 0,
                        center: false,
                        title: "hhh");
                  }),
                  buttonItem("添加data marker", () async {
                    final ByteData byteData = await rootBundle.load("assets/images/location.png");
                    final Uint8List imageBytes = byteData.buffer.asUint8List();
                    appMapController.addMarker(
                      latitude: 39.712,
                      longitude: 112.823,
                      imageAsset: null,
                      imageBytes: imageBytes,
                      index: 1,
                      center: true,
                    );
                  }),
                  buttonItem("添加折线", () {
                    List<Map<String, double>> coordinates = [];
                    coordinates.add({"latitude": 39.912, "longitude": 112.423});
                    coordinates.add({"latitude": 39.812, "longitude": 112.423});
                    coordinates.add({"latitude": 39.712, "longitude": 112.423});
                    coordinates.add({"latitude": 39.612, "longitude": 112.423});
                    appMapController.addPolyline(coordinates, 1, color: Colors.green, lineWidth: 2, isDashed: true);
                  }),
                  buttonItem("更新折线", () {
                    List<Map<String, double>> coordinates = [];
                    coordinates.add({"latitude": 39.912, "longitude": 112.423});
                    coordinates.add({"latitude": 39.812, "longitude": 112.623});
                    coordinates.add({"latitude": 39.712, "longitude": 112.823});
                    coordinates.add({"latitude": 39.612, "longitude": 112.923});
                    appMapController.updatePolyline(coordinates, 1, color: Colors.blue, lineWidth: 4, isDashed: false);
                  }),
                  buttonItem("清除marker", () {
                    appMapController.cleanAllMarkers();
                  }),
                  buttonItem("清除折线", () {
                    appMapController.cleanPolyline();
                  }),
                  buttonItem("屏幕截图", () async {
                    Uint8List? data = await appMapController.takeSnapshot();
                    if (data != null) {
                      setState(() {
                        uint8list = data;
                      });
                    }
                  }),
                  buttonItem("设置手势开关", () {
                    isEnable = !isEnable;
                    appMapController.setGesturesEnabled(isEnable);
                  }),
                ],
              )
            ],
          ),
        ),
      ),
    );
  }

  Widget buttonItem(String text, Function onTap) {
    return GestureDetector(
      onTap: () {
        onTap();
      },
      child: Container(
        decoration: BoxDecoration(color: Colors.blue, borderRadius: BorderRadius.circular(10)),
        padding: const EdgeInsets.symmetric(vertical: 5, horizontal: 10),
        margin: const EdgeInsets.only(right: 10),
        child: Text(text, style: const TextStyle(color: Colors.white, fontSize: 14)),
      ),
    );
  }
}
0
likes
75
points
11
downloads

Publisher

unverified uploader

Weekly Downloads

map插件

Documentation

API reference

License

BSD-2-Clause (license)

Dependencies

flutter, plugin_platform_interface

More

Packages that depend on app_map

Packages that implement app_map