Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 41 additions & 0 deletions samples/web-components-markers/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# Google Maps JavaScript Sample

## web-components-markers

Add a marker to a Google map using web components.

## Setup

### Before starting run:

`npm i`

### Run an example on a local web server

`cd samples/web-components-markers`
`npm start`

### Build an individual example

`cd samples/web-components-markers`
`npm run build`

From 'samples':

`npm run build --workspace=web-components-markers/`

### Build all of the examples.

From 'samples':

`npm run build-all`

### Run lint to check for problems

`cd samples/web-components-markers`
`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).
34 changes: 34 additions & 0 deletions samples/web-components-markers/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<!doctype html>
<!--
@license
Copyright 2025 Google LLC. All Rights Reserved.
SPDX-License-Identifier: Apache-2.0
-->
<!-- [START maps_web_components_markers] -->
<html>
<head>
<title>Add a Map with Markers using HTML</title>

<link rel="stylesheet" type="text/css" href="./style.css" />
<script type="module" src="./index.js"></script>
<script
src="https://maps.googleapis.com/maps/api/js?key=AIzaSyA6myHzS10YXdcazAFalmXvDkrYCp5cLc8&libraries=maps,marker&v=weekly"
defer
></script>
</head>
<body>
<!-- [START maps_web_components_markers_div] -->
<gmp-map
center="41.027748173921374, -92.41852445367961"
zoom="13"
map-id="DEMO_MAP_ID"
>
<gmp-advanced-marker
position="41.027748173921374, -92.41852445367961"
title="Ottumwa, IA"
></gmp-advanced-marker>
</gmp-map>
<!-- [END maps_web_components_markers_div] -->
</body>
</html>
<!-- [END maps_web_components_markers] -->
15 changes: 15 additions & 0 deletions samples/web-components-markers/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/**
* @license
* Copyright 2025 Google LLC. All Rights Reserved.
* SPDX-License-Identifier: Apache-2.0
*/

// [START maps_web_components_markers]
// This example adds a map with markers, using web components.
// [START maps_web_components_markers_initmap]
async function initMap() {
console.log('Maps JavaScript API loaded.');
}
// [END maps_web_components_markers_initmap]
initMap();
// [END maps_web_components_markers]
14 changes: 14 additions & 0 deletions samples/web-components-markers/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"name": "@js-api-samples/web-components-markers",
"version": "1.0.0",
"scripts": {
"build": "tsc && bash ../jsfiddle.sh web-components-markers && bash ../app.sh web-components-markers && bash ../docs.sh web-components-markers && npm run build:vite --workspace=. && bash ../dist.sh web-components-markers",
"test": "tsc && npm run build:vite --workspace=.",
"start": "tsc && vite build --base './' && vite",
"build:vite": "vite build --base './'",
"preview": "vite preview"
},
"dependencies": {

}
}
24 changes: 24 additions & 0 deletions samples/web-components-markers/style.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/**
* @license
* Copyright 2025 Google LLC. All Rights Reserved.
* SPDX-License-Identifier: Apache-2.0
*/
/* [START maps_web_components_markers] */
/*
* Always set the map height explicitly to define the size of the div element
* that contains the map.
*/
gmp-map {
height: 100%;
}

/*
* Optional: Makes the sample page fill the window.
*/
html,
body {
height: 100%;
margin: 0;
padding: 0;
}
/* [END maps_web_components_markers] */
17 changes: 17 additions & 0 deletions samples/web-components-markers/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"compilerOptions": {
"module": "esnext",
"target": "esnext",
"strict": true,
"noImplicitAny": false,
"lib": [
"es2015",
"esnext",
"es6",
"dom",
"dom.iterable"
],
"moduleResolution": "Node",
"jsx": "preserve"
}
}