Skip to content

Commit 8cc6a86

Browse files
authored
feat: Migrates DDS boundaries-simple sample; quality and standards. (#877)
* feat: Migrates DDS boundaries-simple sample; quality and standards. * Update feature layer to explicitly use google.maps.FeatureType. * Add comment tag and region for feature layer retrieval Added region to indicate start and end of feature layer retrieval.
1 parent a79ccba commit 8cc6a86

File tree

6 files changed

+171
-0
lines changed

6 files changed

+171
-0
lines changed
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
# Google Maps JavaScript Sample
2+
3+
This sample is generated from @googlemaps/js-samples located at
4+
https://github.com/googlemaps-samples/js-api-samples.
5+
6+
## Setup
7+
8+
### Before starting run:
9+
10+
`npm i`
11+
12+
### Run an example on a local web server
13+
14+
`cd samples/boundaries-simple`
15+
`npm start`
16+
17+
### Build an individual example
18+
19+
`cd samples/boundaries-simple`
20+
`npm run build`
21+
22+
From 'samples':
23+
24+
`npm run build --workspace=boundaries-simple/`
25+
26+
### Build all of the examples.
27+
28+
From 'samples':
29+
30+
`npm run build-all`
31+
32+
### Run lint to check for problems
33+
34+
`cd samples/boundaries-simple`
35+
`npx eslint index.ts`
36+
37+
## Feedback
38+
39+
For feedback related to this sample, please open a new issue on
40+
[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 2025 Google LLC. All Rights Reserved.
5+
SPDX-License-Identifier: Apache-2.0
6+
-->
7+
<!-- [START maps_boundaries_simple] -->
8+
<html>
9+
<head>
10+
<title>Boundaries Simple</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: "AIzaSyB41DRUbKWJHPxaFjMAwdrzWzbVKartNGg", v: "weekly"});</script>
17+
</head>
18+
<body>
19+
<gmp-map center="20.773,-156.01" zoom="12" map-id="8b37d7206ccf0121d4414bb0">
20+
</body>
21+
</html>
22+
<!-- [END maps_boundaries_simple] -->

samples/boundaries-simple/index.ts

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
/**
2+
* @license
3+
* Copyright 2025 Google LLC. All Rights Reserved.
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
/**
8+
* This is the simplest possible data-driven styling example.
9+
* It calls the styling function with a Place ID.
10+
*/
11+
12+
// [START maps_boundaries_simple]
13+
let featureLayer;
14+
15+
async function initMap() {
16+
// Request needed libraries.
17+
await google.maps.importLibrary("maps") as google.maps.MapsLibrary;
18+
19+
// Get the gmp-map element.
20+
const mapElement = document.querySelector(
21+
"gmp-map"
22+
) as google.maps.MapElement;
23+
24+
// Get the inner map.
25+
const innerMap = mapElement.innerMap;
26+
27+
// [START maps_boundaries_simple_get_layer]
28+
// Get the feature layer.
29+
featureLayer = innerMap.getFeatureLayer(google.maps.FeatureType.LOCALITY);
30+
// [END maps_boundaries_simple_get_layer]
31+
32+
// [START maps_boundaries_simple_style_single]
33+
// Define a style with purple fill and border.
34+
const featureStyleOptions: google.maps.FeatureStyleOptions = {
35+
strokeColor: '#810FCB',
36+
strokeOpacity: 1.0,
37+
strokeWeight: 3.0,
38+
fillColor: '#810FCB',
39+
fillOpacity: 0.5
40+
};
41+
42+
// Apply the style to a single boundary.
43+
featureLayer.style = (options: { feature: { placeId: string; }; }) => {
44+
if (options.feature.placeId == 'ChIJ0zQtYiWsVHkRk8lRoB1RNPo') { // Hana, HI
45+
return featureStyleOptions;
46+
}
47+
};
48+
// [END maps_boundaries_simple_style_single]
49+
50+
}
51+
52+
initMap();
53+
// [END maps_boundaries_simple]
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"name": "@js-api-samples/boundaries-simple",
3+
"version": "1.0.0",
4+
"scripts": {
5+
"build": "tsc && bash ../jsfiddle.sh boundaries-simple && bash ../app.sh boundaries-simple && bash ../docs.sh boundaries-simple && npm run build:vite --workspace=. && bash ../dist.sh boundaries-simple",
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+
"dependencies": {
12+
13+
}
14+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/**
2+
* @license
3+
* Copyright 2025 Google LLC. All Rights Reserved.
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
/* [START maps_boundaries_simple] */
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_boundaries_simple] */
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+
}

0 commit comments

Comments
 (0)