From 76cba600f68cc6ad777cdea7bf07f9b55fe47dd5 Mon Sep 17 00:00:00 2001 From: William French Date: Tue, 17 Feb 2026 10:20:16 -0800 Subject: [PATCH] feat: Migrates the control-bounds-restriction sample to js-api-samples. --- samples/control-bounds-restriction/README.md | 41 +++++++++++++++++++ samples/control-bounds-restriction/index.html | 22 ++++++++++ samples/control-bounds-restriction/index.ts | 37 +++++++++++++++++ .../control-bounds-restriction/package.json | 14 +++++++ samples/control-bounds-restriction/style.css | 17 ++++++++ .../control-bounds-restriction/tsconfig.json | 17 ++++++++ 6 files changed, 148 insertions(+) create mode 100644 samples/control-bounds-restriction/README.md create mode 100644 samples/control-bounds-restriction/index.html create mode 100644 samples/control-bounds-restriction/index.ts create mode 100644 samples/control-bounds-restriction/package.json create mode 100644 samples/control-bounds-restriction/style.css create mode 100644 samples/control-bounds-restriction/tsconfig.json diff --git a/samples/control-bounds-restriction/README.md b/samples/control-bounds-restriction/README.md new file mode 100644 index 000000000..ca3a302dc --- /dev/null +++ b/samples/control-bounds-restriction/README.md @@ -0,0 +1,41 @@ +# Google Maps JavaScript Sample + +## control-bounds-restriction + +This sample demonstrates restricting the map to a specific area. + +## Setup + +### Before starting run: + +`npm i` + +### Run an example on a local web server + +`cd samples/control-bounds-restriction` +`npm start` + +### Build an individual example + +`cd samples/control-bounds-restriction` +`npm run build` + +From 'samples': + +`npm run build --workspace=control-bounds-restriction/` + +### Build all of the examples. + +From 'samples': + +`npm run build-all` + +### Run lint to check for problems + +`cd samples/control-bounds-restriction` +`npx eslint index.ts` + +## Feedback + +For feedback related to this sample, please open a new issue on +[GitHub](https://github.com/googlemaps-samples/js-api-samples/issues). diff --git a/samples/control-bounds-restriction/index.html b/samples/control-bounds-restriction/index.html new file mode 100644 index 000000000..7a7aa91a2 --- /dev/null +++ b/samples/control-bounds-restriction/index.html @@ -0,0 +1,22 @@ + + + + + + Map Bounds Restriction + + + + + + + + + + + diff --git a/samples/control-bounds-restriction/index.ts b/samples/control-bounds-restriction/index.ts new file mode 100644 index 000000000..74ad80f68 --- /dev/null +++ b/samples/control-bounds-restriction/index.ts @@ -0,0 +1,37 @@ +/** + * @license + * Copyright 2026 Google LLC. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 + */ + +// [START maps_control_bounds_restriction] +let innerMap; +const mapElement = document.querySelector('gmp-map') as google.maps.MapElement; + +// [START maps_control_bounds_restriction_region] +const NEW_ZEALAND_BOUNDS = { + north: -34.36, + south: -47.35, + west: 166.28, + east: -175.81, +}; +// [END maps_control_bounds_restriction_region] + +async function initMap() { + // Import the needed libraries. + (await google.maps.importLibrary('maps')) as google.maps.MapsLibrary; + + innerMap = mapElement.innerMap; + // [START maps_control_bounds_restriction_options] + // Restrict the map to the provided bounds. + innerMap.setOptions({ + restriction: { + latLngBounds: NEW_ZEALAND_BOUNDS, + strictBounds: false, + } + }); + // [END maps_control_bounds_restriction_options] +} + +initMap(); +// [END maps_control_bounds_restriction] diff --git a/samples/control-bounds-restriction/package.json b/samples/control-bounds-restriction/package.json new file mode 100644 index 000000000..f54b1372d --- /dev/null +++ b/samples/control-bounds-restriction/package.json @@ -0,0 +1,14 @@ +{ + "name": "@js-api-samples/control-bounds-restriction", + "version": "1.0.0", + "scripts": { + "build": "tsc && bash ../jsfiddle.sh control-bounds-restriction && bash ../app.sh control-bounds-restriction && bash ../docs.sh control-bounds-restriction && npm run build:vite --workspace=. && bash ../dist.sh control-bounds-restriction", + "test": "tsc && npm run build:vite --workspace=.", + "start": "tsc && vite build --base './' && vite", + "build:vite": "vite build --base './'", + "preview": "vite preview" + }, + "dependencies": { + + } +} diff --git a/samples/control-bounds-restriction/style.css b/samples/control-bounds-restriction/style.css new file mode 100644 index 000000000..685148763 --- /dev/null +++ b/samples/control-bounds-restriction/style.css @@ -0,0 +1,17 @@ +/** + * @license + * Copyright 2026 Google LLC. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 + */ +/* [START maps_control_bounds_restriction] */ +/* + * Optional: Makes the sample page fill the window. + */ +html, +body { + height: 100%; + margin: 0; + padding: 0; +} + +/* [END maps_control_bounds_restriction] */ \ No newline at end of file diff --git a/samples/control-bounds-restriction/tsconfig.json b/samples/control-bounds-restriction/tsconfig.json new file mode 100644 index 000000000..366aabb04 --- /dev/null +++ b/samples/control-bounds-restriction/tsconfig.json @@ -0,0 +1,17 @@ +{ + "compilerOptions": { + "module": "esnext", + "target": "esnext", + "strict": true, + "noImplicitAny": false, + "lib": [ + "es2015", + "esnext", + "es6", + "dom", + "dom.iterable" + ], + "moduleResolution": "Node", + "jsx": "preserve" + } +}