diff --git a/package-lock.json b/package-lock.json index d440a729d..460e40f98 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1343,6 +1343,10 @@ "resolved": "samples/layer-traffic", "link": true }, + "node_modules/@js-api-samples/layer-transit": { + "resolved": "samples/layer-transit", + "link": true + }, "node_modules/@js-api-samples/map-drawing-terradraw": { "resolved": "samples/map-drawing-terradraw", "link": true @@ -6753,6 +6757,10 @@ "name": "@js-api-samples/layer-traffic", "version": "1.0.0" }, + "samples/layer-transit": { + "name": "@js-api-samples/layer-transit", + "version": "1.0.0" + }, "samples/map-drawing-terradraw": { "name": "@js-api-samples/map-drawing-terradraw", "version": "1.0.0", diff --git a/samples/layer-transit/README.md b/samples/layer-transit/README.md new file mode 100644 index 000000000..3477f4a0f --- /dev/null +++ b/samples/layer-transit/README.md @@ -0,0 +1,41 @@ +# Google Maps JavaScript Sample + +## layer-transit + +Transit layer sample. + +## Setup + +### Before starting run: + +`npm i` + +### Run an example on a local web server + +`cd samples/layer-transit` +`npm start` + +### Build an individual example + +`cd samples/layer-transit` +`npm run build` + +From 'samples': + +`npm run build --workspace=layer-transit/` + +### Build all of the examples. + +From 'samples': + +`npm run build-all` + +### Run lint to check for problems + +`cd samples/layer-transit` +`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/layer-transit/index.html b/samples/layer-transit/index.html new file mode 100644 index 000000000..e742759f3 --- /dev/null +++ b/samples/layer-transit/index.html @@ -0,0 +1,28 @@ + + + + + + Transit Layer + + + + + + + + + + diff --git a/samples/layer-transit/index.ts b/samples/layer-transit/index.ts new file mode 100644 index 000000000..d60798926 --- /dev/null +++ b/samples/layer-transit/index.ts @@ -0,0 +1,21 @@ +/** + * @license + * Copyright 2026 Google LLC. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 + */ + +// [START maps_layer_transit] +async function init(): Promise { + const { TransitLayer } = await google.maps.importLibrary('maps'); + + const mapElement = + document.querySelector('gmp-map')!; + const innerMap = mapElement.innerMap; + + const transitLayer = new TransitLayer(); + + transitLayer.setMap(innerMap); +} + +void init(); +// [END maps_layer_transit] diff --git a/samples/layer-transit/package.json b/samples/layer-transit/package.json new file mode 100644 index 000000000..88adb356d --- /dev/null +++ b/samples/layer-transit/package.json @@ -0,0 +1,12 @@ +{ + "name": "@js-api-samples/layer-transit", + "version": "1.0.0", + "scripts": { + "build": "bash ../build-single.sh", + "test": "tsc && npm run build:vite --workspace=.", + "start": "tsc && vite build --config ../../vite.config.js --base './' && vite --config ../../vite.config.js", + "build:vite": "vite build --config ../../vite.config.js --base './'", + "preview": "vite preview --config ../../vite.config.js" + }, + "author": "Google LLC" +} diff --git a/samples/layer-transit/style.css b/samples/layer-transit/style.css new file mode 100644 index 000000000..084bf1689 --- /dev/null +++ b/samples/layer-transit/style.css @@ -0,0 +1,22 @@ +/** + * @license + * Copyright 2026 Google LLC. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 + */ +/* [START maps_layer_transit] */ + +/* + * Optional: Makes the sample page fill the window. + */ +html, +body { + height: 100%; + margin: 0; + padding: 0; +} + +gmp-map { + height: 100%; +} + +/* [END maps_layer_transit] */ diff --git a/samples/layer-transit/tsconfig.json b/samples/layer-transit/tsconfig.json new file mode 100644 index 000000000..976bcc6ef --- /dev/null +++ b/samples/layer-transit/tsconfig.json @@ -0,0 +1,7 @@ +{ + "extends": "../../tsconfig.base.json", + "compilerOptions": { + "rootDir": "." + }, + "include": ["./*.ts"] +}