From ee4315d61867b369ef4fe7ae465fb3d733149be7 Mon Sep 17 00:00:00 2001 From: vladimir Date: Wed, 10 Jul 2019 16:14:56 -0400 Subject: [PATCH] Add restriction option for google map options (#36774) * Add restriction option for google map options. * Add comments from original Google Maps JS API documentation and links to it. --- types/googlemaps/googlemaps-tests.ts | 4 ++++ types/googlemaps/index.d.ts | 35 +++++++++++++++++++++++++++- 2 files changed, 38 insertions(+), 1 deletion(-) diff --git a/types/googlemaps/googlemaps-tests.ts b/types/googlemaps/googlemaps-tests.ts index 427187c357..028b5f24f0 100644 --- a/types/googlemaps/googlemaps-tests.ts +++ b/types/googlemaps/googlemaps-tests.ts @@ -11,6 +11,10 @@ let mapOptions: google.maps.MapOptions = { position: google.maps.ControlPosition.RIGHT_TOP }, gestureHandling: 'cooperative', + restriction: { + latLngBounds: { east: 180, west: -180, north: 85, south: -85 }, + strictBounds: true + }, scrollwheel: true, styles: [ { diff --git a/types/googlemaps/index.d.ts b/types/googlemaps/index.d.ts index e88dfef384..1cc6476d0a 100644 --- a/types/googlemaps/index.d.ts +++ b/types/googlemaps/index.d.ts @@ -1,4 +1,4 @@ -// Type definitions for Google Maps JavaScript API 3.36 +// Type definitions for Google Maps JavaScript API 3.37 // Project: https://developers.google.com/maps/ // Definitions by: Folia A/S , // Chris Wrench , @@ -13,6 +13,7 @@ // Michael Gauthier // Colin Doig // Dmitry Demensky +// Vladimir Dashukevich // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped // TypeScript Version: 2.7 @@ -192,6 +193,13 @@ declare namespace google.maps { * in the v3.22 Map Controls}. */ panControlOptions?: PanControlOptions; + /** + * Defines a boundary that restricts the area of the map accessible to users. + * When set, a user can only pan and zoom while the camera view stays inside the + * limits of the boundary. + * @see {@link https://developers.google.com/maps/documentation/javascript/reference/map#MapOptions.restriction Maps JavaScript API} + */ + restriction?: MapRestriction; /** The enabled/disabled state of the Rotate control. */ rotateControl?: boolean; /** The display options for the Rotate control. */ @@ -314,6 +322,31 @@ declare namespace google.maps { position?: ControlPosition; } + /** + * A restriction that can be applied to the Map. The map's viewport will not + * exceed these restrictions. + * @see {@link https://developers.google.com/maps/documentation/javascript/reference/map#MapRestriction Maps JavaScript API} + */ + interface MapRestriction { + /** + * When set, a user can only pan and zoom inside the given bounds. + * Bounds can restrict both longitude and latitude, or can restrict + * latitude only. For latitude-only bounds use west and east longitudes + * of -180 and 180, respectively. + * @see {@link https://developers.google.com/maps/documentation/javascript/reference/map#MapRestriction.latLngBounds Maps JavaScript API} + */ + latLngBounds: LatLngBounds | LatLngBoundsLiteral; + /** + * By default bounds are relaxed, meaning that a user can zoom out + * until the entire bounded area is in view. Bounds can be made more + * restrictive by setting the strictBounds flag to true. This reduces + * how far a user can zoom out, ensuring that everything outside of the + * restricted bounds stays hidden. + * @see {@link https://developers.google.com/maps/documentation/javascript/reference/map#MapRestriction.strictBounds Maps JavaScript API} + */ + strictBounds?: boolean; + } + /** Options for the rendering of the scale control. */ interface ScaleControlOptions { /** Style id. Used to select what style of scale control to display. */