Skip to content

Commit 4898283

Browse files
authored
feat: Migrates the advanced marker zoom demo; tweaks generation script. (#688)
1 parent eecfc81 commit 4898283

File tree

7 files changed

+180
-3
lines changed

7 files changed

+180
-3
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/advanced-markers-zoom`
15+
`npm start`
16+
17+
### Build an individual example
18+
19+
`cd samples/advanced-markers-zoom`
20+
`npm run build`
21+
22+
From 'samples':
23+
24+
`npm run build --workspace=advanced-markers-zoom/`
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/advanced-markers-zoom`
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: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<!doctype html>
2+
<!--
3+
@license
4+
Copyright 2019 Google LLC. All Rights Reserved.
5+
SPDX-License-Identifier: Apache-2.0
6+
-->
7+
<!-- [START maps_advanced_markers_zoom] -->
8+
<html>
9+
<head>
10+
<title>Advanced Marker Zoom Visibility</title>
11+
12+
<link rel="stylesheet" type="text/css" href="./style.css" />
13+
<script type="module" src="./index.js"></script>
14+
</head>
15+
<body>
16+
<div id="map"></div>
17+
18+
<!-- prettier-ignore -->
19+
<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))})
20+
({key: "AIzaSyA6myHzS10YXdcazAFalmXvDkrYCp5cLc8", v: "weekly"});</script>
21+
</body>
22+
</html>
23+
<!-- [END maps_advanced_markers_zoom] -->
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
2+
/**
3+
* @license
4+
* Copyright 2019 Google LLC. All Rights Reserved.
5+
* SPDX-License-Identifier: Apache-2.0
6+
*/
7+
8+
// [START maps_advanced_markers_zoom]
9+
async function initMap() {
10+
// Request needed libraries.
11+
const { Map } = await google.maps.importLibrary("maps") as google.maps.MapsLibrary;
12+
const { AdvancedMarkerElement } = await google.maps.importLibrary("marker") as google.maps.MarkerLibrary;
13+
14+
const map = new Map(document.getElementById('map') as HTMLElement, {
15+
center: {lat: 37.424563902650114, lng: -122.09512859577026},
16+
zoom: 17,
17+
mapId: '4504f8b37365c3d0',
18+
});
19+
20+
const marker01 = new AdvancedMarkerElement({
21+
map,
22+
position: { lat: 37.4239163, lng: -122.094 },
23+
title: 'This marker is visible at zoom level 15 and higher.'
24+
});
25+
26+
const marker02 = new AdvancedMarkerElement({
27+
map,
28+
position: { lat: 37.4245, lng: -122.096 },
29+
title: 'This marker is visible at zoom level 16 and higher.'
30+
});
31+
32+
const marker03 = new AdvancedMarkerElement({
33+
map,
34+
position: { lat: 37.4249, lng: -122.095 },
35+
title: 'This marker is visible at zoom level 17 and higher.'
36+
});
37+
38+
const marker04 = new AdvancedMarkerElement({
39+
map,
40+
position: { lat: 37.425, lng: -122.0955 },
41+
title: 'This marker is visible at zoom level 18 and higher.'
42+
});
43+
// [START maps_advanced_markers_zoom_listener]
44+
map.addListener('zoom_changed', () => {
45+
const zoom = map.getZoom();
46+
if (zoom) {
47+
// Only show each marker above a certain zoom level.
48+
marker01.map = zoom > 14 ? map : null;
49+
marker02.map = zoom > 15 ? map : null;
50+
marker03.map = zoom > 16 ? map : null;
51+
marker04.map = zoom > 17 ? map : null;
52+
}
53+
});
54+
// [END maps_advanced_markers_zoom_listener]
55+
}
56+
57+
initMap();
58+
// [END maps_advanced_markers_zoom]
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"name": "@js-api-samples/advanced-markers-zoom",
3+
"version": "1.0.0",
4+
"scripts": {
5+
"build": "tsc && bash ../jsfiddle.sh advanced-markers-zoom && bash ../app.sh advanced-markers-zoom && bash ../docs.sh advanced-markers-zoom && npm run build:vite --workspace=. && bash ../dist.sh advanced-markers-zoom",
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 2019 Google LLC. All Rights Reserved.
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
/* [START maps_advanced_markers_zoom] */
7+
/*
8+
* Always set the map height explicitly to define the size of the div element
9+
* that contains the map.
10+
*/
11+
#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_advanced_markers_zoom] */
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+
}

samples/new1.sh

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@
1212
# 3. ./new1.sh
1313

1414
# AUTHOR: Update these values!
15-
NAME="advanced-markers-zoom" # The name of the folder to create (for example "map-simple").
16-
REGION_TAG="maps_advanced_markers_zoom" # The region tag to use (for example "maps_map_simple").
17-
TITLE="Demonstrates a Maps feature." # The title of the example.
15+
NAME="sample-name" # The name of the folder to create (for example "map-simple").
16+
REGION_TAG="maps_sample_name" # The region tag to use (for example "maps_map_simple").
17+
TITLE="Descriptive text for sample." # The title of the example.
1818
API_LOADER="api_loader_dynamic" # The type of loader to use (api_loader_dynamic or api_loader_default).
1919

2020
# Path to the source folder for the repo archive; substitute with your own path.

0 commit comments

Comments
 (0)