Skip to content

Commit d82b541

Browse files
authored
Merge pull request #242 from evanfuture/feature/add-minmaxzoom-orig
Add min/max zoom functionality.
2 parents 24ac812 + 31b774c commit d82b541

File tree

8 files changed

+39
-5
lines changed

8 files changed

+39
-5
lines changed

demo/app/main-page.xml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
<Page xmlns="http://www.nativescript.org/tns.xsd" xmlns:maps="nativescript-google-maps-sdk" loaded="pageLoaded">
22
<GridLayout>
33
<maps:mapView latitude="{{ latitude }}" longitude="{{ longitude }}"
4-
zoom="{{ zoom }}" bearing="{{ bearing }}" mapAnimationsEnabled="{{ mapAnimationsEnabled }}"
5-
tilt="{{ tilt }}" i-padding="50,50,50,50" padding="{{ padding }}" mapReady="onMapReady"
4+
zoom="{{ zoom }}" minZoom="{{ minZoom }}" maxZoom="{{ maxZoom }}" bearing="{{ bearing }}" mapAnimationsEnabled="{{ mapAnimationsEnabled }}"
5+
tilt="{{ tilt }}" i-padding="50,50,50,50" padding="{{ padding }}" mapReady="onMapReady"
66
markerSelect="onMarkerEvent" markerBeginDragging="onMarkerEvent"
77
markerEndDragging="onMarkerEvent" markerDrag="onMarkerEvent"
88
markerInfoWindowTapped="onMarkerEvent" coordinateTapped="onCoordinateTapped"
@@ -25,4 +25,4 @@
2525
</maps:mapView.infoWindowTemplates>
2626
</maps:mapView>
2727
</GridLayout>
28-
</Page>
28+
</Page>

demo/app/main-view-model.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ var HelloWorldModel = (function (_super) {
66
this.set("latitude", -33.86);
77
this.set("longitude", 151.20);
88
this.set("zoom", 8);
9+
this.set("minZoom", 0);
10+
this.set("maxZoom", 22);
911
this.set("bearing", 180);
1012
this.set("tilt", 35);
1113
this.set("padding", [80, 40, 40, 40]);

map-view-common.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,10 @@ function onMapPropertyChanged(mapView: MapViewBase) {
3232
if (!mapView.processingCameraEvent) mapView.updateCamera();
3333
}
3434

35+
function onSetMinZoomMaxZoom(mapView: MapViewBase) {
36+
mapView.setMinZoomMaxZoom();
37+
}
38+
3539
function onPaddingPropertyChanged(mapView: MapViewBase) {
3640
mapView.updatePadding();
3741
}
@@ -144,6 +148,8 @@ export abstract class MapViewBase extends View implements MapView {
144148
public longitude: number;
145149
public bearing: number;
146150
public zoom: number;
151+
public minZoom: number;
152+
public maxZoom: number;
147153
public tilt: number;
148154
public padding: number[];
149155
public mapAnimationsEnabled: boolean;
@@ -259,6 +265,8 @@ export abstract class MapViewBase extends View implements MapView {
259265

260266
public abstract updatePadding(): void;
261267

268+
public abstract setMinZoomMaxZoom(): void;
269+
262270
public abstract addMarker(...markers: Marker[]): void;
263271

264272
public abstract removeMarker(...markers: Marker[]): void;
@@ -360,6 +368,12 @@ bearingProperty.register(MapViewBase);
360368
export const zoomProperty = new Property<MapViewBase, number>({ name: 'zoom', defaultValue: 0, valueChanged: onMapPropertyChanged });
361369
zoomProperty.register(MapViewBase);
362370

371+
export const minZoomProperty = new Property<MapViewBase, number>({ name: 'minZoom', defaultValue: 0, valueChanged: onSetMinZoomMaxZoom });
372+
minZoomProperty.register(MapViewBase);
373+
374+
export const maxZoomProperty = new Property<MapViewBase, number>({ name: 'maxZoom', defaultValue: 22, valueChanged: onSetMinZoomMaxZoom });
375+
maxZoomProperty.register(MapViewBase);
376+
363377
export const tiltProperty = new Property<MapViewBase, number>({ name: 'tilt', defaultValue: 0, valueChanged: onMapPropertyChanged });
364378
tiltProperty.register(MapViewBase);
365379

map-view.android.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ export class MapView extends MapViewBase {
8585
onMapReady: (gMap) => {
8686
var owner = that.get();
8787
owner._gMap = gMap;
88+
owner.setMinZoomMaxZoom();
8889
owner.updatePadding();
8990
if (owner._pendingCameraUpdate) {
9091
owner.updateCamera();
@@ -352,6 +353,13 @@ export class MapView extends MapViewBase {
352353
if (this._gMap) this._gMap.setMyLocationEnabled(value);
353354
}
354355

356+
setMinZoomMaxZoom() {
357+
if (this.gMap) {
358+
this.gMap.setMinZoomPreference(this.minZoom);
359+
this.gMap.setMaxZoomPreference(this.maxZoom);
360+
}
361+
}
362+
355363
addMarker(...markers: Marker[]) {
356364
markers.forEach(marker => {
357365
marker.android = this.gMap.addMarker(marker.android);

map-view.d.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ export class MapView extends View {
1717
public latitude: number;
1818
public longitude: number;
1919
public zoom: number;
20+
public minZoom: number;
21+
public maxZoom: number;
2022
public bearing: number;
2123
public tilt: number;
2224
public padding: number[];
@@ -52,6 +54,8 @@ export class MapView extends View {
5254

5355
public myLocationEnabled: boolean;
5456

57+
public setMinZoomMaxZoom(): void;
58+
5559
public addMarker(...markers: Marker[]): void;
5660

5761
public removeMarker(...markers: Marker[]): void;

map-view.ios.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -301,6 +301,10 @@ export class MapView extends MapViewBase {
301301
if (this.nativeView) this.nativeView.myLocationEnabled = value;
302302
}
303303

304+
setMinZoomMaxZoom() {
305+
this.gMap.setMinZoomMaxZoom(this.minZoom, this.maxZoom);
306+
}
307+
304308
addMarker(...markers: Marker[]) {
305309
markers.forEach(marker => {
306310
marker.ios.map = this.gMap;

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ export class MapComponent {
1717
latitude = -33.86;
1818
longitude = 151.20;
1919
zoom = 8;
20+
minZoom = 0;
21+
maxZoom = 22;
2022
bearing = 0;
2123
tilt = 0;
2224
padding = [40, 40, 40, 40];

ng-demo/app/map/map.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
<GridLayout>
22
<MapView #mapView [latitude]="latitude" [longitude]="longitude"
3-
[zoom]="zoom" [bearing]="bearing"
3+
[zoom]="zoom" [minZoom]="minZoom" [maxZoom]="maxZoom" [bearing]="bearing"
44
[tilt]="tilt" i-padding="50,50,50,50" [padding]="padding" (mapReady)="onMapReady($event)"
55
(markerSelect)="onMarkerEvent($event)" (markerBeginDragging)="onMarkerEvent($event)"
66
(markerEndDragging)="onMarkerEvent($event)" (markerDrag)="onMarkerEvent($event)"
77
(markerInfoWindowTapped)="onMarkerEvent($event)" (coordinateTapped)="onCoordinateTapped($event)"
88
(cameraChanged)="onCameraChanged($event)"></MapView>
9-
</GridLayout>
9+
</GridLayout>

0 commit comments

Comments
 (0)