Skip to content
Closed
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
21 changes: 9 additions & 12 deletions e2e/samples.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@
* limitations under the License.
*/

/* eslint-disable @typescript-eslint/no-unsafe-return */

import { test, expect } from '@playwright/test';
import fs from 'node:fs';
import path from 'node:path';
Expand Down Expand Up @@ -138,7 +136,7 @@ foldersToTest.forEach((sampleFolder) => {
test(`test ${sampleFolder}`, async ({ page }) => {
// START run the preview
// Get an available port
const port = 8080;
const port = '8080';
const url = `http://localhost:${port}/`;

const viteProcess = childProcess.spawn(
Expand Down Expand Up @@ -205,8 +203,9 @@ foldersToTest.forEach((sampleFolder) => {

// Wait for Google Maps to load.
await page.waitForFunction(
// eslint-disable-next-line @typescript-eslint/no-explicit-any
() => (window as any).google?.maps,
() =>
(window as typeof window & { google?: { maps?: unknown } })
.google?.maps,
{ timeout: 500 }
);

Expand All @@ -216,12 +215,10 @@ foldersToTest.forEach((sampleFolder) => {
// Assertions. These must be met or the test will fail.
// The sample must load the Google Maps API.
const hasGoogleMaps = await page.evaluate(() => {
return (
// eslint-disable-next-line @typescript-eslint/no-explicit-any
typeof (window as any).google !== 'undefined' &&
// eslint-disable-next-line @typescript-eslint/no-explicit-any
typeof (window as any).google.maps !== 'undefined'
);
const w = window as typeof window & {
google?: { maps?: unknown };
};
return typeof w.google?.maps !== 'undefined';
});
expect(hasGoogleMaps).toBeTruthy();

Expand All @@ -240,7 +237,7 @@ foldersToTest.forEach((sampleFolder) => {
process.kill(viteProcess.pid, 'SIGINT');
} catch (error) {
console.warn(
`Failed to kill Vite process for ${sampleFolder} (PID: ${viteProcess.pid}):`,
`Failed to kill Vite process for ${sampleFolder} (PID: ${String(viteProcess.pid)}):`,
error
);
}
Expand Down
5 changes: 3 additions & 2 deletions e2e/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,9 @@ import process from 'node:process';

export async function waitForGoogleMapsToLoad(page: Page) {
await page.waitForFunction(
// eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/no-unsafe-return
() => (window as any).google?.maps
() =>
(window as typeof window & { google?: { maps?: unknown } }).google
?.maps
);
await page.waitForTimeout(100);
}
Expand Down
9 changes: 8 additions & 1 deletion eslint.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,14 @@ export default defineConfig([
'@typescript-eslint/no-non-null-assertion': 'off',

// downgraded to warn for historic reasons:
'@typescript-eslint/restrict-template-expressions': 'warn',
'@typescript-eslint/restrict-template-expressions': [
'warn',
{
allowNumber: true,
allowNullish: true,
allowBoolean: true,
},
],
'@typescript-eslint/restrict-plus-operands': 'warn',
'@typescript-eslint/prefer-nullish-coalescing': 'warn',

Expand Down
2 changes: 1 addition & 1 deletion samples/3d-accessibility-features/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ async function init() {

tourStops.forEach(({ position, title }, i) => {
const pin = new PinElement({
glyphText: `${i + 1}`,
glyphText: String(i + 1),
scale: 1.5,
glyphColor: '#FFFFFF',
});
Expand Down
11 changes: 8 additions & 3 deletions samples/3d-camera-position/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ async function initMap(): Promise<void> {
const fov = fovClamped.toString();
const roll = map3DElement.roll?.toFixed(0) ?? '0';
const center = map3DElement.center;
const mode = map3DElement.mode;

headingVal.textContent = heading;
tiltVal.textContent = tilt;
Expand All @@ -68,7 +67,7 @@ async function initMap(): Promise<void> {
lngSlider.value = lng;
altitudeVal.textContent = alt;

codeElem.textContent = `<gmp-map-3d center="${lat},${lng},${alt}" mode="${mode}" tilt="${tilt}" range="${range}" heading="${heading}" fov="${fov}" roll="${roll}"></gmp-map-3d>`;
codeElem.textContent = `<gmp-map-3d center="${lat},${lng},${alt}" tilt="${tilt}" range="${range}" heading="${heading}" fov="${fov}" roll="${roll}"></gmp-map-3d>`;
}
};

Expand Down Expand Up @@ -124,8 +123,14 @@ async function initMap(): Promise<void> {
map3DElement.tilt = Math.max(0, val);
} else if (prop === 'fov') {
map3DElement.fov = Math.min(80, Math.max(5, val));
} else if (prop === 'heading') {
map3DElement.heading = val;
} else if (prop === 'range') {
map3DElement.range = val;
} else if (prop === 'roll') {
map3DElement.roll = val;
} else {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
// eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/no-unsafe-member-access
(map3DElement as any)[prop] = val;
Comment thread
willum070 marked this conversation as resolved.
}
updateUI();
Expand Down
2 changes: 1 addition & 1 deletion samples/3d-clamp-mode/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
*/

// [START maps_3d_clamp_mode]
let polyline: google.maps.maps3d.Polyline3DElement;
let polyline: google.maps.maps3d.Polyline3DElement | undefined;

async function init() {
const { Map3DElement, Polyline3DElement } =
Expand Down
1 change: 0 additions & 1 deletion samples/3d-coverage-map/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ async function init() {
placeAutocomplete.addEventListener(
'gmp-select',
async ({ placePrediction }) => {
if (!placePrediction) return;
const place = placePrediction.toPlace();
await place.fetchFields({
fields: ['location'],
Expand Down
2 changes: 1 addition & 1 deletion samples/3d-map-events/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ async function init() {
(i) => i.textContent
);
for (const event of events) {
mapElement?.addEventListener(event, () => {
mapElement.addEventListener(event, () => {
const eventElement = document.querySelector(`#${event}`);
eventElement?.classList.add('active');
setTimeout(() => {
Expand Down
11 changes: 4 additions & 7 deletions samples/3d-places-autocomplete/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,6 @@
* SPDX-License-Identifier: Apache-2.0
*/

/* eslint-disable @typescript-eslint/no-unsafe-assignment */
/* eslint-disable @typescript-eslint/no-unsafe-call */

// [START maps_3d_places_autocomplete]
let map: google.maps.maps3d.Map3DElement;

Expand All @@ -29,11 +26,11 @@ async function init() {
}

async function initAutocomplete() {
// @ts-expect-error - currently missing. bug fix pending
const { PlaceAutocompleteElement } =
await google.maps.importLibrary('places');

const placeAutocomplete = new PlaceAutocompleteElement();
const options: google.maps.places.PlaceAutocompleteElementOptions = {};
const placeAutocomplete = new PlaceAutocompleteElement(options);
placeAutocomplete.id = 'place-autocomplete-input';
const card = document.getElementById('pac-container')!;
card.appendChild(placeAutocomplete);
Expand All @@ -49,7 +46,7 @@ async function initAutocomplete() {
});
// If the place has a geometry, then present it on a map.
if (!place.location) {
window.alert('No viewport for input: ' + place.displayName);
window.alert(`No viewport for input: ${place.displayName}`);
return;
}
void flyToPlace(place);
Expand Down Expand Up @@ -107,7 +104,7 @@ async function getElevationforPoint(
locations: [location],
});

if (!elevationResponse?.results.length) {
if (!elevationResponse.results.length) {
window.alert(
`Insufficient elevation data for place: ${place.displayName}`
);
Expand Down
4 changes: 1 addition & 3 deletions samples/3d-places-autocomplete/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,5 @@
"build:vite": "vite build --base './'",
"preview": "vite preview"
},
"dependencies": {

}
"dependencies": {}
}
4 changes: 2 additions & 2 deletions samples/3d-places/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ async function init() {

// Display place details.
document.getElementById('placeName')!.innerHTML =
'<b>Name :</b><br>&nbsp;' + place.displayName;
`<b>Name :</b><br>&nbsp;${place.displayName ?? ''}`;
document.getElementById('placeId')!.innerHTML =
'<b>Id :</b><br>&nbsp;' + place.id;
`<b>Id :</b><br>&nbsp;${place.id}`;
document.getElementById('placeType')!.innerHTML = '<b>Types :<b/>';

for (const type of place.types ?? []) {
Expand Down
2 changes: 1 addition & 1 deletion samples/3d-polygon-click-event/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ function randomizeHexColor(originalHexColor: string) {
const g = Math.floor(Math.random() * 256);
const b = Math.floor(Math.random() * 256);

console.log(r + ' ' + g + ' ' + b);
console.log(`${r} ${g} ${b}`);

// Convert decimal to 2-digit hex, padding with '0' if needed
const rHex = ('0' + r.toString(16)).slice(-2);
Expand Down
6 changes: 3 additions & 3 deletions samples/address-validation/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ async function handleValidationSubmit(event: Event) {
// Verdict messages
const verdictMessages: Record<
string,
{ trueMessage: string; falseMessage: string }
{ trueMessage: string; falseMessage: string } | undefined
> = {
addressComplete: {
trueMessage:
Expand Down Expand Up @@ -155,7 +155,7 @@ interface ExampleAddress {
}

// Example Address Data
const examples: Record<string, ExampleAddress> = {
const examples: Record<string, ExampleAddress | undefined> = {
google: {
streetAddress1: '1600 Amphitheatre Parkway',
streetAddress2: '', // Explicitly empty
Expand Down Expand Up @@ -215,7 +215,7 @@ function populateAddressFields(exampleAddress: ExampleAddress | null) {

// Get values from example, providing empty string as default
streetAddress1Input.value = exampleAddress.streetAddress1 || '';
streetAddress2Input.value = exampleAddress.streetAddress2 || '';
streetAddress2Input.value = exampleAddress.streetAddress2 ?? '';
cityInput.value = exampleAddress.city || '';
stateInput.value = exampleAddress.state || '';
zipCodeInput.value = exampleAddress.zipCode || '';
Expand Down
2 changes: 1 addition & 1 deletion samples/advanced-markers-accessibility/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ async function init() {
tourStops.forEach(({ position, title }, i) => {
// [START maps_advanced_markers_accessibility_marker]
const pin = new PinElement({
glyphText: `${i + 1}`,
glyphText: String(i + 1),
scale: 1.5,
});
const marker = new AdvancedMarkerElement({
Expand Down
2 changes: 1 addition & 1 deletion samples/advanced-markers-animation/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ function createMarker(
content.style.opacity = '1';
});
const time = 2 + Math.random(); // 2s delay for easy to see the animation
content.style.setProperty('--delay-time', time + 's');
content.style.setProperty('--delay-time', `${time}s`);
intersectionObserver.observe(content);
}

Expand Down
20 changes: 7 additions & 13 deletions samples/ai-powered-summaries/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,10 +88,8 @@ function updateSummaryPanel(place: google.maps.places.Place) {
summaryContent.textContent = '';
aiDisclosure.textContent = '';

placeName.textContent = place.displayName || '';
placeAddress.textContent = place.formattedAddress || '';

let firstTabActivated = false;
placeName.textContent = place.displayName ?? '';
placeAddress.textContent = place.formattedAddress ?? '';

/**
* Safe Helper: Accepts either a text string or a DOM Node (like a div or DocumentFragment).
Expand Down Expand Up @@ -125,7 +123,7 @@ function updateSummaryPanel(place: google.maps.places.Place) {
}

// Set the disclosure text.
aiDisclosure.textContent = disclosure || 'AI-generated content.';
aiDisclosure.textContent = disclosure ?? 'AI-generated content.';

// Add the content flag URI.
if (flagUrl) {
Expand All @@ -135,12 +133,6 @@ function updateSummaryPanel(place: google.maps.places.Place) {
};

tabContainer.appendChild(btn);

// Auto-select the first available summary.
if (!firstTabActivated) {
btn.click();
firstTabActivated = true;
}
};

// --- 1. Generative Summary (Place) ---
Expand Down Expand Up @@ -227,8 +219,10 @@ function updateSummaryPanel(place: google.maps.places.Place) {
}
}

// Safely handle the empty state.
if (!firstTabActivated) {
// Safely handle the empty state or activate first tab.
if (tabContainer.firstChild) {
(tabContainer.firstChild as HTMLButtonElement).click();
} else {
const msg = document.createElement('em');
msg.textContent =
'No AI summaries are available for this specific location.';
Expand Down
2 changes: 1 addition & 1 deletion samples/boundaries-click/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ async function init() {
// If the map gets a mousemove, that means there are no feature layers
// with listeners registered under the mouse, so we clear the last
// interacted feature ids.
if (lastInteractedFeatureIds?.length) {
if (lastInteractedFeatureIds.length) {
lastInteractedFeatureIds = [];
featureLayer.style = applyStyle;
}
Expand Down
4 changes: 2 additions & 2 deletions samples/control-replacement/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,11 @@ function initZoomControl(map: google.maps.Map) {
const zoomOutButton = document.querySelector('.zoom-control-out')!;

zoomInButton.addEventListener('click', () => {
map.setZoom((map.getZoom() || 0) + 1);
map.setZoom((map.getZoom() ?? 0) + 1);
});

zoomOutButton.addEventListener('click', () => {
map.setZoom((map.getZoom() || 0) - 1);
map.setZoom((map.getZoom() ?? 0) - 1);
});
}

Expand Down
18 changes: 7 additions & 11 deletions samples/dds-datasets-polygon-click/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,16 @@ let datasetLayer: google.maps.FeatureLayer;
// [START maps_dds_datasets_polygon_click_eventhandler]
// Note, 'globalid' is an attribute in this Dataset.
function handleClick(event: google.maps.FeatureMouseEvent) {
if (event.features) {
lastClickedFeatureIds = event.features.map(
(f) => (f as google.maps.DatasetFeature).datasetAttributes.globalid
);
}
lastClickedFeatureIds = event.features.map(
(f) => (f as google.maps.DatasetFeature).datasetAttributes.globalid
);
datasetLayer.style = applyStyle;
}

function handleMouseMove(event: google.maps.FeatureMouseEvent) {
if (event.features) {
lastInteractedFeatureIds = event.features.map(
(f) => (f as google.maps.DatasetFeature).datasetAttributes.globalid
);
}
lastInteractedFeatureIds = event.features.map(
(f) => (f as google.maps.DatasetFeature).datasetAttributes.globalid
);
datasetLayer.style = applyStyle;
}
// [END maps_dds_datasets_polygon_click_eventhandler]
Expand All @@ -54,7 +50,7 @@ async function init() {
// If the map gets a mousemove, that means there are no feature layers
// with listeners registered under the mouse, so we clear the last
// interacted feature ids.
if (lastInteractedFeatureIds?.length) {
if (lastInteractedFeatureIds.length) {
lastInteractedFeatureIds = [];
datasetLayer.style = applyStyle;
}
Expand Down
Loading
Loading