Skip to content

Commit 07dc047

Browse files
authored
feat: Migrates a set of control samples. (#1048)
* feat: Migrates a set of control samples. * Fix spacing in gmp-map center attribute * Simplify library import for map initialization * Simplify map library import in initMap function Refactor map library import to simplify code. * Refactor mapTypeIds to use enum values * Clean up package.json by removing dependencies Removed empty dependencies section from package.json * Simplify map library import in initMap function * Refactor control positioning labels for cleaner code * Clean up package.json by removing empty dependencies Removed empty dependencies section from package.json * Fix formatting of gmp-map center attribute * Simplify library import for Google Maps * Update package.json * Update package.json
1 parent 2d28bee commit 07dc047

File tree

24 files changed

+639
-0
lines changed

24 files changed

+639
-0
lines changed
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
# Google Maps JavaScript Sample
2+
3+
## control-disableUI
4+
5+
This sample shows how to disable UI Controls on the Map.
6+
7+
## Setup
8+
9+
### Before starting run:
10+
11+
`npm i`
12+
13+
### Run an example on a local web server
14+
15+
`cd samples/control-disableUI`
16+
`npm start`
17+
18+
### Build an individual example
19+
20+
`cd samples/control-disableUI`
21+
`npm run build`
22+
23+
From 'samples':
24+
25+
`npm run build --workspace=control-disableUI/`
26+
27+
### Build all of the examples.
28+
29+
From 'samples':
30+
31+
`npm run build-all`
32+
33+
### Run lint to check for problems
34+
35+
`cd samples/control-disableUI`
36+
`npx eslint index.ts`
37+
38+
## Feedback
39+
40+
For feedback related to this sample, please open a new issue on
41+
[GitHub](https://github.com/googlemaps-samples/js-api-samples/issues).
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<!doctype html>
2+
<!--
3+
@license
4+
Copyright 2026 Google LLC. All Rights Reserved.
5+
SPDX-License-Identifier: Apache-2.0
6+
-->
7+
<!-- [START maps_control_disableUI] -->
8+
<html>
9+
<head>
10+
<title>Disabling the Default UI</title>
11+
12+
<link rel="stylesheet" type="text/css" href="./style.css" />
13+
<script type="module" src="./index.js"></script>
14+
<!-- prettier-ignore -->
15+
<script>(g=>{var h,a,k,p="The Google Maps JavaScript API",c="google",l="importLibrary",q="__ib__",m=document,b=window;b=b[c]||(b[c]={});var d=b.maps||(b.maps={}),r=new Set,e=new URLSearchParams,u=()=>h||(h=new Promise(async(f,n)=>{await (a=m.createElement("script"));e.set("libraries",[...r]+"");for(k in g)e.set(k.replace(/[A-Z]/g,t=>"_"+t[0].toLowerCase()),g[k]);e.set("callback",c+".maps."+q);a.src=`https://maps.${c}apis.com/maps/api/js?`+e;d[q]=f;a.onerror=()=>h=n(Error(p+" could not load."));a.nonce=m.querySelector("script[nonce]")?.nonce||"";m.head.append(a)}));d[l]?console.warn(p+" only loads once. Ignoring:",g):d[l]=(f,...n)=>r.add(f)&&u().then(()=>d[l](f,...n))})
16+
({key: "AIzaSyA6myHzS10YXdcazAFalmXvDkrYCp5cLc8", v: "weekly"});</script>
17+
</head>
18+
<body>
19+
<gmp-map center="-33,151" zoom="8"></gmp-map>
20+
</body>
21+
</html>
22+
<!-- [END maps_control_disableUI] -->

samples/control-disableUI/index.ts

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/**
2+
* @license
3+
* Copyright 2026 Google LLC. All Rights Reserved.
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
// [START maps_control_disableUI]
8+
async function initMap() {
9+
// Request the needed libraries.
10+
await google.maps.importLibrary('maps');
11+
12+
const mapElement = document.querySelector(
13+
'gmp-map'
14+
) as google.maps.MapElement;
15+
16+
const innerMap = mapElement.innerMap;
17+
18+
// [START maps_control_disableUI_options]
19+
innerMap.setOptions({
20+
// Disable the default UI.
21+
disableDefaultUI: true,
22+
});
23+
// [END maps_control_disableUI_options]
24+
}
25+
26+
initMap();
27+
// [END maps_control_disableUI]
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"name": "@js-api-samples/control-disableUI",
3+
"version": "1.0.0",
4+
"scripts": {
5+
"build": "tsc && bash ../jsfiddle.sh control-disableUI && bash ../app.sh control-disableUI && bash ../docs.sh control-disableUI && npm run build:vite --workspace=. && bash ../dist.sh control-disableUI",
6+
"test": "tsc && npm run build:vite --workspace=.",
7+
"start": "tsc && vite build --base './' && vite",
8+
"build:vite": "vite build --base './'",
9+
"preview": "vite preview"
10+
}
11+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/**
2+
* @license
3+
* Copyright 2026 Google LLC. All Rights Reserved.
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
/* [START maps_control_disableUI] */
7+
/*
8+
* Always set the map height explicitly to define the size of the div element
9+
* that contains the map.
10+
*/
11+
gmp-map {
12+
height: 100%;
13+
}
14+
15+
/*
16+
* Optional: Makes the sample page fill the window.
17+
*/
18+
html,
19+
body {
20+
height: 100%;
21+
margin: 0;
22+
padding: 0;
23+
}
24+
25+
/* [END maps_control_disableUI] */
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
"compilerOptions": {
3+
"module": "esnext",
4+
"target": "esnext",
5+
"strict": true,
6+
"noImplicitAny": false,
7+
"lib": [
8+
"es2015",
9+
"esnext",
10+
"es6",
11+
"dom",
12+
"dom.iterable"
13+
],
14+
"moduleResolution": "Node",
15+
"jsx": "preserve"
16+
}
17+
}

samples/control-options/README.md

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
# Google Maps JavaScript Sample
2+
3+
## control-options
4+
5+
This sample shows setting map control options.
6+
7+
## Setup
8+
9+
### Before starting run:
10+
11+
`npm i`
12+
13+
### Run an example on a local web server
14+
15+
`cd samples/control-options`
16+
`npm start`
17+
18+
### Build an individual example
19+
20+
`cd samples/control-options`
21+
`npm run build`
22+
23+
From 'samples':
24+
25+
`npm run build --workspace=control-options/`
26+
27+
### Build all of the examples.
28+
29+
From 'samples':
30+
31+
`npm run build-all`
32+
33+
### Run lint to check for problems
34+
35+
`cd samples/control-options`
36+
`npx eslint index.ts`
37+
38+
## Feedback
39+
40+
For feedback related to this sample, please open a new issue on
41+
[GitHub](https://github.com/googlemaps-samples/js-api-samples/issues).

samples/control-options/index.html

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<!doctype html>
2+
<!--
3+
@license
4+
Copyright 2026 Google LLC. All Rights Reserved.
5+
SPDX-License-Identifier: Apache-2.0
6+
-->
7+
<!-- [START maps_control_options] -->
8+
<html>
9+
<head>
10+
<title>Control Options</title>
11+
12+
<link rel="stylesheet" type="text/css" href="./style.css" />
13+
<script type="module" src="./index.js"></script>
14+
<!-- prettier-ignore -->
15+
<script>(g=>{var h,a,k,p="The Google Maps JavaScript API",c="google",l="importLibrary",q="__ib__",m=document,b=window;b=b[c]||(b[c]={});var d=b.maps||(b.maps={}),r=new Set,e=new URLSearchParams,u=()=>h||(h=new Promise(async(f,n)=>{await (a=m.createElement("script"));e.set("libraries",[...r]+"");for(k in g)e.set(k.replace(/[A-Z]/g,t=>"_"+t[0].toLowerCase()),g[k]);e.set("callback",c+".maps."+q);a.src=`https://maps.${c}apis.com/maps/api/js?`+e;d[q]=f;a.onerror=()=>h=n(Error(p+" could not load."));a.nonce=m.querySelector("script[nonce]")?.nonce||"";m.head.append(a)}));d[l]?console.warn(p+" only loads once. Ignoring:",g):d[l]=(f,...n)=>r.add(f)&&u().then(()=>d[l](f,...n))})
16+
({key: "AIzaSyA6myHzS10YXdcazAFalmXvDkrYCp5cLc8", v: "weekly"});</script>
17+
</head>
18+
<body>
19+
<gmp-map center="-44.03416970075901, 170.4710062642279" zoom="8"></gmp-map>
20+
</body>
21+
</html>
22+
<!-- [END maps_control_options] -->

samples/control-options/index.ts

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/**
2+
* @license
3+
* Copyright 2026 Google LLC. All Rights Reserved.
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
// [START maps_control_options]
8+
// You can set control options to change the default position or style of many
9+
// of the map controls.
10+
11+
async function initMap() {
12+
// Request the needed libraries.
13+
await google.maps.importLibrary('maps');
14+
15+
const mapElement = document.querySelector(
16+
'gmp-map'
17+
) as google.maps.MapElement;
18+
19+
const innerMap = mapElement.innerMap;
20+
21+
// [START maps_control_options_change_default]
22+
innerMap.setOptions({
23+
mapTypeControl: true,
24+
mapTypeControlOptions: {
25+
style: google.maps.MapTypeControlStyle.DROPDOWN_MENU,
26+
mapTypeIds: [
27+
google.maps.MapTypeId.ROADMAP,
28+
google.maps.MapTypeId.TERRAIN,
29+
],
30+
position: google.maps.ControlPosition.TOP_CENTER,
31+
},
32+
});
33+
// [END maps_control_options_change_default]
34+
}
35+
36+
initMap();
37+
// [END maps_control_options]
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"name": "@js-api-samples/control-options",
3+
"version": "1.0.0",
4+
"scripts": {
5+
"build": "tsc && bash ../jsfiddle.sh control-options && bash ../app.sh control-options && bash ../docs.sh control-options && npm run build:vite --workspace=. && bash ../dist.sh control-options",
6+
"test": "tsc && npm run build:vite --workspace=.",
7+
"start": "tsc && vite build --base './' && vite",
8+
"build:vite": "vite build --base './'",
9+
"preview": "vite preview"
10+
}
11+
}

0 commit comments

Comments
 (0)