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
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,8 @@ You can refer to the example project if you run into any issues with these steps

#### Show a map ( with a toolbar )
mapView.show(
new MapOptions(
new MapOptions(
mapViewType: MapViewType.MAP_TYPE_SATELLITE,
showUserLocation: true,
initialCameraPosition: new CameraPosition(
new Location(45.5235258, -122.6732493), 14.0),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ class MapActivity : AppCompatActivity(),
override fun onMapReady(map: GoogleMap) {
googleMap = map

map.setMapType(MapViewPlugin.mapViewType)

if (MapViewPlugin.showUserLocation) {
if (ContextCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION)
!= PackageManager.PERMISSION_GRANTED) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,17 @@ import io.flutter.plugin.common.MethodChannel
import io.flutter.plugin.common.MethodChannel.MethodCallHandler
import io.flutter.plugin.common.MethodChannel.Result
import io.flutter.plugin.common.PluginRegistry.Registrar
import com.google.android.gms.maps.GoogleMap


class MapViewPlugin(val activity: Activity) : MethodCallHandler {
val mapTypeMapping: HashMap<String, Int> = hashMapOf(
"none" to GoogleMap.MAP_TYPE_NONE,
"normal" to GoogleMap.MAP_TYPE_NORMAL,
"satellite" to GoogleMap.MAP_TYPE_SATELLITE,
"terrain" to GoogleMap.MAP_TYPE_TERRAIN,
"hybrid" to GoogleMap.MAP_TYPE_HYBRID
)

companion object {
lateinit var channel: MethodChannel
Expand All @@ -24,7 +32,7 @@ class MapViewPlugin(val activity: Activity) : MethodCallHandler {
lateinit var initialCameraPosition: CameraPosition
var mapActivity: MapActivity? = null
val REQUEST_GOOGLE_PLAY_SERVICES = 1000

var mapViewType: Int = GoogleMap.MAP_TYPE_NORMAL

@JvmStatic
fun registerWith(registrar: Registrar): Unit {
Expand Down Expand Up @@ -95,6 +103,12 @@ class MapViewPlugin(val activity: Activity) : MethodCallHandler {
toolbarActions = getToolbarActions(call.argument<List<Map<String, Any>>>("actions"))
showUserLocation = mapOptions["showUserLocation"] as Boolean
mapTitle = mapOptions["title"] as String

if (mapOptions["mapViewType"] != null) {
var mappedMapType: Int? = mapTypeMapping.get(mapOptions["mapViewType"]);
if (mappedMapType != null) mapViewType = mappedMapType as Int;
}

val intent = Intent(activity, MapActivity::class.java)
activity.startActivity(intent)
result.success(true)
Expand Down
2 changes: 2 additions & 0 deletions example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import 'package:map_view/map_options.dart';
import 'package:map_view/map_view.dart';
import 'package:map_view/marker.dart';
import 'package:map_view/toolbar_action.dart';
import 'package:map_view/map_view_type.dart';

void main() {
MapView.setApiKey("<your_api_key>");
Expand Down Expand Up @@ -65,6 +66,7 @@ class _MyAppState extends State<MyApp> {
showMap() {
mapView.show(
new MapOptions(
mapViewType: MapViewType.satellite,
showUserLocation: true,
initialCameraPosition: new CameraPosition(
new Location(45.5235258, -122.6732493), 14.0),
Expand Down
4 changes: 4 additions & 0 deletions ios/Classes/MapViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ @interface MapViewController ()
@property (nonatomic, retain) NSArray *navigationItems;
@property (nonatomic, retain) GMSCameraPosition *initialCameraPosition;
@property (nonatomic, retain) NSMutableDictionary *markerIDLookup;
@property (nonatomic, assign) int mapViewType;
@end

@implementation MapViewController
Expand All @@ -33,6 +34,7 @@ - (id)initWithPlugin:(MapViewPlugin *)plugin
self.initialCameraPosition = cameraPosition;
self.markerIDLookup = [NSMutableDictionary dictionary];
self.title = plugin.mapTitle;
self.mapViewType = plugin.mapViewType;
}
return self;
}
Expand Down Expand Up @@ -71,6 +73,8 @@ - (void)loadView {
if (self._locationEnabled) {
[self monitorLocationChanges];
}

self.mapView.mapType = self.mapViewType;
[self.plugin onMapReady];
}

Expand Down
2 changes: 2 additions & 0 deletions ios/Classes/MapViewPlugin.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,11 @@
@property (nonatomic, assign) FlutterMethodChannel *channel;
@property (nonatomic, retain) MapViewController *mapViewController;
@property (nonatomic, retain) NSString *mapTitle;
@property (nonatomic, assign) int mapViewType;
- (void)onMapReady;
- (void)locationDidUpdate:(CLLocation *)location;
- (void)annotationTapped:(NSString *)identifier;
- (void)mapTapped:(CLLocationCoordinate2D)coordinate;
- (void)cameraPositionChanged:(GMSCameraPosition *)position;
- (int)getMapViewType:(NSString *)mapViewTypeName;
@end
26 changes: 26 additions & 0 deletions ios/Classes/MapViewPlugin.m
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,13 @@ - (void)handleMethodCall:(FlutterMethodCall *)call result:(FlutterResult)result
NSDictionary *mapOptions = args[@"mapOptions"];
NSDictionary *cameraDict = mapOptions[@"cameraPosition"];
self.mapTitle = mapOptions[@"title"];

if (mapOptions[@"mapViewType"] != (id) [NSNull null]) {
NSString *mapViewTypeName = mapOptions[@"mapViewType"];
int mapType = [self getMapViewType:mapViewTypeName];
self.mapViewType = mapType;
}

MapViewController *vc = [[MapViewController alloc] initWithPlugin:self
navigationItems:[self buttonItemsFromActions:args[@"actions"]]
cameraPosition:[self cameraPositionFromDict:cameraDict]];
Expand Down Expand Up @@ -155,4 +162,23 @@ - (GMSCameraPosition *)cameraPositionFromDict:(NSDictionary *)dict {
return camera;
}

- (int)getMapViewType:(NSString *)mapViewTypeName {
int mapType = kGMSTypeNormal;
if ([@"none" isEqualToString:mapViewTypeName]) {
mapType = kGMSTypeNone;
}
else if ([@"satellite" isEqualToString:mapViewTypeName]) {
mapType = kGMSTypeSatellite;
}
else if ([@"terrain" isEqualToString:mapViewTypeName]) {
mapType = kGMSTypeTerrain;
}
else if ([@"hybrid" isEqualToString:mapViewTypeName]) {
mapType = kGMSTypeHybrid;
}
else if ([@"none" isEqualToString:mapViewTypeName]) {
mapType = kGMSTypeNone;
}
return mapType;
}
@end
30 changes: 28 additions & 2 deletions lib/map_options.dart
Original file line number Diff line number Diff line change
@@ -1,23 +1,49 @@
import 'package:map_view/camera_position.dart';
import 'package:map_view/location.dart';
import 'package:map_view/map_view_type.dart';

class MapOptions {
final bool showUserLocation;
final CameraPosition initialCameraPosition;
final String title;
static const CameraPosition _defaultCamera =
const CameraPosition(const Location(45.5329661, -122.7059508), 12.0);
MapViewType mapViewType;

MapOptions(
{this.showUserLocation: false,
this.initialCameraPosition: _defaultCamera,
this.title: ""});
this.title: "",
this.mapViewType: MapViewType.normal});

Map<String, dynamic> toMap() {
return {
"showUserLocation": showUserLocation,
"cameraPosition": initialCameraPosition.toMap(),
"title": title
"title": title,
"mapViewType" : getMapTypeName(mapViewType)
};
}

String getMapTypeName(MapViewType mapType) {
String mapTypeName = "normal";
switch(mapType) {
case MapViewType.none:
mapTypeName = "none";
break;
case MapViewType.satellite:
mapTypeName = "satellite";
break;
case MapViewType.terrain:
mapTypeName = "terrain";
break;
case MapViewType.hybrid:
mapTypeName = "hybrid";
break;
case MapViewType.normal:
mapTypeName = "normal";
break;
}
return mapTypeName;
}
}
3 changes: 3 additions & 0 deletions lib/map_view_type.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@

enum MapViewType { none, normal, satellite, terrain, hybrid }