Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
masashiGMS committed Mar 20, 2015
1 parent c353eed commit 24c9454
Show file tree
Hide file tree
Showing 6 changed files with 91 additions and 15 deletions.
Binary file not shown.
5 changes: 4 additions & 1 deletion src/ios/GoogleMaps/GoogleMapsViewController.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
#import "PluginUtil.h"
#import "NSData+Base64.h"

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

@property (nonatomic, strong) GMSMapView* map;
@property (nonatomic, strong) UIWebView* webView;
Expand All @@ -37,4 +37,7 @@

- (void)removeObjectForKey: (NSString *)key;
- (BOOL)didTapMyLocationButtonForMapView:(GMSMapView *)mapView;

- (void) didChangeActiveBuilding: (GMSIndoorBuilding *)building;
- (void) didChangeActiveLevel: (GMSIndoorLevel *)level;
@end
40 changes: 40 additions & 0 deletions src/ios/GoogleMaps/GoogleMapsViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,9 @@ - (void)viewDidLoad
//self.map.autoresizingMask = UIViewAutoresizingNone;
self.map.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;

//indoor display
self.map.indoorDisplay.delegate = self;


BOOL isEnabled = NO;
//controls
Expand Down Expand Up @@ -646,6 +649,43 @@ -(UIImage *)loadImageFromGoogleMap:(NSString *)fileName {
}


- (void) didChangeActiveBuilding: (GMSIndoorBuilding *)building {
//Notify to the JS
NSString* jsString = @"javascript:plugin.google.maps.Map._onMapEvent('indoor_building_focused')";
[self.webView stringByEvaluatingJavaScriptFromString:jsString];
}

- (void) didChangeActiveLevel: (GMSIndoorLevel *)activeLevel {

GMSIndoorBuilding *building = self.map.indoorDisplay.activeBuilding;

NSMutableDictionary *result = [NSMutableDictionary dictionary];

NSUInteger activeLevelIndex = [building.levels indexOfObject:activeLevel];
[result setObject:[NSNumber numberWithInteger:activeLevelIndex] forKey:@"activeLevelIndex"];
[result setObject:[NSNumber numberWithInteger:building.defaultLevelIndex] forKey:@"defaultLevelIndex"];

GMSIndoorLevel *level;
NSMutableDictionary *levelInfo;
NSMutableArray *levels = [NSMutableArray array];
for (level in building.levels) {
levelInfo = [NSMutableDictionary dictionary];

[levelInfo setObject:[NSString stringWithString:level.name] forKey:@"name"];
[levelInfo setObject:[NSString stringWithString:level.shortName] forKey:@"shortName"];
[levels addObject:levelInfo];
}
[result setObject:levels forKey:@"levels"];

NSError *error;
NSData *data = [NSJSONSerialization dataWithJSONObject:result options:NSJSONWritingPrettyPrinted error:&error];

NSString *JSONstring = [[NSString alloc] initWithData:data
encoding:NSUTF8StringEncoding];
NSString *jsString = [NSString stringWithFormat:@"javascript:plugin.google.maps.Map._onMapEvent('indoor_level_activated', %@)", JSONstring];

[self.webView stringByEvaluatingJavaScriptFromString:jsString];
}



Expand Down
1 change: 1 addition & 0 deletions src/ios/GoogleMaps/Map.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,5 @@
- (void)setAllGesturesEnabled:(CDVInvokedUrlCommand*)command;
- (void)setPadding:(CDVInvokedUrlCommand*)command;
- (void)panBy:(CDVInvokedUrlCommand*)command;
- (void)getFocusedBuilding:(CDVInvokedUrlCommand*)command;
@end
31 changes: 31 additions & 0 deletions src/ios/GoogleMaps/Map.m
Original file line number Diff line number Diff line change
Expand Up @@ -470,4 +470,35 @@ - (void)setPadding:(CDVInvokedUrlCommand *)command {

[self.mapCtrl.map setPadding:padding];
}

- (void)getFocusedBuilding:(CDVInvokedUrlCommand*)command {
GMSIndoorBuilding *building = self.mapCtrl.map.indoorDisplay.activeBuilding;
if (building != nil) {
CDVPluginResult* pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK];
[self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
}
GMSIndoorLevel *activeLevel = self.mapCtrl.map.indoorDisplay.activeLevel;

NSMutableDictionary *result = [NSMutableDictionary dictionary];

NSUInteger activeLevelIndex = [building.levels indexOfObject:activeLevel];
[result setObject:[NSNumber numberWithInteger:activeLevelIndex] forKey:@"activeLevelIndex"];
[result setObject:[NSNumber numberWithInteger:building.defaultLevelIndex] forKey:@"defaultLevelIndex"];

GMSIndoorLevel *level;
NSMutableDictionary *levelInfo;
NSMutableArray *levels = [NSMutableArray array];
for (level in building.levels) {
levelInfo = [NSMutableDictionary dictionary];

[levelInfo setObject:[NSString stringWithString:level.name] forKey:@"name"];
[levelInfo setObject:[NSString stringWithString:level.shortName] forKey:@"shortName"];
[levels addObject:levelInfo];
}
[result setObject:levels forKey:@"levels"];


CDVPluginResult* pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsDictionary:result];
[self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
}
@end
29 changes: 15 additions & 14 deletions www/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,28 +4,29 @@
<meta name="viewport" content="user-scalable=no, initial-scale=1, maximum-scale=1, minimum-scale=1, width=device-width, height=device-height" />
<meta charset="utf-8" />
<title>Google Maps Plugin for Cordova</title>
<link rel="stylesheet" type="text/css" href="css/animate.css" />
<link href="css/prettify.css" type="text/css" rel="stylesheet" />
<link href="css/app.css" type="text/css" rel="stylesheet" />
<script type="text/javascript" src="cordova.js"></script>
<script type="text/javascript" src="js/prettify.js"></script>
<script type="text/javascript" src="js/jquery.min.js"></script>
<script type="text/javascript" src="js/jquery.fittext.js"></script>
<script type="text/javascript" src="js/example.js"></script>
<script type="text/javascript">
var map;
function onDeviceReady() {
map = plugin.google.maps.Map.getMap($("map_canvas")[0]);
map.on("map_ready", onMapReady);
map.on("indoor_level_activated", onIndoorLevelActived);
}
function onMapReady() {
}
function onIndoorLevelActived(building) {
console.log(building);
}
$(document).one("deviceready", onDeviceReady);
</script>
<style type="text/css">
html,body {
html,body, #map_canvas {
width: 100%;
height: 100%;
margin: 0;
padding: 0;
}
#map_canvas {
width: 70%;
height: 70%;
margin: 15%;
padding: 0;
border: 1px solid red;
}
</style>
</head>
<body>
Expand Down

0 comments on commit 24c9454

Please sign in to comment.