Giter Site home page Giter Site logo

muskanmahajan37 / flutter_map Goto Github PK

View Code? Open in Web Editor NEW

This project forked from ketanchoyal/flutter_map

0.0 0.0 0.0 8.08 MB

A Flutter map widget inspired by Leaflet

License: BSD 3-Clause "New" or "Revised" License

Java 0.29% Objective-C 0.57% Dart 99.15%

flutter_map's Introduction

BuildStatus Pub

flutter_map

A Dart implementation of Leaflet for Flutter apps.

Usage

Add flutter_map to your pubspec:

dependencies:
  flutter_map: any # or the latest version on Pub

Configure the map using MapOptions and layer options:

  Widget build(BuildContext context) {
    return new FlutterMap(
      options: new MapOptions(
        center: new LatLng(51.5, -0.09),
        zoom: 13.0,
      ),
      layers: [
        new TileLayerOptions(
          urlTemplate: "https://api.tiles.mapbox.com/v4/"
              "{id}/{z}/{x}/{y}@2x.png?access_token={accessToken}",
          additionalOptions: {
            'accessToken': '<PUT_ACCESS_TOKEN_HERE>',
            'id': 'mapbox.streets',
          },
        ),
        new MarkerLayerOptions(
          markers: [
            new Marker(
              width: 80.0,
              height: 80.0,
              point: new LatLng(51.5, -0.09),
              builder: (ctx) =>
              new Container(
                child: new FlutterLogo(),
              ),
            ),
          ],
        ),
      ],
    );
  }

Run the example

See the example/ folder for a working example app.

To run it, in a terminal cd into the folder. Then execute ulimit -S -n 2048 (ref). Then execute flutter run with a running emulator.

Mapbox Tiles

You can use map tiles from a number of free and paid map suppliers, or you can host your own map tiles.

The example uses OpenStreetMap tiles, which are free but can be slow.

Use TileLayerOptions to configure other tile providers, such as mapbox:

Widget build(ctx) {
  return TileLayerOptions(
    urlTemplate: "https://api.mapbox.com/v4/"
        "{id}/{z}/{x}/{y}@2x.png?access_token={accessToken}",
    additionalOptions: {
      'accessToken': '<PUT_ACCESS_TOKEN_HERE>',
      'id': 'mapbox.streets',
    },
  );
}

To use, you'll need a mapbox key:

  1. Create a Mapbox account to get an API key
  2. Open leaflet_flutter_example/lib/main.dart and paste the API key into the additionalOptions map

Offline maps

Follow this guide to grab offline tiles
Once you have your map exported to .mbtiles, you can use mbtilesToPng to unpack into /{z}/{x}/{y}.png. Move this to Assets folder and add asset directories to pubspec.yaml. Minimum required fields for offline maps are:

Widget build(ctx) {
  return FlutterMap(
    options: MapOptions(
      center: LatLng(56.704173, 11.543808),
      zoom: 13.0,
      swPanBoundary: LatLng(56.6877, 11.5089),
      nePanBoundary: LatLng(56.7378, 11.6644),
    ),
    layers: [
      TileLayerOptions(
        tileProvider: AssetTileProvider(),
        urlTemplate: "assets/offlineMap/{z}/{x}/{y}.png",
      ),
    ],
  );
}

Make sure PanBoundaries are within offline map boundary to stop missing asset errors.
See the flutter_map_example/ folder for a working example.

Note that there is also FileTileProvider(), which you can use to load tiles from the filesystem.

Plugins

Roadmap

For the latest roadmap, please see the Issue Tracker

flutter_map's People

Contributors

4kssoft avatar alfanhui avatar avbk avatar avioli avatar csjames avatar escamoteur avatar ftognetto avatar ihorklimov avatar jesusrp98 avatar johnpryan avatar josh-burton avatar julianberger avatar kaetemi avatar kengu avatar ketanchoyal avatar ljaracastillo avatar lpongetti avatar lsaudon avatar manhluong avatar max053 avatar mortenboye avatar orkon avatar raimundwege avatar smasato avatar solid-software-hq avatar tomwyr avatar victor-emil avatar vinicentus avatar wmcshane avatar xqwzts avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.