Skip to content
This repository was archived by the owner on Jun 23, 2025. It is now read-only.

Commit 7201a75

Browse files
kamilchlebekdoom777
authored andcommitted
feat(AgmMap): add area restriction option
implement MapRestriction option on AgmMap see: https://developers.google.com/maps/documentation/javascript/reference/map#MapRestriction fixes #1624
1 parent 8b2f2dc commit 7201a75

2 files changed

Lines changed: 18 additions & 4 deletions

File tree

packages/core/directives/map.ts

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,9 @@ import {Subscription} from 'rxjs';
44
import {MouseEvent} from '../map-types';
55
import {GoogleMapsAPIWrapper} from '../services/google-maps-api-wrapper';
66
import {
7-
FullscreenControlOptions, LatLng, LatLngLiteral, MapTypeControlOptions, MapTypeId, PanControlOptions,
8-
RotateControlOptions, ScaleControlOptions, StreetViewControlOptions, ZoomControlOptions} from '../services/google-maps-types';
7+
FullscreenControlOptions, LatLng, LatLngLiteral, MapTypeControlOptions, MapTypeId, PanControlOptions, MapRestriction,
8+
RotateControlOptions, ScaleControlOptions, StreetViewControlOptions, ZoomControlOptions
9+
} from '../services/google-maps-types';
910
import {LatLngBounds, LatLngBoundsLiteral, MapTypeStyle} from '../services/google-maps-types';
1011
import {CircleManager} from '../services/managers/circle-manager';
1112
import {RectangleManager} from '../services/managers/rectangle-manager';
@@ -259,6 +260,11 @@ export class AgmMap implements OnChanges, OnInit, OnDestroy {
259260
*/
260261
@Input() gestureHandling: 'cooperative'|'greedy'|'none'|'auto' = 'auto';
261262

263+
/**
264+
* Options for restricting the bounds of the map.
265+
* User cannot pan or zoom away from restricted area.
266+
*/
267+
@Input() restriction: MapRestriction;
262268
/**
263269
* Map option attributes that can change over time
264270
*/
@@ -268,7 +274,7 @@ export class AgmMap implements OnChanges, OnInit, OnDestroy {
268274
'streetViewControlOptions', 'zoom', 'mapTypeControl', 'mapTypeControlOptions', 'minZoom',
269275
'maxZoom', 'panControl', 'panControlOptions', 'rotateControl', 'rotateControlOptions',
270276
'fullscreenControl', 'fullscreenControlOptions', 'scaleControl', 'scaleControlOptions',
271-
'mapTypeId', 'clickableIcons', 'gestureHandling'
277+
'mapTypeId', 'clickableIcons', 'gestureHandling', 'restriction'
272278
];
273279

274280
private _observableSubscriptions: Subscription[] = [];
@@ -363,7 +369,8 @@ export class AgmMap implements OnChanges, OnInit, OnDestroy {
363369
fullscreenControlOptions: this.fullscreenControlOptions,
364370
mapTypeId: this.mapTypeId,
365371
clickableIcons: this.clickableIcons,
366-
gestureHandling: this.gestureHandling
372+
gestureHandling: this.gestureHandling,
373+
restriction: this.restriction,
367374
})
368375
.then(() => this._mapsWrapper.getNativeMap())
369376
.then(map => this.mapReady.emit(map));

packages/core/services/google-maps-types.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,7 @@ export interface MapOptions {
187187
mapTypeId?: string|MapTypeId;
188188
clickableIcons?: boolean;
189189
gestureHandling?: 'cooperative'|'greedy'|'none'|'auto';
190+
restriction?: MapRestriction;
190191
}
191192

192193
export interface MapTypeStyle {
@@ -596,3 +597,9 @@ export interface FullscreenControlOptions {
596597
*/
597598
position?: ControlPosition;
598599
}
600+
601+
/** Options for the restricting the bounds of the map. */
602+
export interface MapRestriction {
603+
latLngBounds: LatLngBounds|LatLngBoundsLiteral;
604+
strictBounds?: boolean;
605+
}

0 commit comments

Comments
 (0)