Skip to content

Commit a086010

Browse files
committed
feat(android): Add indoor events for Android
1 parent 0092aeb commit a086010

File tree

3 files changed

+73
-2
lines changed

3 files changed

+73
-2
lines changed

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;
@@ -349,6 +352,16 @@ export abstract class MapViewBase extends View implements MapView {
349352
notifyMyLocationTapped() {
350353
this.notify({ eventName: MapViewBase.myLocationTappedEvent, object: this });
351354
}
355+
356+
notifyBuildingFocusedEvent(indoorBuilding: IndoorBuilding) {
357+
let args: BuildingFocusedEventData = { eventName: MapViewBase.indoorBuildingFocusedEvent, object: this, indoorBuilding: indoorBuilding };
358+
this.notify(args);
359+
}
360+
361+
notifyIndoorLevelActivatedEvent(activateLevel: IndoorLevel) {
362+
let args: IndoorLevelActivatedEventData = { eventName: MapViewBase.indoorBuildingFocusedEvent, object: this, activateLevel: activateLevel };
363+
this.notify(args);
364+
}
352365
}
353366

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

src/map-view.android.ts

Lines changed: 39 additions & 0 deletions
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
}));

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+
}

0 commit comments

Comments
 (0)