Skip to content

Commit 37adb10

Browse files
Merge branch 'master' into master
2 parents 0e2ae5b + 480acb7 commit 37adb10

File tree

7 files changed

+285
-117
lines changed

7 files changed

+285
-117
lines changed

README.md

Lines changed: 138 additions & 114 deletions
Large diffs are not rendered by default.

demo/app/main-page.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,8 +245,18 @@ function onCameraMove(args) {
245245
console.log("Camera moving: "+JSON.stringify(args.camera));
246246
}
247247

248+
function onIndoorBuildingFocused(args) {
249+
console.log("Building focus changed: " + JSON.stringify(args.indoorBuilding));
250+
}
251+
252+
function onIndoorLevelActivated(args) {
253+
console.log("Indoor level changed: " + JSON.stringify(args.activateLevel));
254+
}
255+
248256
exports.onMapReady = onMapReady;
249257
exports.onCoordinateTapped = onCoordinateTapped;
250258
exports.onMarkerEvent = onMarkerEvent;
251259
exports.onCameraChanged = onCameraChanged;
252260
exports.onCameraMove = onCameraMove;
261+
exports.onIndoorBuildingFocused = onIndoorBuildingFocused;
262+
exports.onIndoorLevelActivated = onIndoorLevelActivated;

demo/app/main-page.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
markerEndDragging="onMarkerEvent" markerDrag="onMarkerEvent"
88
markerInfoWindowTapped="onMarkerEvent" coordinateTapped="onCoordinateTapped"
99
cameraChanged="onCameraChanged"
10+
indoorBuildingFocused="onIndoorBuildingFocused"
11+
indoorLevelActivated="onIndoorLevelActivated"
1012
cameraMove="onCameraMove">
1113
<maps:mapView.infoWindowTemplate>
1214
<StackLayout orientation="vertical" width="200" height="150" >

src/map-view-common.ts

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import {
22
MapView, Position, Marker, Shape, Polyline, Polygon, Projection,
33
Circle, Camera, MarkerEventData, ShapeEventData, VisibleRegion,
4-
CameraEventData, PositionEventData, Bounds, Style, UISettings
4+
CameraEventData, PositionEventData, Bounds, Style, UISettings, IndoorBuilding, IndoorLevel,
5+
IndoorLevelActivatedEventData, BuildingFocusedEventData
56
} from "./map-view";
67
import { Point, View, Template, KeyedTemplate } from "tns-core-modules/ui/core/view";
78
import { Image } from "tns-core-modules/ui/image";
@@ -162,7 +163,7 @@ export abstract class MapViewBase extends View implements MapView {
162163
}
163164
return undefined;
164165
}
165-
}
166+
};
166167
public _infoWindowTemplates = new Array<KeyedTemplate>();
167168

168169
public projection: Projection;
@@ -181,6 +182,8 @@ export abstract class MapViewBase extends View implements MapView {
181182
public static cameraChangedEvent: string = "cameraChanged";
182183
public static cameraMoveEvent: string = "cameraMove";
183184
public static myLocationTappedEvent: string = "myLocationTapped";
185+
public static indoorBuildingFocusedEvent: string = "indoorBuildingFocused";
186+
public static indoorLevelActivatedEvent: string = "indoorLevelActivated";
184187

185188
public get gMap() {
186189
return this._gMap;
@@ -352,6 +355,16 @@ export abstract class MapViewBase extends View implements MapView {
352355
notifyMyLocationTapped() {
353356
this.notify({ eventName: MapViewBase.myLocationTappedEvent, object: this });
354357
}
358+
359+
notifyBuildingFocusedEvent(indoorBuilding: IndoorBuilding) {
360+
let args: BuildingFocusedEventData = { eventName: MapViewBase.indoorBuildingFocusedEvent, object: this, indoorBuilding: indoorBuilding };
361+
this.notify(args);
362+
}
363+
364+
notifyIndoorLevelActivatedEvent(activateLevel: IndoorLevel) {
365+
let args: IndoorLevelActivatedEventData = { eventName: MapViewBase.indoorLevelActivatedEvent, object: this, activateLevel: activateLevel };
366+
this.notify(args);
367+
}
355368
}
356369

357370
export const infoWindowTemplateProperty = new Property<MapViewBase, string | Template>({ name: "infoWindowTemplate" });

src/map-view.android.ts

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import { Image } from "tns-core-modules/ui/image";
1111
import { Color } from "tns-core-modules/color";
1212
import { Point } from "tns-core-modules/ui/core/view";
1313
import imageSource = require("tns-core-modules/image-source");
14+
import {IndoorLevel} from "./map-view";
1415

1516
export * from "./map-view-common";
1617

@@ -133,6 +134,44 @@ export class MapView extends MapViewBase {
133134
onMyLocationButtonClick: () => {
134135
owner.notifyMyLocationTapped();
135136

137+
return false;
138+
},
139+
}));
140+
141+
gMap.setOnIndoorStateChangeListener(new com.google.android.gms.maps.GoogleMap.OnIndoorStateChangeListener({
142+
onIndoorBuildingFocused: () => {
143+
const buildingFocused = gMap.getFocusedBuilding();
144+
let data = null;
145+
if (buildingFocused) {
146+
const levels = [];
147+
let count = 0;
148+
while (count < buildingFocused.getLevels().size()) {
149+
levels.push(
150+
{
151+
name: buildingFocused.getLevels().get(count).getName(),
152+
shortName: buildingFocused.getLevels().get(count).getShortName(),
153+
}
154+
);
155+
count += 1;
156+
}
157+
data = {
158+
defaultLevelIndex: buildingFocused.getDefaultLevelIndex(),
159+
levels: levels,
160+
isUnderground: buildingFocused.isUnderground(),
161+
};
162+
163+
}
164+
owner.notifyBuildingFocusedEvent(data);
165+
166+
return false;
167+
},
168+
onIndoorLevelActivated: (gmsIndoorBuilding) => {
169+
const level = gmsIndoorBuilding.getLevels().get(gmsIndoorBuilding.getActiveLevelIndex());
170+
owner.notifyIndoorLevelActivatedEvent({
171+
name: level.getName(),
172+
shortName: level.getShortName(),
173+
});
174+
136175
return false;
137176
}
138177
}));
@@ -398,7 +437,7 @@ export class MapView extends MapViewBase {
398437
}
399438

400439
removeAllMarkers() {
401-
if(!this._markers || !this.gMap) return null;
440+
if(!this._markers || !this.gMap || !this._markers.length) return null;
402441
this._markers.forEach(marker => {
403442
this._unloadInfoWindowContent(marker);
404443
marker.android.remove();

src/map-view.d.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,17 @@ import { Image } from "tns-core-modules/ui/image";
44
import { Color } from "tns-core-modules/color";
55
import { EventData } from "tns-core-modules/data/observable";
66

7+
export class IndoorLevel {
8+
public name: string;
9+
public shortName: string;
10+
}
11+
12+
export class IndoorBuilding {
13+
public defaultLevelIndex: number;
14+
public levels: IndoorLevel[];
15+
public isUnderground: boolean;
16+
}
17+
718
export class Camera {
819
public latitude: number;
920
public longitude: number;
@@ -265,3 +276,11 @@ export interface CameraEventData extends EventData {
265276
export interface PositionEventData extends EventData {
266277
position: Position;
267278
}
279+
280+
export interface BuildingFocusedEventData extends EventData {
281+
indoorBuilding: IndoorBuilding;
282+
}
283+
284+
export interface IndoorLevelActivatedEventData extends EventData {
285+
activateLevel: IndoorLevel;
286+
}

src/map-view.ios.ts

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,62 @@ export * from "./map-view-common";
1515

1616
declare function UIEdgeInsetsMake(...params: any[]): any;
1717

18+
class IndoorDisplayDelegateImpl extends NSObject implements GMSIndoorDisplayDelegate {
19+
20+
public static ObjCProtocols = [GMSIndoorDisplayDelegate];
21+
22+
private _owner: WeakRef<MapView>;
23+
24+
public static initWithOwner(owner: WeakRef<MapView>): IndoorDisplayDelegateImpl {
25+
let handler = <IndoorDisplayDelegateImpl>IndoorDisplayDelegateImpl.new();
26+
handler._owner = owner;
27+
return handler;
28+
}
29+
30+
public didChangeActiveBuilding(indoorBuilding: GMSIndoorBuilding): void {
31+
let owner = this._owner.get();
32+
if (owner) {
33+
let data = null;
34+
if (indoorBuilding) {
35+
const levels = [];
36+
let count = 0;
37+
38+
while (count < indoorBuilding.levels.count) {
39+
levels.push(
40+
{
41+
name: indoorBuilding.levels[count].name,
42+
shortName: indoorBuilding.levels[count].shortName,
43+
}
44+
);
45+
count += 1;
46+
}
47+
48+
data = {
49+
defaultLevelIndex: indoorBuilding.defaultLevelIndex,
50+
levels: levels,
51+
isUnderground: indoorBuilding.underground,
52+
};
53+
}
54+
owner.notifyBuildingFocusedEvent(data);
55+
}
56+
}
57+
58+
public didChangeActiveLevel(activateLevel: GMSIndoorLevel): void {
59+
let owner = this._owner.get();
60+
if (owner) {
61+
let data = null;
62+
if (activateLevel) {
63+
data = {
64+
name: activateLevel.name,
65+
shortName: activateLevel.shortName,
66+
};
67+
}
68+
owner.notifyIndoorLevelActivatedEvent(data);
69+
}
70+
}
71+
}
72+
73+
1874
class MapViewDelegateImpl extends NSObject implements GMSMapViewDelegate {
1975

2076
public static ObjCProtocols = [GMSMapViewDelegate];
@@ -217,29 +273,34 @@ export class MapView extends MapViewBase {
217273
protected _markers: Array<Marker> = new Array<Marker>();
218274

219275
private _delegate: MapViewDelegateImpl;
276+
private _indoorDelegate:IndoorDisplayDelegateImpl;
220277

221278
constructor() {
222279
super();
223280

224281
this.nativeView = GMSMapView.mapWithFrameCamera(CGRectZero, this._createCameraPosition());
225282
this._delegate = MapViewDelegateImpl.initWithOwner(new WeakRef(this));
283+
this._indoorDelegate = IndoorDisplayDelegateImpl.initWithOwner(new WeakRef(this));
226284
this.updatePadding();
227285
}
228286

229287
public onLoaded() {
230288
super.onLoaded();
231289
this.nativeView.delegate = this._delegate;
290+
this.nativeView.indoorDisplay.delegate = this._indoorDelegate;
232291
this.notifyMapReady();
233292
}
234293

235294
public onUnloaded() {
236295
this.nativeView.delegate = null;
296+
this.nativeView.indoorDisplay.delegate = null;
237297
super.onUnloaded();
238298
}
239299

240300
public disposeNativeView() {
241301
this._markers = null;
242302
this._delegate = null;
303+
this._indoorDelegate=null;
243304
super.disposeNativeView();
244305
GC();
245306
};

0 commit comments

Comments
 (0)