Skip to content

Comments

Update custom controls sample and migrate to new repo#1121

Open
sascala wants to merge 2 commits intomainfrom
control-custom-update
Open

Update custom controls sample and migrate to new repo#1121
sascala wants to merge 2 commits intomainfrom
control-custom-update

Conversation

@sascala
Copy link

@sascala sascala commented Feb 20, 2026

Update custom controls sample and migrate to new repo

@snippet-bot
Copy link

snippet-bot bot commented Feb 20, 2026

Here is the summary of changes.

You are about to add 11 region tags.

This comment is generated by snippet-bot.
If you find problems with this result, please file an issue at:
https://github.com/googleapis/repo-automation-bots/issues.
To update this comment, add snippet-bot:force-run label or use the checkbox below:

  • Refresh this comment

Copy link
Collaborator

@willum070 willum070 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you so much, this totally makes my day!! A great start, but there are a few things to clean up. Specifically there's a refactor I'd like to see done for all migrations where it makes sense (see my comments and use #1119 for reference).

Also please make sure your PR doesn't contain any changes to dist/, as that stuff gets generated automatically once your changes are merged.

</head>

<body>
<gmp-map zoom="12" center="chicago" </gmp-map>
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
<gmp-map zoom="12" center="chicago" </gmp-map>
<gmp-map zoom="12" center="41.85, -87.65"> </gmp-map>

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The gmp-map element needs lat/lng coordinates. I usually just use whatever's been defined in the TS (in this case the value for chicago rather than the variable).


<body>
<gmp-map zoom="12" center="chicago" </gmp-map>
<!--
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can remove ln. 28 - ln. 37, since you're now using the dynamic bootstrap.

*/

// [START maps_control_custom]
let map: google.maps.Map;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can remove this since you're now using innerMap instead of map.

<!doctype html>
<!--
@license
Copyright 2019 Google LLC. All Rights Reserved.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Global: Update all license header copyright dates to 2026.

/**
* Creates a control that recenters the map on Chicago.
*/
function createCenterControl(map) {
Copy link
Collaborator

@willum070 willum070 Feb 20, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here is where the fun begins! My practice has been to refactor things to be declarative rather than generate UI programmatically. Here are the steps I'd recommend:

  • Take the CSS definitions from the createCenterControl() function and move them into a new CSS style.
  • Nest the button element in the gmp-map element and use the slot attribute to position it.
  • Within initMap(), add code to get the button element from the HTML.
  • Move the event handler for the button into initMap().
  • Remove the createCenterControl() function.
  • Remove the injection code on ln. 61 - ln. 68, as it's not needed now that you've got HTML.

See #1119 for reference.

@@ -0,0 +1,25 @@
/**
* @license
* Copyright 2019 Google LLC. All Rights Reserved.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Update to 2026

*/
/* [START maps_control_custom] */
/*
* Always set the map height explicitly to define the size of the div element
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove the comment ln. 8 - ln. 10

* Always set the map height explicitly to define the size of the div element
* that contains the map.
*/
#map {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can remove this style now that gmp-map is in use.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants