Skip to content
This repository was archived by the owner on Jun 25, 2019. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -396,6 +396,14 @@ mapView.onMapTapped
.listen((location) => print("Touched location $location"));
```

#### Receive indoor building & indoor level
```dart
mapView.onIndoorBuildingActivated.listen(
(indoorBuilding) => print("Activated indoor building $indoorBuilding"));
mapView.onIndoorLevelActivated.listen(
(indoorLevel) => print("Activated indoor level $indoorLevel"));
```

#### Receive camera change updates
```dart
mapView.onCameraChanged.listen((cameraPosition) =>
Expand Down
13 changes: 13 additions & 0 deletions android/src/main/kotlin/com/apptreesoftware/mapview/MapActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,19 @@ class MapActivity : AppCompatActivity(),
map.setOnInfoWindowClickListener { marker ->
MapViewPlugin.infoWindowTapped(marker.tag as String)
}
map.setOnIndoorStateChangeListener(object : GoogleMap.OnIndoorStateChangeListener {
override fun onIndoorBuildingFocused() {
MapViewPlugin.indoorBuildingActivated(map.focusedBuilding)
}

override fun onIndoorLevelActivated(building: IndoorBuilding?) {
if (building == null || building.activeLevelIndex < 0) {
MapViewPlugin.indoorLevelActivated(null)
} else {
MapViewPlugin.indoorLevelActivated(building.levels.get(building.activeLevelIndex))
}
}
})
map.moveCamera(CameraUpdateFactory.newCameraPosition(
MapViewPlugin.initialCameraPosition))
MapViewPlugin.onMapReady()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import android.os.Build
import com.google.android.gms.common.GoogleApiAvailability
import com.google.android.gms.maps.GoogleMap
import com.google.android.gms.maps.model.CameraPosition
import com.google.android.gms.maps.model.IndoorBuilding
import com.google.android.gms.maps.model.IndoorLevel
import com.google.android.gms.maps.model.LatLng
import io.flutter.plugin.common.MethodCall
import io.flutter.plugin.common.MethodChannel
Expand Down Expand Up @@ -154,6 +156,38 @@ class MapViewPlugin(val activity: Activity) : MethodCallHandler {
val key = registrar.lookupKeyForAsset(asset)
return assetManager.openFd(key)
}

fun indoorBuildingActivated(indoorBuilding: IndoorBuilding?) {
if (indoorBuilding == null) {
this.channel.invokeMethod("indoorBuildingActivated", null)
} else {
this.channel.invokeMethod("indoorBuildingActivated", mapOf(
"underground" to indoorBuilding.isUnderground,
"defaultIndex" to indoorBuilding.defaultLevelIndex,
"levels" to mappingIndoorLevels(indoorBuilding.levels)))
}
}

fun indoorLevelActivated(level: IndoorLevel?) {
if (level == null) {
this.channel.invokeMethod("indoorLevelActivated", null)
} else {
this.channel.invokeMethod("indoorLevelActivated", mappingIndoorLevel(level))
}
}

private fun mappingIndoorLevels(levels: List<IndoorLevel>): List<Map<String, Any>> {
val list = mutableListOf<Map<String, Any>>()
levels.forEach { level -> list.add(mappingIndoorLevel(level)) }
return list
}

private fun mappingIndoorLevel(level: IndoorLevel): Map<String, Any> {
return mapOf(
"name" to level.name,
"shortName" to level.shortName
)
}
}

override fun onMethodCall(call: MethodCall, result: Result): Unit {
Expand Down
6 changes: 6 additions & 0 deletions example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,12 @@ class _MyAppState extends State<MyApp> {
print("Info Window Tapped for ${marker.title}");
});
compositeSubscription.add(sub);
sub = mapView.onIndoorBuildingActivated.listen(
(indoorBuilding) => print("Activated indoor building $indoorBuilding"));
compositeSubscription.add(sub);
sub = mapView.onIndoorLevelActivated.listen(
(indoorLevel) => print("Activated indoor level $indoorLevel"));
compositeSubscription.add(sub);
}

_handleDismiss() async {
Expand Down
3 changes: 2 additions & 1 deletion ios/Classes/MapViewController.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,14 @@
#import <UIKit/UIKit.h>
#import <CoreLocation/CoreLocation.h>
#import <GoogleMaps/GoogleMaps/GMSMapView.h>
#import <GoogleMaps/GoogleMaps/GMSIndoorDisplay.h>

@class MapViewPlugin;
@class MapAnnotation;
@class MapPolyline;
@class MapPolygon;

@interface MapViewController : UIViewController <GMSMapViewDelegate>
@interface MapViewController : UIViewController <GMSMapViewDelegate, GMSIndoorDisplayDelegate>

- (id)initWithPlugin:(MapViewPlugin *)plugin
navigationItems:(NSArray *)items
Expand Down
9 changes: 9 additions & 0 deletions ios/Classes/MapViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ - (void)loadView {

// Creates a marker in the center of the map.
self.mapView.delegate = self;
self.mapView.indoorDisplay.delegate = self;
[self loadMapOptions];

self.mapView.mapType = self.mapViewType;
Expand Down Expand Up @@ -370,6 +371,14 @@ - (void)mapView:(GMSMapView *)mapView didDragMarker:(nonnull GMSMarker *)marker{
[self.plugin annotationDrag:marker.userData position:marker.position];
}

- (void)didChangeActiveBuilding:(GMSIndoorBuilding *)building{
[self.plugin indoorBuildingActivated:building];
}

- (void)didChangeActiveLevel:(GMSIndoorLevel *)level{
[self.plugin indoorLevelActivated:level];
}

- (CLLocationCoordinate2D) centerLocation {
return self.mapView.camera.target;
}
Expand Down
6 changes: 6 additions & 0 deletions ios/Classes/MapViewPlugin.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
@class MapViewController;

@class GMSCameraPosition;
@class GMSIndoorBuilding;
@class GMSIndoorLevel;

@interface MapViewPlugin : NSObject<FlutterPlugin>

Expand All @@ -24,6 +26,10 @@
- (void)infoWindowTapped:(NSString *)identifier;
- (void)mapTapped:(CLLocationCoordinate2D)coordinate;
- (void)cameraPositionChanged:(GMSCameraPosition *)position;
- (void)indoorBuildingActivated:(GMSIndoorBuilding *)indoorBuilding;
- (void)indoorLevelActivated:(GMSIndoorLevel *)indoorLevel;
- (NSArray<NSDictionary *> *)mappingIndoorLevels:(NSArray<GMSIndoorLevel *> *)levels;
- (NSDictionary *)mappingIndoorLevel:(GMSIndoorLevel *)level;
- (int)getMapViewType:(NSString *)mapViewTypeName;
- (NSString *)getAssetPath:(NSString *)iconPath;
@end
34 changes: 34 additions & 0 deletions ios/Classes/MapViewPlugin.m
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,40 @@ - (GMSCameraPosition *)cameraPositionFromDict:(NSDictionary *)dict {
return camera;
}

- (void)indoorBuildingActivated:(GMSIndoorBuilding *)indoorBuilding {
NSDictionary *arg = nil;
if (indoorBuilding != nil) {
arg = @{@"underground": @(indoorBuilding.underground),
@"defaultLevelIndex": @(indoorBuilding.defaultLevelIndex),
@"levels": [self mappingIndoorLevels:indoorBuilding.levels]};
}
[self.channel invokeMethod:@"indoorBuildingActivated" arguments:arg];
}

- (void)indoorLevelActivated:(GMSIndoorLevel *)indoorLevel {
NSDictionary *arg = nil;
if (indoorLevel != nil) {
arg = [self mappingIndoorLevel:indoorLevel];
}
[self.channel invokeMethod:@"indoorLevelActivated" arguments:arg];
}

- (NSArray<NSDictionary *> *)mappingIndoorLevels:(NSArray<GMSIndoorLevel *> *)levels {
if (levels == nil) {
return nil;
}
NSMutableArray* array = [NSMutableArray array];
for (GMSIndoorLevel *level in levels) {
[array addObject: [self mappingIndoorLevel:level]];
}
return array;
}

- (NSDictionary *)mappingIndoorLevel:(GMSIndoorLevel *)level {
return @{@"name": [NSString stringWithString:level.name],
@"shortName": [NSString stringWithString:level.shortName]};
}

- (int)getMapViewType:(NSString *)mapViewTypeName {
int mapType = kGMSTypeNormal;
if ([@"none" isEqualToString:mapViewTypeName]) {
Expand Down
33 changes: 33 additions & 0 deletions lib/map_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import 'dart:async';

import 'package:flutter/services.dart';
import 'package:map_view/camera_position.dart';
import 'package:map_view/indoor_building.dart';
import 'package:map_view/location.dart';
import 'package:map_view/map_options.dart';
import 'package:map_view/marker.dart';
Expand Down Expand Up @@ -45,6 +46,10 @@ class MapView {
new StreamController.broadcast();
StreamController<Marker> _infoWindowStreamController =
new StreamController.broadcast();
StreamController<IndoorBuilding> _indoorBuildingActivatedStreamController =
new StreamController.broadcast();
StreamController<IndoorLevel> _indoorLevelActivatedStreamController =
new StreamController.broadcast();

Map<String, Marker> _annotations = {};
Map<String, Polyline> _polylines = {};
Expand Down Expand Up @@ -262,6 +267,12 @@ class MapView {

Stream<Marker> get onInfoWindowTapped => _infoWindowStreamController.stream;

Stream<IndoorBuilding> get onIndoorBuildingActivated =>
_indoorBuildingActivatedStreamController.stream;

Stream<IndoorLevel> get onIndoorLevelActivated =>
_indoorLevelActivatedStreamController.stream;

Future<dynamic> _handleMethod(MethodCall call) async {
switch (call.method) {
case "onMapReady":
Expand Down Expand Up @@ -343,6 +354,28 @@ class MapView {
case "onToolbarAction":
_toolbarActionStreamController.add(call.arguments);
break;
case "indoorBuildingActivated":
if (call.arguments == null) {
_indoorBuildingActivatedStreamController.add(null);
} else {
List<IndoorLevel> levels = [];
for (var value in call.arguments["levels"]) {
levels.add(IndoorLevel(value["name"], value["shortName"]));
}
_indoorBuildingActivatedStreamController.add(new IndoorBuilding(
call.arguments["underground"],
call.arguments["defaultLevelIndex"],
levels));
}
break;
case "indoorLevelActivated":
if (call.arguments == null) {
_indoorLevelActivatedStreamController.add(null);
} else {
_indoorLevelActivatedStreamController.add(
IndoorLevel(call.arguments["name"], call.arguments["shortName"]));
}
break;
}
return new Future.value("");
}
Expand Down