Samples for the Google Maps JavaScript API.
The samples can be demoed at the official documentation site.
This project uses 11ty (Eleventy) static site generator with Nunjucks templates to build the sample showcase.
Nunjucks is a powerful JavaScript templating engine inspired by Python's Jinja2.
.njkextension = Nunjucks template files- Purpose: Generate dynamic HTML with variable interpolation, loops, conditionals, etc.
- Syntax example:
{% for sample in collections.samples_ts %} <h4>{{ sample.data.name }}</h4> {% endfor %}
Eleventy (shortened as 11ty) is a static site generator.
- Naming origin: "Eleventy" = 11ty (11 = eleven, ty = ty)
- @11ty/eleventy is the npm package name, @ indicates a scoped package
- Purpose: Transform template files into static HTML websites
index.html.njk → [11ty processes] → index.html
- Input:
index.html.njk(Nunjucks template) - Processing: 11ty reads templates and executes Nunjucks syntax
- Output: Static
index.htmlfiles
The collections.samples_ts is automatically generated by scanning the samples directory:
Configuration (.eleventy.js):
eleventyConfig.addCollection("samples_ts", function (collectionApi) {
const samples = collectionApi.getFilteredByGlob("samples/*/index.ts*");
return samples;
});Directory Structure:
samples/
├── add-map/
│ ├── index.ts # ← Included in collection
│ ├── index.njk
│ └── ...
├── react-map/
│ ├── index.tsx # ← Included in collection
│ └── ...
samples/index.html.njk (template)
↓ (11ty processing)
dist/index.html (final static file)
npm iInstall dependencies.npm run buildBuild all targets and updatedist/folder.
npm testTest outputs.- (Optional)
npm run lintFix lint issues withnpm run format - (Optional)
npm run test:playwright:playground:update-snapshotsUpdate snapshots. This uses an custom env var to only to only update screenshots that differ from the previous ones (Playwright only supportsnone,all, ormissing). To update all screenshots, usenpm run test:playwright:playground:update-snapshots -- --update-snapshots. It's possible to target a single sample by using-g <sample-name>.
- Start a server with all samples using
npm start
For staging samples (not common), use Cloud Source Repositories which are controlled by an access control list.
gcloud auth logingit config --global credential.https://source.developers.google.com.helper gcloud.shgit remote add google https://source.developers.google.com/p/geo-devrel-javascript-samples/r/js-samplesgit push googlegit rev-parse --short HEADor visit the bucket.
All samples can be explored at https://googlemaps.github.io/js-samples/.
- Google Maps JavaScript API Documentation
- Google Maps JavaScript API Reference Documentation
- Google Maps Typings -
npm i -D @types/google.maps - Google Maps Utilities
These libraries are community supported. We're comfortable enough with the stability and features of the libraries that we want you to build real production applications on it.
If you find a bug, or have a feature suggestion, please log an issue. If you'd like to contribute, please read How to Contribute.