diff --git a/dist/index.html b/dist/index.html index 3e7d260c..fb0b71f2 100644 --- a/dist/index.html +++ b/dist/index.html @@ -46,6 +46,7 @@

Maps JSAPI Samples

  • advanced-markers-html-simple
  • advanced-markers-simple
  • advanced-markers-zoom
  • +
  • boundaries-choropleth
  • boundaries-simple
  • deckgl-heatmap
  • deckgl-kml
  • diff --git a/dist/samples/boundaries-choropleth/app/.eslintsrc.json b/dist/samples/boundaries-choropleth/app/.eslintsrc.json new file mode 100644 index 00000000..4c44dab0 --- /dev/null +++ b/dist/samples/boundaries-choropleth/app/.eslintsrc.json @@ -0,0 +1,13 @@ +{ + "extends": [ + "plugin:@typescript-eslint/recommended" + ], + "parser": "@typescript-eslint/parser", + "rules": { + "@typescript-eslint/ban-ts-comment": 0, + "@typescript-eslint/no-this-alias": 1, + "@typescript-eslint/no-empty-function": 1, + "@typescript-eslint/explicit-module-boundary-types": 1, + "@typescript-eslint/no-unused-vars": 1 + } +} diff --git a/dist/samples/boundaries-choropleth/app/README.md b/dist/samples/boundaries-choropleth/app/README.md new file mode 100644 index 00000000..183237d4 --- /dev/null +++ b/dist/samples/boundaries-choropleth/app/README.md @@ -0,0 +1,40 @@ +# Google Maps JavaScript Sample + +This sample is generated from @googlemaps/js-samples located at +https://github.com/googlemaps-samples/js-api-samples. + +## Setup + +### Before starting run: + +`npm i` + +### Run an example on a local web server + +`cd samples/boundaries-choropleth` +`npm start` + +### Build an individual example + +`cd samples/boundaries-choropleth` +`npm run build` + +From 'samples': + +`npm run build --workspace=boundaries-choropleth/` + +### Build all of the examples. + +From 'samples': + +`npm run build-all` + +### Run lint to check for problems + +`cd samples/boundaries-choropleth` +`npx eslint index.ts` + +## Feedback + +For feedback related to this sample, please open a new issue on +[GitHub](https://github.com/googlemaps-samples/js-api-samples/issues). diff --git a/dist/samples/boundaries-choropleth/app/index.html b/dist/samples/boundaries-choropleth/app/index.html new file mode 100644 index 00000000..80ea24c5 --- /dev/null +++ b/dist/samples/boundaries-choropleth/app/index.html @@ -0,0 +1,22 @@ + + + + + + Choropleth Map + + + + + + + + + + + diff --git a/dist/samples/boundaries-choropleth/app/index.ts b/dist/samples/boundaries-choropleth/app/index.ts new file mode 100644 index 00000000..8fb59b08 --- /dev/null +++ b/dist/samples/boundaries-choropleth/app/index.ts @@ -0,0 +1,108 @@ +/** + * @license + * Copyright 2025 Google LLC. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 + */ + +// [START maps_boundaries_choropleth] +async function initMap() { + // Request needed libraries. + (await google.maps.importLibrary('maps')) as google.maps.MapsLibrary; + + // Get the gmp-map element. + const mapElement = document.querySelector( + 'gmp-map' + ) as google.maps.MapElement; + + // Get the inner map. + const innerMap = mapElement.innerMap; + + const featureLayer = innerMap.getFeatureLayer( + google.maps.FeatureType.ADMINISTRATIVE_AREA_LEVEL_1 + ); + + // [START maps_boundaries_choropleth_style_function] + featureLayer.style = (featureStyleFunctionOptions) => { + const placeFeature = + featureStyleFunctionOptions.feature as google.maps.PlaceFeature; + const population = states[placeFeature.placeId]; + + let fillColor; + // Specify colors using any of the following: + // * Named ('green') + // * Hexadecimal ('#FF0000') + // * RGB ('rgb(0, 0, 255)') + // * HSL ('hsl(60, 100%, 50%)') + + if (population < 2000000) { + fillColor = 'green'; + } else if (population < 5000000) { + fillColor = 'red'; + } else if (population < 10000000) { + fillColor = 'blue'; + } else if (population < 40000000) { + fillColor = 'yellow'; + } + return { + fillColor, + fillOpacity: 0.5, + }; + }; + // [END maps_boundaries_choropleth_style_function] + // Population data by state. + const states = { + 'ChIJdf5LHzR_hogR6czIUzU0VV4': 5039877, // Alabama + 'ChIJG8CuwJzfAFQRNduKqSde27w': 732673, // Alaska + 'ChIJaxhMy-sIK4cRcc3Bf7EnOUI': 7276316, // Arizona + 'ChIJYSc_dD-e0ocR0NLf_z5pBaQ': 3025891, // Arkansas + 'ChIJPV4oX_65j4ARVW8IJ6IJUYs': 39237836, // California + 'ChIJt1YYm3QUQIcR_6eQSTGDVMc': 5812069, // Colorado + 'ChIJpVER8hFT5okR5XBhBVttmq4': 3605597, // Connecticut + 'ChIJO9YMTXYFx4kReOgEjBItHZQ': 1003384, // Delaware + 'ChIJvypWkWV2wYgR0E7HW9MTLvc': 21781128, // Florida + 'ChIJV4FfHcU28YgR5xBP7BC8hGY': 10799566, // Georgia + 'ChIJBeB5Twbb_3sRKIbMdNKCd0s': 1441553, // Hawaii + 'ChIJ6Znkhaj_WFMRWIf3FQUwa9A': 1900923, // Idaho + 'ChIJGSZubzgtC4gRVlkRZFCCFX8': 12671469, // Illinois + 'ChIJHRv42bxQa4gRcuwyy84vEH4': 6805985, // Indiana + 'ChIJGWD48W9e7ocR2VnHV0pj78Y': 3193079, // Iowa + 'ChIJawF8cXEXo4cRXwk-S6m0wmg': 2934582, // Kansas + 'ChIJyVMZi0xzQogR_N_MxU5vH3c': 4509394, // Kentucky + 'ChIJZYIRslSkIIYRA0flgTL3Vck': 4624047, // Louisiana + 'ChIJ1YpTHd4dsEwR0KggZ2_MedY': 1372247, // Maine + 'ChIJ35Dx6etNtokRsfZVdmU3r_I': 6165129, // Maryland + 'ChIJ_b9z6W1l44kRHA2DVTbQxkU': 6984723, // Massachussetts + 'ChIJEQTKxz2qTE0Rs8liellI3Zc': 10050811, // Michigan + 'ChIJmwt4YJpbWE0RD6L-EJvJogI': 5707390, // Minnesota + 'ChIJGdRK5OQyKIYR2qbc6X8XDWI': 2949965, // Mississippi + 'ChIJfeMiSNXmwIcRcr1mBFnEW7U': 6168187, // Misssouri + 'ChIJ04p7LZwrQVMRGGwqz1jWcfU': 1104271, // Montana + 'ChIJ7fwMtciNk4cRxArzDwyQJ6E': 1963692, // Nebraska + 'ChIJcbTe-KEKmYARs5X8qooDR88': 3143991, // Nevada + 'ChIJ66bAnUtEs0wR64CmJa8CyNc': 1388992, // New Hampshire + 'ChIJn0AAnpX7wIkRjW0_-Ad70iw': 9267130, // New Jersey + 'ChIJqVKY50NQGIcRup41Yxpuv0Y': 2115877, // New Mexico + 'ChIJqaUj8fBLzEwRZ5UY3sHGz90': 19835913, // New York + 'ChIJgRo4_MQfVIgRGa4i6fUwP60': 10551162, // North Carolina + 'ChIJY-nYVxKD11IRyc9egzmahA0': 774948, // North Dakota + 'ChIJwY5NtXrpNogRFtmfnDlkzeU': 11780017, // Ohio + 'ChIJnU-ssRE5rIcRSOoKQDPPHF0': 3986639, // Oklahoma + 'ChIJVWqfm3xuk1QRdrgLettlTH0': 4246155, // Oregon + 'ChIJieUyHiaALYgRPbQiUEchRsI': 12964056, // Pennsylvania + 'ChIJD9cOYhQ15IkR5wbB57wYTh4': 1095610, // Rhode Island + 'ChIJ49ExeWml-IgRnhcF9TKh_7k': 5190705, // South Carolina + 'ChIJpTjphS1DfYcRt6SGMSnW8Ac': 895376, // South Dakota + 'ChIJA8-XniNLYYgRVpGBpcEgPgM': 6975218, // Tennessee + 'ChIJSTKCCzZwQIYRPN4IGI8c6xY': 29527941, // Texas + 'ChIJzfkTj8drTIcRP0bXbKVK370': 3337975, // Utah + 'ChIJ_87aSGzctEwRtGtUNnSJTSY': 645570, // Vermont + 'ChIJzbK8vXDWTIgRlaZGt0lBTsA': 8642274, // Virginia + 'ChIJ-bDD5__lhVQRuvNfbGh4QpQ': 7738692, // Washington + 'ChIJRQnL1KVUSogRQzrN3mjHALs': 1782959, // West Virginia + 'ChIJr-OEkw_0qFIR1kmG-LjV1fI': 5895908, // Wisconsin + 'ChIJaS7hSDTiXocRLzh90nkisCY': 578803, // Wyoming + }; +} + +initMap(); +// [END maps_boundaries_choropleth] diff --git a/dist/samples/boundaries-choropleth/app/package.json b/dist/samples/boundaries-choropleth/app/package.json new file mode 100644 index 00000000..f04f31f4 --- /dev/null +++ b/dist/samples/boundaries-choropleth/app/package.json @@ -0,0 +1,14 @@ +{ + "name": "@js-api-samples/boundaries-choropleth", + "version": "1.0.0", + "scripts": { + "build": "tsc && bash ../jsfiddle.sh boundaries-choropleth && bash ../app.sh boundaries-choropleth && bash ../docs.sh boundaries-choropleth && npm run build:vite --workspace=. && bash ../dist.sh boundaries-choropleth", + "test": "tsc && npm run build:vite --workspace=.", + "start": "tsc && vite build --base './' && vite", + "build:vite": "vite build --base './'", + "preview": "vite preview" + }, + "dependencies": { + + } +} diff --git a/dist/samples/boundaries-choropleth/app/style.css b/dist/samples/boundaries-choropleth/app/style.css new file mode 100644 index 00000000..bae1997d --- /dev/null +++ b/dist/samples/boundaries-choropleth/app/style.css @@ -0,0 +1,25 @@ +/** + * @license + * Copyright 2025 Google LLC. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 + */ +/* [START maps_boundaries_choropleth] */ +/* + * Always set the map height explicitly to define the size of the div element + * that contains the map. + */ +gmp-map { + height: 100%; +} + +/* + * Optional: Makes the sample page fill the window. + */ +html, +body { + height: 100%; + margin: 0; + padding: 0; +} + +/* [END maps_boundaries_choropleth] */ \ No newline at end of file diff --git a/dist/samples/boundaries-choropleth/app/tsconfig.json b/dist/samples/boundaries-choropleth/app/tsconfig.json new file mode 100644 index 00000000..366aabb0 --- /dev/null +++ b/dist/samples/boundaries-choropleth/app/tsconfig.json @@ -0,0 +1,17 @@ +{ + "compilerOptions": { + "module": "esnext", + "target": "esnext", + "strict": true, + "noImplicitAny": false, + "lib": [ + "es2015", + "esnext", + "es6", + "dom", + "dom.iterable" + ], + "moduleResolution": "Node", + "jsx": "preserve" + } +} diff --git a/dist/samples/boundaries-choropleth/dist/assets/index-CgdwweuI.js b/dist/samples/boundaries-choropleth/dist/assets/index-CgdwweuI.js new file mode 100644 index 00000000..0513e904 --- /dev/null +++ b/dist/samples/boundaries-choropleth/dist/assets/index-CgdwweuI.js @@ -0,0 +1,5 @@ +(function(){const c=document.createElement("link").relList;if(c&&c.supports&&c.supports("modulepreload"))return;for(const e of document.querySelectorAll('link[rel="modulepreload"]'))o(e);new MutationObserver(e=>{for(const t of e)if(t.type==="childList")for(const I of t.addedNodes)I.tagName==="LINK"&&I.rel==="modulepreload"&&o(I)}).observe(document,{childList:!0,subtree:!0});function h(e){const t={};return e.integrity&&(t.integrity=e.integrity),e.referrerPolicy&&(t.referrerPolicy=e.referrerPolicy),e.crossOrigin==="use-credentials"?t.credentials="include":e.crossOrigin==="anonymous"?t.credentials="omit":t.credentials="same-origin",t}function o(e){if(e.ep)return;e.ep=!0;const t=h(e);fetch(e.href,t)}})();/** + * @license + * Copyright 2025 Google LLC. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 + */async function s(){await google.maps.importLibrary("maps");const h=document.querySelector("gmp-map").innerMap.getFeatureLayer(google.maps.FeatureType.ADMINISTRATIVE_AREA_LEVEL_1);h.style=e=>{const t=e.feature,I=o[t.placeId];let r;return I<2e6?r="green":I<5e6?r="red":I<1e7?r="blue":I<4e7&&(r="yellow"),{fillColor:r,fillOpacity:.5}};const o={ChIJdf5LHzR_hogR6czIUzU0VV4:5039877,ChIJG8CuwJzfAFQRNduKqSde27w:732673,"ChIJaxhMy-sIK4cRcc3Bf7EnOUI":7276316,"ChIJYSc_dD-e0ocR0NLf_z5pBaQ":3025891,ChIJPV4oX_65j4ARVW8IJ6IJUYs:39237836,ChIJt1YYm3QUQIcR_6eQSTGDVMc:5812069,ChIJpVER8hFT5okR5XBhBVttmq4:3605597,ChIJO9YMTXYFx4kReOgEjBItHZQ:1003384,ChIJvypWkWV2wYgR0E7HW9MTLvc:21781128,ChIJV4FfHcU28YgR5xBP7BC8hGY:10799566,ChIJBeB5Twbb_3sRKIbMdNKCd0s:1441553,ChIJ6Znkhaj_WFMRWIf3FQUwa9A:1900923,ChIJGSZubzgtC4gRVlkRZFCCFX8:12671469,ChIJHRv42bxQa4gRcuwyy84vEH4:6805985,ChIJGWD48W9e7ocR2VnHV0pj78Y:3193079,"ChIJawF8cXEXo4cRXwk-S6m0wmg":2934582,ChIJyVMZi0xzQogR_N_MxU5vH3c:4509394,ChIJZYIRslSkIIYRA0flgTL3Vck:4624047,ChIJ1YpTHd4dsEwR0KggZ2_MedY:1372247,ChIJ35Dx6etNtokRsfZVdmU3r_I:6165129,ChIJ_b9z6W1l44kRHA2DVTbQxkU:6984723,ChIJEQTKxz2qTE0Rs8liellI3Zc:10050811,"ChIJmwt4YJpbWE0RD6L-EJvJogI":5707390,ChIJGdRK5OQyKIYR2qbc6X8XDWI:2949965,ChIJfeMiSNXmwIcRcr1mBFnEW7U:6168187,ChIJ04p7LZwrQVMRGGwqz1jWcfU:1104271,ChIJ7fwMtciNk4cRxArzDwyQJ6E:1963692,"ChIJcbTe-KEKmYARs5X8qooDR88":3143991,ChIJ66bAnUtEs0wR64CmJa8CyNc:1388992,"ChIJn0AAnpX7wIkRjW0_-Ad70iw":9267130,ChIJqVKY50NQGIcRup41Yxpuv0Y:2115877,ChIJqaUj8fBLzEwRZ5UY3sHGz90:19835913,ChIJgRo4_MQfVIgRGa4i6fUwP60:10551162,"ChIJY-nYVxKD11IRyc9egzmahA0":774948,ChIJwY5NtXrpNogRFtmfnDlkzeU:11780017,"ChIJnU-ssRE5rIcRSOoKQDPPHF0":3986639,ChIJVWqfm3xuk1QRdrgLettlTH0:4246155,ChIJieUyHiaALYgRPbQiUEchRsI:12964056,ChIJD9cOYhQ15IkR5wbB57wYTh4:1095610,"ChIJ49ExeWml-IgRnhcF9TKh_7k":5190705,ChIJpTjphS1DfYcRt6SGMSnW8Ac:895376,"ChIJA8-XniNLYYgRVpGBpcEgPgM":6975218,ChIJSTKCCzZwQIYRPN4IGI8c6xY:29527941,ChIJzfkTj8drTIcRP0bXbKVK370:3337975,ChIJ_87aSGzctEwRtGtUNnSJTSY:645570,ChIJzbK8vXDWTIgRlaZGt0lBTsA:8642274,"ChIJ-bDD5__lhVQRuvNfbGh4QpQ":7738692,ChIJRQnL1KVUSogRQzrN3mjHALs:1782959,"ChIJr-OEkw_0qFIR1kmG-LjV1fI":5895908,ChIJaS7hSDTiXocRLzh90nkisCY:578803}}s(); diff --git a/dist/samples/boundaries-choropleth/dist/assets/index-i_98oPIq.css b/dist/samples/boundaries-choropleth/dist/assets/index-i_98oPIq.css new file mode 100644 index 00000000..c48393ed --- /dev/null +++ b/dist/samples/boundaries-choropleth/dist/assets/index-i_98oPIq.css @@ -0,0 +1,5 @@ +/** + * @license + * Copyright 2025 Google LLC. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 + */gmp-map{height:100%}html,body{height:100%;margin:0;padding:0} diff --git a/dist/samples/boundaries-choropleth/dist/index.html b/dist/samples/boundaries-choropleth/dist/index.html new file mode 100644 index 00000000..cb0d65b4 --- /dev/null +++ b/dist/samples/boundaries-choropleth/dist/index.html @@ -0,0 +1,22 @@ + + + + + + Choropleth Map + + + + + + + + + + + diff --git a/dist/samples/boundaries-choropleth/docs/index.html b/dist/samples/boundaries-choropleth/docs/index.html new file mode 100644 index 00000000..80ea24c5 --- /dev/null +++ b/dist/samples/boundaries-choropleth/docs/index.html @@ -0,0 +1,22 @@ + + + + + + Choropleth Map + + + + + + + + + + + diff --git a/dist/samples/boundaries-choropleth/docs/index.js b/dist/samples/boundaries-choropleth/docs/index.js new file mode 100644 index 00000000..4b040fe0 --- /dev/null +++ b/dist/samples/boundaries-choropleth/docs/index.js @@ -0,0 +1,99 @@ +"use strict"; +/** + * @license + * Copyright 2025 Google LLC. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 + */ +// [START maps_boundaries_choropleth] +async function initMap() { + // Request needed libraries. + (await google.maps.importLibrary('maps')); + // Get the gmp-map element. + const mapElement = document.querySelector('gmp-map'); + // Get the inner map. + const innerMap = mapElement.innerMap; + const featureLayer = innerMap.getFeatureLayer(google.maps.FeatureType.ADMINISTRATIVE_AREA_LEVEL_1); + // [START maps_boundaries_choropleth_style_function] + featureLayer.style = (featureStyleFunctionOptions) => { + const placeFeature = featureStyleFunctionOptions.feature; + const population = states[placeFeature.placeId]; + let fillColor; + // Specify colors using any of the following: + // * Named ('green') + // * Hexadecimal ('#FF0000') + // * RGB ('rgb(0, 0, 255)') + // * HSL ('hsl(60, 100%, 50%)') + if (population < 2000000) { + fillColor = 'green'; + } + else if (population < 5000000) { + fillColor = 'red'; + } + else if (population < 10000000) { + fillColor = 'blue'; + } + else if (population < 40000000) { + fillColor = 'yellow'; + } + return { + fillColor, + fillOpacity: 0.5, + }; + }; + // [END maps_boundaries_choropleth_style_function] + // Population data by state. + const states = { + 'ChIJdf5LHzR_hogR6czIUzU0VV4': 5039877, // Alabama + 'ChIJG8CuwJzfAFQRNduKqSde27w': 732673, // Alaska + 'ChIJaxhMy-sIK4cRcc3Bf7EnOUI': 7276316, // Arizona + 'ChIJYSc_dD-e0ocR0NLf_z5pBaQ': 3025891, // Arkansas + 'ChIJPV4oX_65j4ARVW8IJ6IJUYs': 39237836, // California + 'ChIJt1YYm3QUQIcR_6eQSTGDVMc': 5812069, // Colorado + 'ChIJpVER8hFT5okR5XBhBVttmq4': 3605597, // Connecticut + 'ChIJO9YMTXYFx4kReOgEjBItHZQ': 1003384, // Delaware + 'ChIJvypWkWV2wYgR0E7HW9MTLvc': 21781128, // Florida + 'ChIJV4FfHcU28YgR5xBP7BC8hGY': 10799566, // Georgia + 'ChIJBeB5Twbb_3sRKIbMdNKCd0s': 1441553, // Hawaii + 'ChIJ6Znkhaj_WFMRWIf3FQUwa9A': 1900923, // Idaho + 'ChIJGSZubzgtC4gRVlkRZFCCFX8': 12671469, // Illinois + 'ChIJHRv42bxQa4gRcuwyy84vEH4': 6805985, // Indiana + 'ChIJGWD48W9e7ocR2VnHV0pj78Y': 3193079, // Iowa + 'ChIJawF8cXEXo4cRXwk-S6m0wmg': 2934582, // Kansas + 'ChIJyVMZi0xzQogR_N_MxU5vH3c': 4509394, // Kentucky + 'ChIJZYIRslSkIIYRA0flgTL3Vck': 4624047, // Louisiana + 'ChIJ1YpTHd4dsEwR0KggZ2_MedY': 1372247, // Maine + 'ChIJ35Dx6etNtokRsfZVdmU3r_I': 6165129, // Maryland + 'ChIJ_b9z6W1l44kRHA2DVTbQxkU': 6984723, // Massachussetts + 'ChIJEQTKxz2qTE0Rs8liellI3Zc': 10050811, // Michigan + 'ChIJmwt4YJpbWE0RD6L-EJvJogI': 5707390, // Minnesota + 'ChIJGdRK5OQyKIYR2qbc6X8XDWI': 2949965, // Mississippi + 'ChIJfeMiSNXmwIcRcr1mBFnEW7U': 6168187, // Misssouri + 'ChIJ04p7LZwrQVMRGGwqz1jWcfU': 1104271, // Montana + 'ChIJ7fwMtciNk4cRxArzDwyQJ6E': 1963692, // Nebraska + 'ChIJcbTe-KEKmYARs5X8qooDR88': 3143991, // Nevada + 'ChIJ66bAnUtEs0wR64CmJa8CyNc': 1388992, // New Hampshire + 'ChIJn0AAnpX7wIkRjW0_-Ad70iw': 9267130, // New Jersey + 'ChIJqVKY50NQGIcRup41Yxpuv0Y': 2115877, // New Mexico + 'ChIJqaUj8fBLzEwRZ5UY3sHGz90': 19835913, // New York + 'ChIJgRo4_MQfVIgRGa4i6fUwP60': 10551162, // North Carolina + 'ChIJY-nYVxKD11IRyc9egzmahA0': 774948, // North Dakota + 'ChIJwY5NtXrpNogRFtmfnDlkzeU': 11780017, // Ohio + 'ChIJnU-ssRE5rIcRSOoKQDPPHF0': 3986639, // Oklahoma + 'ChIJVWqfm3xuk1QRdrgLettlTH0': 4246155, // Oregon + 'ChIJieUyHiaALYgRPbQiUEchRsI': 12964056, // Pennsylvania + 'ChIJD9cOYhQ15IkR5wbB57wYTh4': 1095610, // Rhode Island + 'ChIJ49ExeWml-IgRnhcF9TKh_7k': 5190705, // South Carolina + 'ChIJpTjphS1DfYcRt6SGMSnW8Ac': 895376, // South Dakota + 'ChIJA8-XniNLYYgRVpGBpcEgPgM': 6975218, // Tennessee + 'ChIJSTKCCzZwQIYRPN4IGI8c6xY': 29527941, // Texas + 'ChIJzfkTj8drTIcRP0bXbKVK370': 3337975, // Utah + 'ChIJ_87aSGzctEwRtGtUNnSJTSY': 645570, // Vermont + 'ChIJzbK8vXDWTIgRlaZGt0lBTsA': 8642274, // Virginia + 'ChIJ-bDD5__lhVQRuvNfbGh4QpQ': 7738692, // Washington + 'ChIJRQnL1KVUSogRQzrN3mjHALs': 1782959, // West Virginia + 'ChIJr-OEkw_0qFIR1kmG-LjV1fI': 5895908, // Wisconsin + 'ChIJaS7hSDTiXocRLzh90nkisCY': 578803, // Wyoming + }; +} +initMap(); +// [END maps_boundaries_choropleth] diff --git a/dist/samples/boundaries-choropleth/docs/index.ts b/dist/samples/boundaries-choropleth/docs/index.ts new file mode 100644 index 00000000..8fb59b08 --- /dev/null +++ b/dist/samples/boundaries-choropleth/docs/index.ts @@ -0,0 +1,108 @@ +/** + * @license + * Copyright 2025 Google LLC. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 + */ + +// [START maps_boundaries_choropleth] +async function initMap() { + // Request needed libraries. + (await google.maps.importLibrary('maps')) as google.maps.MapsLibrary; + + // Get the gmp-map element. + const mapElement = document.querySelector( + 'gmp-map' + ) as google.maps.MapElement; + + // Get the inner map. + const innerMap = mapElement.innerMap; + + const featureLayer = innerMap.getFeatureLayer( + google.maps.FeatureType.ADMINISTRATIVE_AREA_LEVEL_1 + ); + + // [START maps_boundaries_choropleth_style_function] + featureLayer.style = (featureStyleFunctionOptions) => { + const placeFeature = + featureStyleFunctionOptions.feature as google.maps.PlaceFeature; + const population = states[placeFeature.placeId]; + + let fillColor; + // Specify colors using any of the following: + // * Named ('green') + // * Hexadecimal ('#FF0000') + // * RGB ('rgb(0, 0, 255)') + // * HSL ('hsl(60, 100%, 50%)') + + if (population < 2000000) { + fillColor = 'green'; + } else if (population < 5000000) { + fillColor = 'red'; + } else if (population < 10000000) { + fillColor = 'blue'; + } else if (population < 40000000) { + fillColor = 'yellow'; + } + return { + fillColor, + fillOpacity: 0.5, + }; + }; + // [END maps_boundaries_choropleth_style_function] + // Population data by state. + const states = { + 'ChIJdf5LHzR_hogR6czIUzU0VV4': 5039877, // Alabama + 'ChIJG8CuwJzfAFQRNduKqSde27w': 732673, // Alaska + 'ChIJaxhMy-sIK4cRcc3Bf7EnOUI': 7276316, // Arizona + 'ChIJYSc_dD-e0ocR0NLf_z5pBaQ': 3025891, // Arkansas + 'ChIJPV4oX_65j4ARVW8IJ6IJUYs': 39237836, // California + 'ChIJt1YYm3QUQIcR_6eQSTGDVMc': 5812069, // Colorado + 'ChIJpVER8hFT5okR5XBhBVttmq4': 3605597, // Connecticut + 'ChIJO9YMTXYFx4kReOgEjBItHZQ': 1003384, // Delaware + 'ChIJvypWkWV2wYgR0E7HW9MTLvc': 21781128, // Florida + 'ChIJV4FfHcU28YgR5xBP7BC8hGY': 10799566, // Georgia + 'ChIJBeB5Twbb_3sRKIbMdNKCd0s': 1441553, // Hawaii + 'ChIJ6Znkhaj_WFMRWIf3FQUwa9A': 1900923, // Idaho + 'ChIJGSZubzgtC4gRVlkRZFCCFX8': 12671469, // Illinois + 'ChIJHRv42bxQa4gRcuwyy84vEH4': 6805985, // Indiana + 'ChIJGWD48W9e7ocR2VnHV0pj78Y': 3193079, // Iowa + 'ChIJawF8cXEXo4cRXwk-S6m0wmg': 2934582, // Kansas + 'ChIJyVMZi0xzQogR_N_MxU5vH3c': 4509394, // Kentucky + 'ChIJZYIRslSkIIYRA0flgTL3Vck': 4624047, // Louisiana + 'ChIJ1YpTHd4dsEwR0KggZ2_MedY': 1372247, // Maine + 'ChIJ35Dx6etNtokRsfZVdmU3r_I': 6165129, // Maryland + 'ChIJ_b9z6W1l44kRHA2DVTbQxkU': 6984723, // Massachussetts + 'ChIJEQTKxz2qTE0Rs8liellI3Zc': 10050811, // Michigan + 'ChIJmwt4YJpbWE0RD6L-EJvJogI': 5707390, // Minnesota + 'ChIJGdRK5OQyKIYR2qbc6X8XDWI': 2949965, // Mississippi + 'ChIJfeMiSNXmwIcRcr1mBFnEW7U': 6168187, // Misssouri + 'ChIJ04p7LZwrQVMRGGwqz1jWcfU': 1104271, // Montana + 'ChIJ7fwMtciNk4cRxArzDwyQJ6E': 1963692, // Nebraska + 'ChIJcbTe-KEKmYARs5X8qooDR88': 3143991, // Nevada + 'ChIJ66bAnUtEs0wR64CmJa8CyNc': 1388992, // New Hampshire + 'ChIJn0AAnpX7wIkRjW0_-Ad70iw': 9267130, // New Jersey + 'ChIJqVKY50NQGIcRup41Yxpuv0Y': 2115877, // New Mexico + 'ChIJqaUj8fBLzEwRZ5UY3sHGz90': 19835913, // New York + 'ChIJgRo4_MQfVIgRGa4i6fUwP60': 10551162, // North Carolina + 'ChIJY-nYVxKD11IRyc9egzmahA0': 774948, // North Dakota + 'ChIJwY5NtXrpNogRFtmfnDlkzeU': 11780017, // Ohio + 'ChIJnU-ssRE5rIcRSOoKQDPPHF0': 3986639, // Oklahoma + 'ChIJVWqfm3xuk1QRdrgLettlTH0': 4246155, // Oregon + 'ChIJieUyHiaALYgRPbQiUEchRsI': 12964056, // Pennsylvania + 'ChIJD9cOYhQ15IkR5wbB57wYTh4': 1095610, // Rhode Island + 'ChIJ49ExeWml-IgRnhcF9TKh_7k': 5190705, // South Carolina + 'ChIJpTjphS1DfYcRt6SGMSnW8Ac': 895376, // South Dakota + 'ChIJA8-XniNLYYgRVpGBpcEgPgM': 6975218, // Tennessee + 'ChIJSTKCCzZwQIYRPN4IGI8c6xY': 29527941, // Texas + 'ChIJzfkTj8drTIcRP0bXbKVK370': 3337975, // Utah + 'ChIJ_87aSGzctEwRtGtUNnSJTSY': 645570, // Vermont + 'ChIJzbK8vXDWTIgRlaZGt0lBTsA': 8642274, // Virginia + 'ChIJ-bDD5__lhVQRuvNfbGh4QpQ': 7738692, // Washington + 'ChIJRQnL1KVUSogRQzrN3mjHALs': 1782959, // West Virginia + 'ChIJr-OEkw_0qFIR1kmG-LjV1fI': 5895908, // Wisconsin + 'ChIJaS7hSDTiXocRLzh90nkisCY': 578803, // Wyoming + }; +} + +initMap(); +// [END maps_boundaries_choropleth] diff --git a/dist/samples/boundaries-choropleth/docs/style.css b/dist/samples/boundaries-choropleth/docs/style.css new file mode 100644 index 00000000..bae1997d --- /dev/null +++ b/dist/samples/boundaries-choropleth/docs/style.css @@ -0,0 +1,25 @@ +/** + * @license + * Copyright 2025 Google LLC. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 + */ +/* [START maps_boundaries_choropleth] */ +/* + * Always set the map height explicitly to define the size of the div element + * that contains the map. + */ +gmp-map { + height: 100%; +} + +/* + * Optional: Makes the sample page fill the window. + */ +html, +body { + height: 100%; + margin: 0; + padding: 0; +} + +/* [END maps_boundaries_choropleth] */ \ No newline at end of file diff --git a/dist/samples/boundaries-choropleth/jsfiddle/demo.css b/dist/samples/boundaries-choropleth/jsfiddle/demo.css new file mode 100644 index 00000000..29cd2be7 --- /dev/null +++ b/dist/samples/boundaries-choropleth/jsfiddle/demo.css @@ -0,0 +1,24 @@ +/** + * @license + * Copyright 2025 Google LLC. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 + */ + +/* + * Always set the map height explicitly to define the size of the div element + * that contains the map. + */ +gmp-map { + height: 100%; +} + +/* + * Optional: Makes the sample page fill the window. + */ +html, +body { + height: 100%; + margin: 0; + padding: 0; +} + diff --git a/dist/samples/boundaries-choropleth/jsfiddle/demo.details b/dist/samples/boundaries-choropleth/jsfiddle/demo.details new file mode 100644 index 00000000..78d4b536 --- /dev/null +++ b/dist/samples/boundaries-choropleth/jsfiddle/demo.details @@ -0,0 +1,7 @@ +name: boundaries-choropleth +authors: + - Geo Developer IX Documentation Team +tags: + - google maps +load_type: h +description: Sample code supporting Google Maps Platform JavaScript API documentation. diff --git a/dist/samples/boundaries-choropleth/jsfiddle/demo.html b/dist/samples/boundaries-choropleth/jsfiddle/demo.html new file mode 100644 index 00000000..20462283 --- /dev/null +++ b/dist/samples/boundaries-choropleth/jsfiddle/demo.html @@ -0,0 +1,22 @@ + + + + + + Choropleth Map + + + + + + + + + + + diff --git a/dist/samples/boundaries-choropleth/jsfiddle/demo.js b/dist/samples/boundaries-choropleth/jsfiddle/demo.js new file mode 100644 index 00000000..fa0efdbe --- /dev/null +++ b/dist/samples/boundaries-choropleth/jsfiddle/demo.js @@ -0,0 +1,99 @@ +"use strict"; +/** + * @license + * Copyright 2025 Google LLC. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 + */ + +async function initMap() { + // Request needed libraries. + (await google.maps.importLibrary('maps')); + // Get the gmp-map element. + const mapElement = document.querySelector('gmp-map'); + // Get the inner map. + const innerMap = mapElement.innerMap; + const featureLayer = innerMap.getFeatureLayer(google.maps.FeatureType.ADMINISTRATIVE_AREA_LEVEL_1); + + featureLayer.style = (featureStyleFunctionOptions) => { + const placeFeature = featureStyleFunctionOptions.feature; + const population = states[placeFeature.placeId]; + let fillColor; + // Specify colors using any of the following: + // * Named ('green') + // * Hexadecimal ('#FF0000') + // * RGB ('rgb(0, 0, 255)') + // * HSL ('hsl(60, 100%, 50%)') + if (population < 2000000) { + fillColor = 'green'; + } + else if (population < 5000000) { + fillColor = 'red'; + } + else if (population < 10000000) { + fillColor = 'blue'; + } + else if (population < 40000000) { + fillColor = 'yellow'; + } + return { + fillColor, + fillOpacity: 0.5, + }; + }; + + // Population data by state. + const states = { + 'ChIJdf5LHzR_hogR6czIUzU0VV4': 5039877, // Alabama + 'ChIJG8CuwJzfAFQRNduKqSde27w': 732673, // Alaska + 'ChIJaxhMy-sIK4cRcc3Bf7EnOUI': 7276316, // Arizona + 'ChIJYSc_dD-e0ocR0NLf_z5pBaQ': 3025891, // Arkansas + 'ChIJPV4oX_65j4ARVW8IJ6IJUYs': 39237836, // California + 'ChIJt1YYm3QUQIcR_6eQSTGDVMc': 5812069, // Colorado + 'ChIJpVER8hFT5okR5XBhBVttmq4': 3605597, // Connecticut + 'ChIJO9YMTXYFx4kReOgEjBItHZQ': 1003384, // Delaware + 'ChIJvypWkWV2wYgR0E7HW9MTLvc': 21781128, // Florida + 'ChIJV4FfHcU28YgR5xBP7BC8hGY': 10799566, // Georgia + 'ChIJBeB5Twbb_3sRKIbMdNKCd0s': 1441553, // Hawaii + 'ChIJ6Znkhaj_WFMRWIf3FQUwa9A': 1900923, // Idaho + 'ChIJGSZubzgtC4gRVlkRZFCCFX8': 12671469, // Illinois + 'ChIJHRv42bxQa4gRcuwyy84vEH4': 6805985, // Indiana + 'ChIJGWD48W9e7ocR2VnHV0pj78Y': 3193079, // Iowa + 'ChIJawF8cXEXo4cRXwk-S6m0wmg': 2934582, // Kansas + 'ChIJyVMZi0xzQogR_N_MxU5vH3c': 4509394, // Kentucky + 'ChIJZYIRslSkIIYRA0flgTL3Vck': 4624047, // Louisiana + 'ChIJ1YpTHd4dsEwR0KggZ2_MedY': 1372247, // Maine + 'ChIJ35Dx6etNtokRsfZVdmU3r_I': 6165129, // Maryland + 'ChIJ_b9z6W1l44kRHA2DVTbQxkU': 6984723, // Massachussetts + 'ChIJEQTKxz2qTE0Rs8liellI3Zc': 10050811, // Michigan + 'ChIJmwt4YJpbWE0RD6L-EJvJogI': 5707390, // Minnesota + 'ChIJGdRK5OQyKIYR2qbc6X8XDWI': 2949965, // Mississippi + 'ChIJfeMiSNXmwIcRcr1mBFnEW7U': 6168187, // Misssouri + 'ChIJ04p7LZwrQVMRGGwqz1jWcfU': 1104271, // Montana + 'ChIJ7fwMtciNk4cRxArzDwyQJ6E': 1963692, // Nebraska + 'ChIJcbTe-KEKmYARs5X8qooDR88': 3143991, // Nevada + 'ChIJ66bAnUtEs0wR64CmJa8CyNc': 1388992, // New Hampshire + 'ChIJn0AAnpX7wIkRjW0_-Ad70iw': 9267130, // New Jersey + 'ChIJqVKY50NQGIcRup41Yxpuv0Y': 2115877, // New Mexico + 'ChIJqaUj8fBLzEwRZ5UY3sHGz90': 19835913, // New York + 'ChIJgRo4_MQfVIgRGa4i6fUwP60': 10551162, // North Carolina + 'ChIJY-nYVxKD11IRyc9egzmahA0': 774948, // North Dakota + 'ChIJwY5NtXrpNogRFtmfnDlkzeU': 11780017, // Ohio + 'ChIJnU-ssRE5rIcRSOoKQDPPHF0': 3986639, // Oklahoma + 'ChIJVWqfm3xuk1QRdrgLettlTH0': 4246155, // Oregon + 'ChIJieUyHiaALYgRPbQiUEchRsI': 12964056, // Pennsylvania + 'ChIJD9cOYhQ15IkR5wbB57wYTh4': 1095610, // Rhode Island + 'ChIJ49ExeWml-IgRnhcF9TKh_7k': 5190705, // South Carolina + 'ChIJpTjphS1DfYcRt6SGMSnW8Ac': 895376, // South Dakota + 'ChIJA8-XniNLYYgRVpGBpcEgPgM': 6975218, // Tennessee + 'ChIJSTKCCzZwQIYRPN4IGI8c6xY': 29527941, // Texas + 'ChIJzfkTj8drTIcRP0bXbKVK370': 3337975, // Utah + 'ChIJ_87aSGzctEwRtGtUNnSJTSY': 645570, // Vermont + 'ChIJzbK8vXDWTIgRlaZGt0lBTsA': 8642274, // Virginia + 'ChIJ-bDD5__lhVQRuvNfbGh4QpQ': 7738692, // Washington + 'ChIJRQnL1KVUSogRQzrN3mjHALs': 1782959, // West Virginia + 'ChIJr-OEkw_0qFIR1kmG-LjV1fI': 5895908, // Wisconsin + 'ChIJaS7hSDTiXocRLzh90nkisCY': 578803, // Wyoming + }; +} +initMap(); + diff --git a/index.html b/index.html index 3e7d260c..fb0b71f2 100644 --- a/index.html +++ b/index.html @@ -46,6 +46,7 @@

    Maps JSAPI Samples

  • advanced-markers-html-simple
  • advanced-markers-simple
  • advanced-markers-zoom
  • +
  • boundaries-choropleth
  • boundaries-simple
  • deckgl-heatmap
  • deckgl-kml
  • diff --git a/package-lock.json b/package-lock.json index a5b6b0a4..1fbcc321 100644 --- a/package-lock.json +++ b/package-lock.json @@ -23,7 +23,7 @@ "@types/node": "^24.9.1", "eslint": "^9.38.0", "globals": "^16.5.0", - "rimraf": "^6.1,0", + "rimraf": "^6.1.0", "typescript": "^5.9.3", "typescript-eslint": "^8.46.2", "vite": "^7.1.11" @@ -1435,6 +1435,10 @@ "resolved": "samples/advanced-markers-zoom", "link": true }, + "node_modules/@js-api-samples/boundaries-choropleth": { + "resolved": "samples/boundaries-choropleth", + "link": true + }, "node_modules/@js-api-samples/boundaries-simple": { "resolved": "samples/boundaries-simple", "link": true @@ -8809,6 +8813,10 @@ "name": "@js-api-samples/advanced-markers-zoom", "version": "1.0.0" }, + "samples/boundaries-choropleth": { + "name": "@js-api-samples/boundaries-choropleth", + "version": "1.0.0" + }, "samples/boundaries-simple": { "name": "@js-api-samples/boundaries-simple", "version": "1.0.0" @@ -8875,11 +8883,11 @@ "version": "1.0.0", "dependencies": { "@googlemaps/js-api-loader": "^2.0.2", - "terra-draw": "*", - "terra-draw-google-maps-adapter": "*" + "terra-draw": "latest", + "terra-draw-google-maps-adapter": "latest" }, "devDependencies": { - "@types/google.maps": "*", + "@types/google.maps": "latest", "typescript": "^5.9.3", "vite": "^7.1.11" } @@ -9019,7 +9027,7 @@ "name": "@js-api-samples/react-ui-kit-place-details-latlng-compact", "version": "1.0.0", "dependencies": { - "@vis.gl/react-google-maps": "*", + "@vis.gl/react-google-maps": "latest", "react": "^19.2.0", "react-dom": "^19.2.0" },