Skip to content

Commit c6ce395

Browse files
authored
Merge branch 'main' into migrate-dds-datasets-polygon-click
2 parents 571d7a1 + 759589b commit c6ce395

File tree

21 files changed

+515
-0
lines changed

21 files changed

+515
-0
lines changed

dist/index.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ <h1>Maps JSAPI Samples</h1>
6060
<li><a href='/samples/control-simple/dist'>control-simple</a></li>
6161
<li><a href='/samples/dds-datasets-point/dist'>dds-datasets-point</a></li>
6262
<li><a href='/samples/dds-datasets-polygon/dist'>dds-datasets-polygon</a></li>
63+
<li><a href='/samples/dds-datasets-polygon-colors/dist'>dds-datasets-polygon-colors</a></li>
6364
<li><a href='/samples/dds-datasets-polyline/dist'>dds-datasets-polyline</a></li>
6465
<li><a href='/samples/dds-region-viewer/dist'>dds-region-viewer</a></li>
6566
<li><a href='/samples/deckgl-heatmap/dist'>deckgl-heatmap</a></li>
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"extends": [
3+
"plugin:@typescript-eslint/recommended"
4+
],
5+
"parser": "@typescript-eslint/parser",
6+
"rules": {
7+
"@typescript-eslint/ban-ts-comment": 0,
8+
"@typescript-eslint/no-this-alias": 1,
9+
"@typescript-eslint/no-empty-function": 1,
10+
"@typescript-eslint/explicit-module-boundary-types": 1,
11+
"@typescript-eslint/no-unused-vars": 1
12+
}
13+
}
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+
## dds-datasets-polygon-colors
4+
5+
This example shows an approach to styling polygon geometry based data features.
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/dds-datasets-polygon-colors`
16+
`npm start`
17+
18+
### Build an individual example
19+
20+
`cd samples/dds-datasets-polygon-colors`
21+
`npm run build`
22+
23+
From 'samples':
24+
25+
`npm run build --workspace=dds-datasets-polygon-colors/`
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/dds-datasets-polygon-colors`
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: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
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_dds_datasets_polygon_colors] -->
8+
<html>
9+
<head>
10+
<title>Style a polygon data feature with more detail</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="40.580732, -74.152826" zoom="14" map-id="5cd2c9ca1cf05670">
20+
<div id="attribution" slot="control-block-end-inline-start">Data source: NYC Open Data</div>
21+
</gmp-map>
22+
</body>
23+
</html>
24+
<!-- [END maps_dds_datasets_polygon_colors] -->
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
/**
2+
* @license
3+
* Copyright 2026 Google LLC. All Rights Reserved.
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
// [START maps_dds_datasets_polygon_colors]
8+
const mapElement = document.querySelector('gmp-map') as google.maps.MapElement;
9+
let innerMap;
10+
// [START maps_dds_datasets_polygon_colors_style_function]
11+
function setStyle(/* FeatureStyleFunctionOptions */ params) {
12+
const datasetFeature = params.feature;
13+
// 'typecategory' is an attribute in this Dataset.
14+
const typeCategory = datasetFeature.datasetAttributes['typecategory'];
15+
16+
switch (typeCategory) {
17+
case 'Undeveloped': // Color undeveloped areas blue.
18+
return /* FeatureStyleOptions */ {
19+
strokeColor: 'blue',
20+
strokeWeight: 2,
21+
strokeOpacity: 1,
22+
fillColor: 'blue',
23+
fillOpacity: 0.3,
24+
};
25+
break;
26+
case 'Parkway': // Color historical house sites red.
27+
return /* FeatureStyleOptions */ {
28+
strokeColor: 'red',
29+
strokeWeight: 2,
30+
strokeOpacity: 1,
31+
fillColor: 'red',
32+
fillOpacity: 0.5,
33+
};
34+
break;
35+
default: // Color other type categories green.
36+
return /* FeatureStyleOptions */ {
37+
strokeColor: 'green',
38+
strokeWeight: 2,
39+
strokeOpacity: 1,
40+
fillColor: 'green',
41+
fillOpacity: 0.3,
42+
};
43+
break;
44+
}
45+
}
46+
// [END maps_dds_datasets_polygon_colors_style_function]
47+
48+
async function initMap() {
49+
// Request needed libraries.
50+
await google.maps.importLibrary("maps") as google.maps.MapsLibrary;
51+
52+
// Get the inner map.
53+
innerMap = mapElement.innerMap;
54+
55+
// Dataset ID for NYC park data.
56+
const datasetId = 'a75dd002-ad20-4fe6-af60-27cd2ed636b4';
57+
const datasetLayer = innerMap.getDatasetFeatureLayer(datasetId);
58+
datasetLayer.style = setStyle;
59+
}
60+
61+
initMap();
62+
// [END maps_dds_datasets_polygon_colors]
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"name": "@js-api-samples/dds-datasets-polygon-colors",
3+
"version": "1.0.0",
4+
"scripts": {
5+
"build": "tsc && bash ../jsfiddle.sh dds-datasets-polygon-colors && bash ../app.sh dds-datasets-polygon-colors && bash ../docs.sh dds-datasets-polygon-colors && npm run build:vite --workspace=. && bash ../dist.sh dds-datasets-polygon-colors",
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: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/**
2+
* @license
3+
* Copyright 2026 Google LLC. All Rights Reserved.
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
/* [START maps_dds_datasets_polygon_colors] */
7+
8+
/*
9+
* Optional: Makes the sample page fill the window.
10+
*/
11+
html,
12+
body {
13+
height: 100%;
14+
margin: 0;
15+
padding: 0;
16+
}
17+
18+
#attribution {
19+
background-color: rgba(255, 255, 255, 0.7);
20+
font-family: "Roboto", "Arial", "sans-serif";
21+
font-size: 10px;
22+
padding: 2px;
23+
margin: 2px;
24+
}
25+
26+
/* [END maps_dds_datasets_polygon_colors] */
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+
}

dist/samples/dds-datasets-polygon-colors/dist/assets/index-BqXZ8XbW.js

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
html,body{height:100%;margin:0;padding:0}#attribution{background-color:#ffffffb3;font-family:Roboto,Arial,"sans-serif";font-size:10px;padding:2px;margin:2px}

0 commit comments

Comments
 (0)