• Stars
    star
    210
  • Rank 187,585 (Top 4 %)
  • Language
    Dart
  • License
    Other
  • Created over 3 years ago
  • Updated 4 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Customizable, performant and vendor-free vector and raster maps, flutter wrapper for maplibre-native and maplibre-gl-js (fork of flutter-mapbox-gl/maps)

Flutter Maplibre GL

Flutter CI Generate docs

⚠️ Current notice: the repository has been transferred to the @maplibre organization. You shouldn't see any negative effects, as GitHub automatically redirects references from the old URL to the new URL. Please see #221 for more information.

This Flutter plugin allows to show embedded interactive and customizable vector maps as a Flutter widget.

For the Android and iOS integration, we use maplibre-gl-native. For web, we rely on maplibre-gl-js. This project only supports a subset of the API exposed by these libraries.

This project is a fork of https://github.com/tobrun/flutter-mapbox-gl, replacing its usage of Mapbox GL libraries with the open source Maplibre GL libraries.

Please note that this project is community driven and is not affiliated with the company Mapbox.
It does use some of their amazing open source libraries/tools, though. Thank you, Mapbox, for all the open-source work you do!

Using the plugin in your project

This project is not yet available on pub.dev. You can use it by referencing it in your pubspec.yaml like this:

dependencies:
    ...
    maplibre_gl:
      git:
        url: https://github.com/maplibre/flutter-maplibre-gl.git
        ref: main

This will get you the very latest changes from the main branch. You can replace main with the name of the latest release to get a more stable version.

Compared to flutter-mapbox-gl, the only breaking API changes are:

  • MapboxMap <--> MaplibreMap
  • MapboxMapController <--> MaplibreMapController

Documentation

Documentation is available on the docs branch in the doc/api folder and automatically updated on each push to the main branch. You can easily preview the documentation / API reference here.

Please visit https://github.com/maplibre/maplibre-gl-js and https://github.com/maplibre/maplibre-gl-native for more information about the Maplibre libraries.

iOS

To use this plugin with iOS, you need to add the source repository and 2 additional pods to your Podfile, as shown in the example app: https://github.com/maplibre/flutter-maplibre-gl/blob/main/example/ios/Podfile

source 'https://cdn.cocoapods.org/'
source 'https://github.com/m0nac0/flutter-maplibre-podspecs.git'

pod 'MapLibre'
pod 'MapLibreAnnotationExtension'

Web

Include the following JavaScript and CSS files in the <head> of the web/index.html file.

<script src='https://unpkg.com/maplibre-gl@latest/dist/maplibre-gl.js'></script>
<link href='https://unpkg.com/maplibre-gl@latest/dist/maplibre-gl.css' rel='stylesheet' />

Supported API

Feature Android iOS Web
Style
Camera
Gesture
User Location
Symbol
Circle
Line
Fill

Map Styles

Map styles can be supplied by setting the styleString in the MapOptions. The following formats are supported:

  1. Passing the URL of the map style. This should be a custom map style served remotely using a URL that start with 'http(s)://'
  2. Passing the style as a local asset. Create a JSON file in the assets and add a reference in pubspec.yml. Set the style string to the relative path for this asset in order to load it into the map.
  3. Passing the style as a local file. create an JSON file in app directory (e.g. ApplicationDocumentsDirectory). Set the style string to the absolute path of this JSON file.
  4. Passing the raw JSON of the map style. This is only supported on Android.

Tile sources requiring an API key

If your tile source requires an API key, we recommend directly specifying a source url with the API key included. For example:

https://tiles.example.com/{z}/{x}/{y}.vector.pbf?api_key={your_key}

Location features

Android

Add the ACCESS_COARSE_LOCATION or ACCESS_FINE_LOCATION permission in the application manifest android/app/src/main/AndroidManifest.xml to enable location features in an Android application:

<manifest ...
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />

Starting from Android API level 23 you also need to request it at runtime. This plugin does not handle this for you. The example app uses the flutter 'location' plugin for this.

iOS

To enable location features in an iOS application:

If you access your users' location, you should also add the following key to ios/Runner/Info.plist to explain why you need access to their location data:

xml ...
    <key>NSLocationWhenInUseUsageDescription</key>
    <string>[Your explanation here]</string>

A possible explanation could be: "Shows your location on the map".

Getting Help

  • Need help with your code?: Check the discussions on this repo or open a new one. Or look for previous questions on the #maplibre tag — or ask a new question.
  • Have a bug to report? Open an issue. If possible, include a full log and information which shows the issue.
  • Have a feature request? Open an issue. Tell us what the feature should do and why you want the feature.

Running in GitHub Codespaces

When you open this project in GitHub Codespaces, you can run the example app on web with the command flutter run -d web-server --web-hostname=0.0.0.0

Codespaces should automatically take care of the necessary port forwarding, so that you can view the running web app on your local device or in a new tab.

Please note: the Docker image used to setup the Codespace is from CirrusCI and sets the Git username and email to CirrusCI default values. You should set these correctly, if you plan on committing from the Codespace.

Fixing common issues

Avoid Android UnsatisfiedLinkError

Update buildTypes in android\app\build.gradle

buildTypes {
    release {
        // other configs
        ndk {
            abiFilters 'armeabi-v7a','arm64-v8a','x86_64', 'x86'
        }
    }
}

iOS app crashes when using location based features

Please include the NSLocationWhenInUseUsageDescription as described here

Layer is not displayed on IOS, but no error

Have a look in your LayerProperties object, if you supply a lineColor argument, (or any color argument) the issue might come from here. Android supports the following format : 'rgba(192, 192, 255, 1.0)', but on iOS, this doesn't work!

You have to have the color in the following format : #C0C0FF

iOS crashes with error: 'NSInvalidArgumentException', reason: 'Invalid filter value: filter property must be a string'

Check if one of your expression is : ["!has", "value"]. Android support this format, but iOS does not. You can replace your expression with : ["!",["has", "value"] ] which works both in Android and iOS.

Note : iOS will display the error : NSPredicate: Use of 'mgl_does:have:' as an NSExpression function is forbidden, but it seems like the expression still works well.

Contributing

Feedback and contributions are very welcome!

More Repositories

1

maplibre-gl-js

MapLibre GL JS - Interactive vector tile maps in the browser
TypeScript
6,404
star
2

martin

Blazing fast and lightweight PostGIS, MBtiles and PMtiles tile server, tile generation, and mbtiles tooling.
Rust
2,231
star
3

maputnik

An open source visual editor for the 'MapLibre Style Specification'
TypeScript
2,094
star
4

maplibre-rs

Experimental Maps for Web, Mobile and Desktop
Rust
1,343
star
5

maplibre-native

MapLibre Native - Interactive vector tile maps for iOS, Android and other platforms.
C++
1,048
star
6

awesome-maplibre

A collection of awesome things that use or support MapLibre!
378
star
7

maplibre-react-native

A MapLibre react native module for creating custom maps
Java
209
star
8

maplibre-tile-spec

Next generation vector tiles format
Java
171
star
9

font-maker

Web app to convert font files into fontstacks for MapLibre GL
TypeScript
161
star
10

maplibre-gl-leaflet

This is a binding from MapLibre GL JS to the familiar Leaflet API.
JavaScript
123
star
11

maplibre-navigation-android

Maplibre Navigation SDK for Android
Java
91
star
12

demotiles

Demo vector tiles and map style for web, helloworld and CI tests @MapLibre. Hosted directly on GitHub Pages, serverless, no keys.
HTML
74
star
13

maplibre

Documents that span across multiple MapLibre projects
73
star
14

ngx-maplibre-gl

Angular binding of maplibre-gl
TypeScript
73
star
15

maplibre-gl-directions

A plugin to show routing directions on a MapLibre GL JS map
TypeScript
72
star
16

maplibre-style-spec

MapLibre Style Specification & Utilities
TypeScript
66
star
17

mbtileserver-rs

Deprecated mbtiles server in Rust. Use Martin tile server instead.
Rust
61
star
18

maplibre-gl-native-distribution

MapLibre Native for iOS distributed via the Swift Package Manager.
Swift
51
star
19

maplibre-gl-inspect

Maplibre GL Inspect adds an inspect control to maplibre-gl-js to view all features of the vector sources and allows hovering over features to see their properties.
TypeScript
39
star
20

maplibre-native-qt

MapLibre Native Qt Bindings and Qt Location Plugin
C++
38
star
21

maplibre-navigation-ios

MapLibre Navigation SDK for iOS
Swift
36
star
22

maplibre-navigation-android-legacy

Legacy MapLibre Navigation SDK for Android
Java
33
star
23

maplibre-gl-compare

Swipe and sync between two maps
JavaScript
32
star
24

maplibre-gl-js-docs

Deprecated - Docs are in the /docs folder of the maplibre-gl-js repo.
JavaScript
23
star
25

maplibre-plugins-android

MapLibre Native for Android Plugins
Java
22
star
26

maplibre-java

MapLibre Native Android utilities
Java
16
star
27

maplibre.github.io

HTML
13
star
28

maplibre-native-base

MapLibre Native Base C++ Libraries
C++
4
star
29

maplibre-native-android-examples

MapLibre Native Android Examples
3
star
30

workshop

HTML
2
star
31

mvt-cpp

C++ library for decoding MVT files
C++
2
star
32

martin-landing-page

JavaScript
1
star
33

maplibre-gestures-android

The MapLibre Gestures for Android library makes it easy to detect and handle user gestures on an Android device.
Java
1
star
34

homebrew-martin

Homebrew for Martin
Ruby
1
star
35

repo-stats

A repository to get statistics on other maplibre repos
1
star