mapwize 0.0.1-beta.4 copy "mapwize: ^0.0.1-beta.4" to clipboard
mapwize: ^0.0.1-beta.4 copied to clipboard

Integrate Mapwize Indoor Maps in Flutter apps

example/lib/main.dart

import 'package:flutter/material.dart';
import 'dart:async';

import 'package:flutter/services.dart';
import 'package:mapwize/mapwize.dart';

import 'dart:typed_data';

void main() => runApp(MaterialApp(home: MapViewExample()));

class MapViewExample extends StatelessWidget {

  MapwizeMapController controller;

  @override
  Widget build(BuildContext context) {
    return Scaffold(
        appBar: AppBar(title: const Text('Flutter Mapwize Example')),
        body: Column(children: [
          Expanded(
              flex: 3,
              child: MapwizeMap(
                apiKey: "MapwizeDevAPIKEY", //This is a demo API KEY that CANNOT be used for production.
                centerOnVenueId: "56b20714c3fa800b00d8f0b5",
                onMapCreatedCallback: _onMapViewCreated,
                onMapLoadedCallback: _onMapLoaded,
                onMapClickCallback: _onMapClick,
                onFloorsChangeCallback: _onFloorsChanged,
                onFloorChangeCallback: _onFloorChanged,
                onVenueEnterCallback: _onVenueEnter,
              )
          ),
          new FlatButton(
            onPressed: _addLineAndMarker,
            child: new Icon(Icons.add),
          ),
          new FlatButton(
              onPressed: _removeLineAndMarker,
              child: new Icon(Icons.delete),
          ),
        ]));
  }

  /// Adds an asset image to the currently displayed style
  Future<void> addImageFromAsset(String name, String assetName) async {
    final ByteData bytes = await rootBundle.load(assetName);
    final Uint8List list = bytes.buffer.asUint8List();
    return controller.addImage(name, list);
  }

  void _addLineAndMarker() async {
    controller.setFloor(3);
    SymbolOptions options = SymbolOptions(
      geometry: LatLng(10.0, 10.0),
      iconImage: "assetImage",
      iconSize: 3
    );
    Symbol s = await this.controller.addSymbol(options);
    LineOptions lineOptions = LineOptions(
      geometry: <LatLng>[LatLng(0.0, 0.0), LatLng(10.0, 10.0)],
      lineColor: "#C51586"
    );
    debugPrint("$lineOptions");
    this.controller.addLine(lineOptions);
  }

  void _removeLineAndMarker() async {
    this.controller.clearSymbols();
    this.controller.clearLines();
  }

  void _onMapViewCreated(MapwizeMapController controller) {
    debugPrint("On map view created");
    this.controller = controller;
  }

  void _onMapLoaded() {
    debugPrint("On map loaded");
    addImageFromAsset("assetImage", "assets/custom-icon.png");
  }

  void _onMapClick(LatLngFloor llf) {
    debugPrint("On map click $llf");
  }

  void _onFloorsChanged(List<Floor> floors) {
    debugPrint("On floors changed $floors");
  }

  void _onFloorChanged(Floor floor) {
    debugPrint("On floor changed $floor");
  }

  void _onVenueEnter(Venue venue) {
    debugPrint("on venue enter ${venue.name}");
  }
}
6
likes
30
pub points
0%
popularity

Publisher

unverified uploader

Integrate Mapwize Indoor Maps in Flutter apps

Homepage

License

BSD-2-Clause, MIT (LICENSE)

Dependencies

flutter

More

Packages that depend on mapwize