Skip to content

Commit 8fca320

Browse files
authored
Merge pull request #298 from jnorkus/master
feat: onCameraMove event
2 parents 9c264cf + 6559ad5 commit 8fca320

File tree

8 files changed

+49
-4
lines changed

8 files changed

+49
-4
lines changed

README.md

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,8 @@ Modify your view by adding the namespace `xmlns:maps="nativescript-google-maps-s
121121
tilt="{{ tilt }}" padding="{{ padding }}" mapReady="onMapReady"
122122
markerSelect="onMarkerSelect" markerBeginDragging="onMarkerBeginDragging"
123123
markerEndDragging="onMarkerEndDragging" markerDrag="onMarkerDrag"
124-
cameraChanged="onCameraChanged" />
124+
cameraChanged="onCameraChanged"
125+
cameraMove="onCameraMove" />
125126
</GridLayout>
126127
</Page>
127128
```
@@ -155,7 +156,8 @@ Event | Description
155156
`markerDrag` | Fires repeatedly while a marker is being dragged
156157
`markerEndDragging` | Fires when a marker ends dragging
157158
`markerInfoWindowTapped` | Fired on tapping Marker Info Window
158-
`cameraChanged` | Fired on each camera change
159+
`cameraChanged` | Fired after the camera has changed
160+
`cameraMove` | Fired while the camera is moving
159161

160162

161163
The property `gMap` gives you access to the raw platform Map Object - see their SDK references for how to use them ( [iOS](https://developers.google.com/maps/documentation/ios-sdk/reference/interface_g_m_s_map_view) | [Android](https://developers.google.com/android/reference/com/google/android/gms/maps/GoogleMap) )
@@ -188,9 +190,14 @@ function onCameraChanged(args) {
188190
console.log("Camera changed: " + JSON.stringify(args.camera));
189191
}
190192
193+
function onCameraMove(args) {
194+
console.log("Camera moving: "+JSON.stringify(args.camera));
195+
}
196+
191197
exports.onMapReady = onMapReady;
192198
exports.onMarkerSelect = onMarkerSelect;
193199
exports.onCameraChanged = onCameraChanged;
200+
exports.onCameraMove = onCameraMove;
194201
```
195202

196203
## UI Settings

demo/app/main-page.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,12 @@ function onCameraChanged(args) {
241241
}));
242242
}
243243

244+
function onCameraMove(args) {
245+
console.log("Camera moving: "+JSON.stringify(args.camera));
246+
}
247+
244248
exports.onMapReady = onMapReady;
245249
exports.onCoordinateTapped = onCoordinateTapped;
246250
exports.onMarkerEvent = onMarkerEvent;
247251
exports.onCameraChanged = onCameraChanged;
252+
exports.onCameraMove = onCameraMove;

demo/app/main-page.xml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@
66
markerSelect="onMarkerEvent" markerBeginDragging="onMarkerEvent"
77
markerEndDragging="onMarkerEvent" markerDrag="onMarkerEvent"
88
markerInfoWindowTapped="onMarkerEvent" coordinateTapped="onCoordinateTapped"
9-
cameraChanged="onCameraChanged">
9+
cameraChanged="onCameraChanged"
10+
cameraMove="onCameraMove">
1011
<maps:mapView.infoWindowTemplate>
1112
<StackLayout orientation="vertical" width="200" height="150" >
1213
<Label text="{{title}}" className="title" width="125" />

ng-demo/app/map/map.component.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,4 +60,8 @@ export class MapComponent {
6060
this.lastCamera = JSON.stringify(args.camera);
6161
}
6262

63+
onCameraMove(args) {
64+
console.log("Camera moving: " + JSON.stringify(args.camera));
65+
}
66+
6367
}

ng-demo/app/map/map.html

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,6 @@
55
(markerSelect)="onMarkerEvent($event)" (markerBeginDragging)="onMarkerEvent($event)"
66
(markerEndDragging)="onMarkerEvent($event)" (markerDrag)="onMarkerEvent($event)"
77
(markerInfoWindowTapped)="onMarkerEvent($event)" (coordinateTapped)="onCoordinateTapped($event)"
8-
(cameraChanged)="onCameraChanged($event)"></MapView>
8+
(cameraChanged)="onCameraChanged($event)"
9+
(cameraMove)="onCameraMove($event)"></MapView>
910
</GridLayout>

src/map-view-common.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,7 @@ export abstract class MapViewBase extends View implements MapView {
181181
public static coordinateTappedEvent: string = "coordinateTapped";
182182
public static coordinateLongPressEvent: string = "coordinateLongPress";
183183
public static cameraChangedEvent: string = "cameraChanged";
184+
public static cameraMoveEvent: string = "cameraMove";
184185
public static myLocationTappedEvent: string = "myLocationTapped";
185186

186187
public get gMap() {

src/map-view.android.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,21 @@ export class MapView extends MapViewBase {
241241
}));
242242
}
243243

244+
if (gMap.setOnCameraMoveListener) {
245+
gMap.setOnCameraMoveListener(new com.google.android.gms.maps.GoogleMap.OnCameraMoveListener({
246+
onCameraMove: () => {
247+
const cameraPosition = gMap.getCameraPosition();
248+
owner.notifyCameraEvent(MapViewBase.cameraMoveEvent, {
249+
latitude: cameraPosition.target.latitude,
250+
longitude: cameraPosition.target.longitude,
251+
zoom: cameraPosition.zoom,
252+
bearing: cameraPosition.bearing,
253+
tilt: cameraPosition.tilt
254+
});
255+
}
256+
}));
257+
}
258+
244259
gMap.setInfoWindowAdapter(new com.google.android.gms.maps.GoogleMap.InfoWindowAdapter({
245260

246261
getInfoWindow: function (gmsMarker) {

src/map-view.ios.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,17 @@ class MapViewDelegateImpl extends NSObject implements GMSMapViewDelegate {
102102
}
103103
}
104104

105+
public mapViewDidChangeCameraPosition(mapView: GMSMapView, cameraPosition: GMSCameraPosition) {
106+
let owner = this._owner.get();
107+
owner.notifyCameraEvent(MapViewBase.cameraMoveEvent, {
108+
latitude: cameraPosition.target.latitude,
109+
longitude: cameraPosition.target.longitude,
110+
zoom: cameraPosition.zoom,
111+
bearing: cameraPosition.bearing,
112+
tilt: cameraPosition.viewingAngle
113+
});
114+
}
115+
105116
public mapViewDidTapAtCoordinate(mapView: GMSMapView, coordinate: CLLocationCoordinate2D): void {
106117
let owner = this._owner.get();
107118
if (owner) {

0 commit comments

Comments
 (0)