Wemap Flutter SDK

Wemap

New home for Wemap Flutter SDKs

Getting Started

A Flutter plugin to display wemap's map. For the Android and iOS integration, we use wemap-sdk-android, wemap-sdk-ios.

To fully get started with the SDK, see the official documentation.

Development

To develop Wemap software in this repository, ensure that you have at least the following software:

Installation

The SDK is published on pub.dev.

Add the dependency

In your app pubspec.yaml:

dependencies:
  wemap_sdk_flutter: ^0.29.0

Or:

flutter pub add wemap_sdk_flutter

Then:

flutter pub get

You will need a Map ID and token from Wemap to display a map — contact Wemap if you do not have them yet.

Android

  • Add the Wemap Maven repository to the repositories block inside allprojects in android/build.gradle:
allprojects {
    repositories {
        google()
        mavenCentral()
        // Wemap Maven repository
        maven {
            url "https://s3.eu-west-1.amazonaws.com/mobile.getwemap.com/releases/android"
        }
    }
}
  • Add the minSdkVersion to local.properties:
flutter.minSdkVersion=24
  • In app/build.gradle, set minSdkVersion inside defaultConfig:
minSdkVersion localProperties.getProperty('flutter.minSdkVersion').toInteger()
  • For VPS / location, add to AndroidManifest.xml:
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.CAMERA" />

iOS

The plugin supports Swift Package Manager (SPM) and CocoaPods. Prefer SPM when you can.

Enable SPM for your Flutter app (per project):

# pubspec.yaml
flutter:
  config:
    enable-swift-package-manager: true

Or globally:

flutter config --enable-swift-package-manager

Set the iOS deployment target to 13.0 or higher (Xcode / Podfile platform :ios if you still use one). Then run flutter pub get and build as usual. No Wemap CocoaPods sources or extra gems are required for this path.

Option B — CocoaPods
  • At the top of ios/Podfile:
source 'https://cdn.cocoapods.org/'
source 'https://github.com/wemap/cocoapods-specs.git'
  • Minimum deployment target:
platform :ios, '13.0'
  • In post_install, set BUILD_LIBRARY_FOR_DISTRIBUTION:
post_install do |installer|
  installer.pods_project.targets.each do |target|
    flutter_additional_ios_build_settings(target)
    target.build_configurations.each do |config|
      config.build_settings['BUILD_LIBRARY_FOR_DISTRIBUTION'] = 'YES'
    end
  end
end
  • Install gems (project Gemfile or manually):
source 'https://rubygems.org'

gem 'cocoapods'
gem 'cocoapods-s3-download'
bundle install
cd ios && pod install

When upgrading an existing install, use pod update instead of pod install.

Permissions (SPM and CocoaPods)

For VPS / location, add to Info.plist:

<key>NSLocationWhenInUseUsageDescription</key>
<string></string>
<key>NSCameraUsageDescription</key>
<string></string>

And in the Podfile post_install block (needed by permission_handler):

config.build_settings['GCC_PREPROCESSOR_DEFINITIONS'] ||= [
  '$(inherited)',
  'PERMISSION_CAMERA=1',
  'PERMISSION_LOCATION=1',
]

Usage

  • You can simply add the WemapMap widget as follow:
import 'package:flutter/material.dart';
import 'package:wemap_sdk_flutter/wemap_sdk_flutter.dart';

void main() {
  runApp(const MyHomePage(
    title: 'wemap sample',
  ));
}

class MyHomePage extends StatelessWidget {
  final String title;

  const MyHomePage({super.key, required this.title});

  void _onMapReady(MapData mapData, MapManager livemapManager) {
    // what ever to do, the map is ready
  }

  void _onBuildingFocusChanged(Building? building) {
    // print("on Building focus changed");
  }

  void _onActiveLevelChanged(Building building, Level level) {
    // print("on active level changed");
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
        home: Scaffold(
            appBar: AppBar(title: Text(title)),
            body: Container(
                constraints: const BoxConstraints.expand(),
                child: WemapMap(
                  options: MapOptions(
                      mapID: mapID, token: token, environment: Environment.PROD, locationSource: LocationSource.GPS),
                  onMapReady: _onMapReady,
                  onActiveLevelChanged: _onActiveLevelChanged,
                  onBuildingFocusChanged: _onBuildingFocusChanged,
                ))));
  }
}

Offline

For offline mode, you need to provide a full file path to the pack data ZIP file via packDataPath in MapOptions. There are two ways to do this:

Use PackDataManager.downloadPackData(mapID) to download pack data for a given map. The returned PackData contains a filePath you can pass to packDataPath:

final packData = await PackDataManager.downloadPackData(mapID);

MapOptions(
  mapID: mapID,
  token: token,
  environment: Environment.PROD,
  offlineMode: true,
  packDataPath: packData.filePath,
)

You can also check for updates with PackDataManager.isNewPackDataAvailable(mapID, packData.eTag).

Option 2: Use bundled pack data from assets

Add the offline ZIP file in example/assets and declare it in pubspec.yaml:

  assets:
    - assets/packdata.zip

The SDK expects a file path, so you must copy the asset to a temporary directory first. You'll need the path_provider package in your pubspec.yaml:

import 'dart:io';
import 'package:flutter/services.dart';
import 'package:path_provider/path_provider.dart';

Future<String> _getAssetPackDataPath(String assetPath) async {
  final dir = await getTemporaryDirectory();
  final fileName = assetPath.split('/').last;
  final file = File('${dir.path}/$fileName');
  if (!await file.exists()) {
    final bytes = await rootBundle.load(assetPath);
    await file.writeAsBytes(bytes.buffer.asUint8List());
  }
  return file.path;
}

// Usage
final packDataPath = await _getAssetPackDataPath('assets/packdata.zip');

MapOptions(
  mapID: xxx,
  token: xxx,
  environment: Environment.PROD,
  offlineMode: true,
  packDataPath: packDataPath,
)

Shared raster tiles (optional)

If you have multiple offline data packs (e.g., a ZIP file per language) and use raster tiles, you can specify a single raster ZIP file to be shared among the packs, reducing storage. Add it to assets in pubspec.yaml and use rasterZipFileName:

  assets:
    - assets/packdata.zip
    - assets/raster-tiles.zip
MapOptions(
  // ...
  offlineMode: true,
  packDataPath: packDataPath,
  rasterZipFileName: "raster-tiles.zip",
)

Libraries

wemap_sdk_flutter