diff --git a/samples/polyline-simple/README.md b/samples/polyline-simple/README.md new file mode 100644 index 00000000..75f25e80 --- /dev/null +++ b/samples/polyline-simple/README.md @@ -0,0 +1,41 @@ +# Google Maps JavaScript Sample + +## polyline-simple + +This example creates a two-pixel-wide red polyline that shows the path of the first trans-Pacific flight between Oakland, CA, and Brisbane, Australia. + +## Setup + +### Before starting run: + +`npm i` + +### Run an example on a local web server + +`cd samples/polyline-simple` +`npm start` + +### Build an individual example + +`cd samples/polyline-simple` +`npm run build` + +From 'samples': + +`npm run build --workspace=polyline-simple/` + +### Build all of the examples. + +From 'samples': + +`npm run build-all` + +### Run lint to check for problems + +`cd samples/polyline-simple` +`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/polyline-simple/index.html b/samples/polyline-simple/index.html new file mode 100644 index 00000000..37bf31fa --- /dev/null +++ b/samples/polyline-simple/index.html @@ -0,0 +1,22 @@ + + + + + + Simple Polylines + + + + + + + + + + + diff --git a/samples/polyline-simple/index.ts b/samples/polyline-simple/index.ts new file mode 100644 index 00000000..e8034d44 --- /dev/null +++ b/samples/polyline-simple/index.ts @@ -0,0 +1,36 @@ +/** + * @license + * Copyright 2026 Google LLC. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 + */ + +// [START maps_polyline_simple] +// This example creates a 2-pixel-wide red polyline showing the path of +// the first trans-Pacific flight between Oakland, CA, and Brisbane, +// Australia which was made by Charles Kingsford Smith. +const mapElement = document.querySelector('gmp-map') as google.maps.MapElement; +let innerMap; + +async function initMap() { + (await google.maps.importLibrary('maps')) as google.maps.MapsLibrary; + innerMap = mapElement.innerMap; + + const flightPlanCoordinates = [ + { lat: 37.772, lng: -122.214 }, + { lat: 21.291, lng: -157.821 }, + { lat: -18.142, lng: 178.431 }, + { lat: -27.467, lng: 153.027 }, + ]; + const flightPath = new google.maps.Polyline({ + path: flightPlanCoordinates, + geodesic: true, + strokeColor: '#FF0000', + strokeOpacity: 1.0, + strokeWeight: 2, + }); + + flightPath.setMap(innerMap); +} + +initMap(); +// [END maps_polyline_simple] diff --git a/samples/polyline-simple/package.json b/samples/polyline-simple/package.json new file mode 100644 index 00000000..3e0eecda --- /dev/null +++ b/samples/polyline-simple/package.json @@ -0,0 +1,14 @@ +{ + "name": "@js-api-samples/polyline-simple", + "version": "1.0.0", + "scripts": { + "build": "tsc && bash ../jsfiddle.sh polyline-simple && bash ../app.sh polyline-simple && bash ../docs.sh polyline-simple && npm run build:vite --workspace=. && bash ../dist.sh polyline-simple", + "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/polyline-simple/style.css b/samples/polyline-simple/style.css new file mode 100644 index 00000000..73d8c6e9 --- /dev/null +++ b/samples/polyline-simple/style.css @@ -0,0 +1,18 @@ +/** + * @license + * Copyright 2026 Google LLC. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 + */ + +/* [START maps_polyline_simple] */ +/* + * Optional: Makes the sample page fill the window. + */ +html, +body { + height: 100%; + margin: 0; + padding: 0; +} + +/* [END maps_polyline_simple] */ diff --git a/samples/polyline-simple/tsconfig.json b/samples/polyline-simple/tsconfig.json new file mode 100644 index 00000000..366aabb0 --- /dev/null +++ b/samples/polyline-simple/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" + } +}