Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Map running low performance Scaffold Widget #396

Closed
pvictorf opened this issue Aug 27, 2020 · 3 comments
Closed

Map running low performance Scaffold Widget #396

pvictorf opened this issue Aug 27, 2020 · 3 comments
Labels

Comments

@pvictorf
Copy link

pvictorf commented Aug 27, 2020

When I put the full map in a body: of Scaffold widget and close/open App the performance of map is very slow in a real device(Android).

However, if the map is in a Container widget work perfectly.

Flutter version: 1.20.2
Plugin version: mapbox_gl: ^0.8.0

import 'package:flutter/material.dart';
import 'package:mapbox_gl/mapbox_gl.dart';
import 'package:location/location.dart';

class FullScreenMap extends StatefulWidget {
  const FullScreenMap({Key key}) : super(key: key);

  @override
  _FullScreenMapState createState() => _FullScreenMapState();
}

class _FullScreenMapState extends State<FullScreenMap> {
  MapboxMapController mapController;
  String _mapStyle = "mapbox://styles/mapbox/streets-v11";
  MinMaxZoomPreference _minMaxZoomPreference = MinMaxZoomPreference.unbounded;
  CameraTargetBounds _cameraTargetBounds = CameraTargetBounds.unbounded;
  bool _scrollGesturesEnabled = true;
  bool _tiltGesturesEnabled = true;
  bool _zoomGesturesEnabled = true;
  bool _myLocationEnabled = true;
  bool _rotateGesturesEnabled = true;
  bool _compassEnabled = true;
  bool _trackCameraPosition = true;
  LatLng _currentLocation = LatLng(0.0, 0.0);
  LatLng _userPosition;

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

  void _getUserLocation() async {
    Location location = Location();
    PermissionStatus hasPermissions = await location.hasPermission();

    if (hasPermissions != PermissionStatus.granted) {
      hasPermissions = await location.requestPermission();
    }

    if (hasPermissions != PermissionStatus.denied) {
      var locationData = await location.getLocation();
      setState(() {
        _userPosition = LatLng(locationData.latitude, locationData.longitude);
      });
    }
  }

  void _moveCameraToUser(LatLng latLng) {
    if (mapController != null) {
      mapController.animateCamera(CameraUpdate.newLatLng(latLng));
    }
  }

  void _onMapCreated(MapboxMapController controller) {
    mapController = controller;
    mapController.setTelemetryEnabled(false);
    mapController.invalidateAmbientCache();
  }

  @override
  Widget build(BuildContext context) {
    return Container(
      child: MapboxMap(
        onMapCreated: _onMapCreated,
        initialCameraPosition:
            CameraPosition(target: _currentLocation, zoom: 14),
        myLocationTrackingMode: MyLocationTrackingMode.TrackingGPS,
        myLocationRenderMode: MyLocationRenderMode.GPS,
        myLocationEnabled: _myLocationEnabled,
        zoomGesturesEnabled: _zoomGesturesEnabled,
        tiltGesturesEnabled: _tiltGesturesEnabled,
        scrollGesturesEnabled: _scrollGesturesEnabled,
        rotateGesturesEnabled: _rotateGesturesEnabled,
        minMaxZoomPreference: _minMaxZoomPreference,
        compassEnabled: _compassEnabled,
        cameraTargetBounds: _cameraTargetBounds,
        trackCameraPosition: _trackCameraPosition,
        styleString: _mapStyle,
      ),
    );
  }
}

@AAverin
Copy link
Contributor

AAverin commented Sep 8, 2020

You should make sure there are no leaks and when you go out and back in only one instance of the map is present.

@AAverin
Copy link
Contributor

AAverin commented Sep 11, 2020

mapbox/mapbox-gl-native-ios#172

@stale
Copy link

stale bot commented Jan 14, 2022

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the stale label Jan 14, 2022
@stale stale bot closed this as completed Jan 21, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants