maplibre / flutter-maplibre-gl

Customizable, performant and vendor-free vector and raster maps, flutter wrapper for maplibre-native and maplibre-gl-js (fork of flutter-mapbox-gl/maps)
https://pub.dev/packages/maplibre_gl
Other
215 stars 117 forks source link

How to load cache.db properly? #321

Open mehmetkalayci opened 10 months ago

mehmetkalayci commented 10 months ago

Hello,

I downloaded a region which kept in cache.db file in assets folder. I am trying to load the cache.db file from assets (I already defined the path in yaml file).

Sometimes it works, sometimes there is a blackscreen. How to load the cache.db file properly? Part of the code is bellow;


  bool _tilesLoaded = false;

  _copyTilesIntoPlace() async {
    try {
      await installOfflineMapTiles("assets/cache.db");
    } catch (err) {
      print(err);
    }
    setState(() {
      this._tilesLoaded = true;
    });

    print("_tilesLoaded--->" + _tilesLoaded.toString());
  }

  @override
  void initState() {
    _copyTilesIntoPlace();
    super.initState();
  }

  @override
  Widget build(BuildContext context) {

    if (this._tilesLoaded) {
      // _tilesLoaded is bool set during the function _copyTilesIntoPlace
      return Scaffold(
        body: MaplibreMap(
          styleString: _mapStyleUrl(),
          myLocationEnabled: true,
          initialCameraPosition: const CameraPosition(target: LatLng(0.0, 0.0)),
          onMapCreated: _onMapCreated,
          trackCameraPosition: true,
        ),
        floatingActionButton: Padding(padding: EdgeInsets.all(20), child: actionButton),
        floatingActionButtonLocation: FloatingActionButtonLocation.centerDocked,
      );
    } else {
      return Center(
        child: new CircularProgressIndicator(),
      );
    }
  }
m0nac0 commented 10 months ago

Do you see any error messages or a stacktrace?

m0nac0 commented 10 months ago

Also, on what OS is that?