Skip to content
Merged
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
1 change: 1 addition & 0 deletions dist/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ <h1>Maps JSAPI Samples</h1>
<li><a href='/samples/advanced-markers-zoom/dist'>advanced-markers-zoom</a></li>
<li><a href='/samples/boundaries-choropleth/dist'>boundaries-choropleth</a></li>
<li><a href='/samples/boundaries-simple/dist'>boundaries-simple</a></li>
<li><a href='/samples/boundaries-text-search/dist'>boundaries-text-search</a></li>
<li><a href='/samples/deckgl-heatmap/dist'>deckgl-heatmap</a></li>
<li><a href='/samples/deckgl-kml/dist'>deckgl-kml</a></li>
<li><a href='/samples/deckgl-kml-updated/dist'>deckgl-kml-updated</a></li>
Expand Down
13 changes: 13 additions & 0 deletions dist/samples/boundaries-text-search/app/.eslintsrc.json
Original file line number Diff line number Diff line change
@@ -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
}
}
40 changes: 40 additions & 0 deletions dist/samples/boundaries-text-search/app/README.md
Original file line number Diff line number Diff line change
@@ -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-text-search`
`npm start`

### Build an individual example

`cd samples/boundaries-text-search`
`npm run build`

From 'samples':

`npm run build --workspace=boundaries-text-search/`

### Build all of the examples.

From 'samples':

`npm run build-all`

### Run lint to check for problems

`cd samples/boundaries-text-search`
`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).
22 changes: 22 additions & 0 deletions dist/samples/boundaries-text-search/app/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<!doctype html>
<!--
@license
Copyright 2025 Google LLC. All Rights Reserved.
SPDX-License-Identifier: Apache-2.0
-->
<!-- [START maps_boundaries_text_search] -->
<html>
<head>
<title>Boundaries Text Search</title>

<link rel="stylesheet" type="text/css" href="./style.css" />
<script type="module" src="./index.js"></script>
<!-- prettier-ignore -->
<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))})
({key: "AIzaSyA6myHzS10YXdcazAFalmXvDkrYCp5cLc8", v: "beta"});</script>
</head>
<body>
<gmp-map center="41.059,-124.151" zoom="15" map-id="8b37d7206ccf0121d4414bb0"></gmp-map>
</body>
</html>
<!-- [END maps_boundaries_text_search] -->
73 changes: 73 additions & 0 deletions dist/samples/boundaries-text-search/app/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
/**
* @license
* Copyright 2025 Google LLC. All Rights Reserved.
* SPDX-License-Identifier: Apache-2.0
*/

// [START maps_boundaries_text_search]
let innerMap;
let featureLayer;
let center;

async function initMap() {
// Load the needed libraries.
await google.maps.importLibrary('maps') as google.maps.MapsLibrary;

center = { lat: 41.059, lng: -124.151 }; // Trinidad, CA

// Get the gmp-map element.
const mapElement = document.querySelector(
'gmp-map'
) as google.maps.MapElement;

// Get the inner map.
innerMap = mapElement.innerMap;

// Get the LOCALITY feature layer.
featureLayer = innerMap.getFeatureLayer(google.maps.FeatureType.LOCALITY);

findBoundary();
}
// [START maps_boundaries_text_search_find_region]
async function findBoundary() {
const request = {
textQuery: 'Trinidad, CA',
fields: ['id', 'location'],
includedType: 'locality',
locationBias: center,
};

const { Place } = (await google.maps.importLibrary(
'places'
)) as google.maps.PlacesLibrary;
const { places } = await Place.searchByText(request);

if (places.length) {
const place = places[0];
styleBoundary(place.id);
innerMap.setCenter(place.location);
} else {
console.log('No results');
}
}

function styleBoundary(placeid) {
// Define a style of transparent purple with opaque stroke.
const styleFill = {
strokeColor: '#810FCB',
strokeOpacity: 1.0,
strokeWeight: 3.0,
fillColor: '#810FCB',
fillOpacity: 0.5,
};

// Define the feature style function.
featureLayer.style = (params) => {
if (params.feature.placeId == placeid) {
return styleFill;
}
};
}
// [END maps_boundaries_text_search_find_region]
initMap();
// [END maps_boundaries_text_search]
14 changes: 14 additions & 0 deletions dist/samples/boundaries-text-search/app/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"name": "@js-api-samples/boundaries-text-search",
"version": "1.0.0",
"scripts": {
"build": "tsc && bash ../jsfiddle.sh boundaries-text-search && bash ../app.sh boundaries-text-search && bash ../docs.sh boundaries-text-search && npm run build:vite --workspace=. && bash ../dist.sh boundaries-text-search",
"test": "tsc && npm run build:vite --workspace=.",
"start": "tsc && vite build --base './' && vite",
"build:vite": "vite build --base './'",
"preview": "vite preview"
},
"dependencies": {

}
}
25 changes: 25 additions & 0 deletions dist/samples/boundaries-text-search/app/style.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/**
* @license
* Copyright 2025 Google LLC. All Rights Reserved.
* SPDX-License-Identifier: Apache-2.0
*/
/* [START maps_boundaries_text_search] */
/*
* 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_text_search] */
17 changes: 17 additions & 0 deletions dist/samples/boundaries-text-search/app/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"compilerOptions": {
"module": "esnext",
"target": "esnext",
"strict": true,
"noImplicitAny": false,
"lib": [
"es2015",
"esnext",
"es6",
"dom",
"dom.iterable"
],
"moduleResolution": "Node",
"jsx": "preserve"
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -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}
22 changes: 22 additions & 0 deletions dist/samples/boundaries-text-search/dist/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<!doctype html>
<!--
@license
Copyright 2025 Google LLC. All Rights Reserved.
SPDX-License-Identifier: Apache-2.0
-->
<!-- [START maps_boundaries_text_search] -->
<html>
<head>
<title>Boundaries Text Search</title>

<!-- prettier-ignore -->
<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))})
({key: "AIzaSyA6myHzS10YXdcazAFalmXvDkrYCp5cLc8", v: "beta"});</script>
<script type="module" crossorigin src="./assets/index-Bi-eZjfD.js"></script>
<link rel="stylesheet" crossorigin href="./assets/index-i_98oPIq.css">
</head>
<body>
<gmp-map center="41.059,-124.151" zoom="15" map-id="8b37d7206ccf0121d4414bb0"></gmp-map>
</body>
</html>
<!-- [END maps_boundaries_text_search] -->
22 changes: 22 additions & 0 deletions dist/samples/boundaries-text-search/docs/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<!doctype html>
<!--
@license
Copyright 2025 Google LLC. All Rights Reserved.
SPDX-License-Identifier: Apache-2.0
-->
<!-- [START maps_boundaries_text_search] -->
<html>
<head>
<title>Boundaries Text Search</title>

<link rel="stylesheet" type="text/css" href="./style.css" />
<script type="module" src="./index.js"></script>
<!-- prettier-ignore -->
<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))})
({key: "AIzaSyA6myHzS10YXdcazAFalmXvDkrYCp5cLc8", v: "beta"});</script>
</head>
<body>
<gmp-map center="41.059,-124.151" zoom="15" map-id="8b37d7206ccf0121d4414bb0"></gmp-map>
</body>
</html>
<!-- [END maps_boundaries_text_search] -->
60 changes: 60 additions & 0 deletions dist/samples/boundaries-text-search/docs/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
"use strict";
/**
* @license
* Copyright 2025 Google LLC. All Rights Reserved.
* SPDX-License-Identifier: Apache-2.0
*/
// [START maps_boundaries_text_search]
let innerMap;
let featureLayer;
let center;
async function initMap() {
// Load the needed libraries.
await google.maps.importLibrary('maps');
center = { lat: 41.059, lng: -124.151 }; // Trinidad, CA
// Get the gmp-map element.
const mapElement = document.querySelector('gmp-map');
// Get the inner map.
innerMap = mapElement.innerMap;
// Get the LOCALITY feature layer.
featureLayer = innerMap.getFeatureLayer(google.maps.FeatureType.LOCALITY);
findBoundary();
}
// [START maps_boundaries_text_search_find_region]
async function findBoundary() {
const request = {
textQuery: 'Trinidad, CA',
fields: ['id', 'location'],
includedType: 'locality',
locationBias: center,
};
const { Place } = (await google.maps.importLibrary('places'));
const { places } = await Place.searchByText(request);
if (places.length) {
const place = places[0];
styleBoundary(place.id);
innerMap.setCenter(place.location);
}
else {
console.log('No results');
}
}
function styleBoundary(placeid) {
// Define a style of transparent purple with opaque stroke.
const styleFill = {
strokeColor: '#810FCB',
strokeOpacity: 1.0,
strokeWeight: 3.0,
fillColor: '#810FCB',
fillOpacity: 0.5,
};
// Define the feature style function.
featureLayer.style = (params) => {
if (params.feature.placeId == placeid) {
return styleFill;
}
};
}
// [END maps_boundaries_text_search_find_region]
initMap();
// [END maps_boundaries_text_search]
Loading
Loading