diff --git a/samples/control-positioning/README.md b/samples/control-positioning/README.md new file mode 100644 index 00000000..71d15132 --- /dev/null +++ b/samples/control-positioning/README.md @@ -0,0 +1,41 @@ +# Google Maps JavaScript Sample + +## control-positioning + +This example demontrates custom positioning of the map controls. + +## Setup + +### Before starting run: + +`npm i` + +### Run an example on a local web server + +`cd samples/control-positioning` +`npm start` + +### Build an individual example + +`cd samples/control-positioning` +`npm run build` + +From 'samples': + +`npm run build --workspace=control-positioning/` + +### Build all of the examples. + +From 'samples': + +`npm run build-all` + +### Run lint to check for problems + +`cd samples/control-positioning` +`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-positioning/index.html b/samples/control-positioning/index.html new file mode 100644 index 00000000..9dc026b8 --- /dev/null +++ b/samples/control-positioning/index.html @@ -0,0 +1,22 @@ + + + + + + Control Positioning + + + + + + + + + + + diff --git a/samples/control-positioning/index.ts b/samples/control-positioning/index.ts new file mode 100755 index 00000000..8e8ffc44 --- /dev/null +++ b/samples/control-positioning/index.ts @@ -0,0 +1,39 @@ +/** + * @license + * Copyright 2026 Google LLC. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 + */ + +// [START maps_control_positioning] +const mapElement = document.querySelector('gmp-map') as google.maps.MapElement; +let innerMap; + +async function initMap() { + // Request needed libraries. + (await google.maps.importLibrary('maps')) as google.maps.MapsLibrary; + + // Get the inner map. + const innerMap = mapElement.innerMap; + + // Set the map's controls options. + innerMap.setOptions({ + mapTypeControl: true, + mapTypeControlOptions: { + style: google.maps.MapTypeControlStyle.HORIZONTAL_BAR, + position: google.maps.ControlPosition.BLOCK_START_INLINE_CENTER, + }, + zoomControl: true, + zoomControlOptions: { + position: google.maps.ControlPosition.INLINE_START_BLOCK_CENTER, + }, + scaleControl: true, + streetViewControl: true, + streetViewControlOptions: { + position: google.maps.ControlPosition.INLINE_START_BLOCK_START, + }, + fullscreenControl: true, + }); +} + +initMap(); +// [END maps_control_positioning] diff --git a/samples/control-positioning/package.json b/samples/control-positioning/package.json new file mode 100644 index 00000000..c7b53075 --- /dev/null +++ b/samples/control-positioning/package.json @@ -0,0 +1,14 @@ +{ + "name": "@js-api-samples/control-positioning", + "version": "1.0.0", + "scripts": { + "build": "tsc && bash ../jsfiddle.sh control-positioning && bash ../app.sh control-positioning && bash ../docs.sh control-positioning && npm run build:vite --workspace=. && bash ../dist.sh control-positioning", + "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-positioning/style.css b/samples/control-positioning/style.css new file mode 100644 index 00000000..a6ab5a10 --- /dev/null +++ b/samples/control-positioning/style.css @@ -0,0 +1,17 @@ +/** + * @license + * Copyright 2026 Google LLC. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 + */ +/* [START maps_control_positioning] */ +/* + * Optional: Makes the sample page fill the window. + */ +html, +body { + height: 100%; + margin: 0; + padding: 0; +} + +/* [END maps_control_positioning] */ diff --git a/samples/control-positioning/tsconfig.json b/samples/control-positioning/tsconfig.json new file mode 100644 index 00000000..366aabb0 --- /dev/null +++ b/samples/control-positioning/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" + } +}