Skip to content

Commit f333300

Browse files
authored
feat: Migrates four advanced marker samples. (#618)
1 parent ecd43f4 commit f333300

30 files changed

+952
-0
lines changed
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
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+
First `cd` to the folder for the sample to run, then:
15+
16+
`npm start`
17+
18+
### Build an individual example
19+
20+
From `samples/`:
21+
22+
`npm run build --workspace=sample-name/`
23+
24+
### Build all of the examples.
25+
26+
From `samples/`:
27+
28+
`npm run build-all`
29+
30+
## Feedback
31+
32+
For feedback related to this sample, please open a new issue on
33+
[GitHub](https://github.com/googlemaps-samples/js-api-samples/issues).
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
2+
{% spaceless %}{% include "maps/documentation/javascript/examples/full/_apikey.html" %}{% endspaceless %}<!DOCTYPE html>
3+
<html>
4+
<head>
5+
<meta name="viewport" content="initial-scale=1.0, user-scalable=no">
6+
<meta charset="utf-8">
7+
<title>Advanced markers basic customization.</title>
8+
<style>
9+
{% includecode content_path="maps/documentation/javascript/examples/samples/advanced-markers-basic-style/style.css" region_tag="maps_advanced_markers_basic_style" html_escape="False" %}
10+
</style>
11+
</head>
12+
<body>
13+
{% includecode content_path="maps/documentation/javascript/examples/samples/advanced-markers-basic-style/index.html" region_tag="maps_advanced_markers_basic_style_body" html_escape="False" %}
14+
{{ api_loader_dynamic }}
15+
<script>
16+
{% includecode content_path="maps/documentation/javascript/examples/samples/advanced-markers-basic-style/index.js" region_tag="maps_advanced_markers_basic_style" html_escape="False" %}
17+
</script>
18+
</body>
19+
</html>
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_basic_style] -->
8+
<html>
9+
<head>
10+
<title>Advanced Marker Basic Customization</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_basic_style] -->
Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
/**
2+
* @license
3+
* Copyright 2019 Google LLC. All Rights Reserved.
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
// [START maps_advanced_markers_basic_style]
8+
const parser = new DOMParser();
9+
10+
async function initMap() {
11+
// Request needed libraries.
12+
const { Map } = await google.maps.importLibrary("maps") as google.maps.MapsLibrary;
13+
const { AdvancedMarkerElement, PinElement } = await google.maps.importLibrary("marker") as google.maps.MarkerLibrary;
14+
15+
const map = new Map(document.getElementById('map') as HTMLElement, {
16+
center: { lat: 37.419, lng: -122.02 },
17+
zoom: 14,
18+
mapId: '4504f8b37365c3d0',
19+
});
20+
21+
// Each PinElement is paired with a MarkerView to demonstrate setting each parameter.
22+
23+
// [START maps_advanced_markers_basic_style_title]
24+
// Default marker with title text (no PinElement).
25+
const markerViewWithText = new AdvancedMarkerElement({
26+
map,
27+
position: { lat: 37.419, lng: -122.03 },
28+
title: 'Title text for the marker at lat: 37.419, lng: -122.03',
29+
});
30+
// [END maps_advanced_markers_basic_style_title]
31+
32+
// [START maps_advanced_markers_basic_style_scale]
33+
// Adjust the scale.
34+
const pinScaled = new PinElement({
35+
scale: 1.5,
36+
});
37+
const markerViewScaled = new AdvancedMarkerElement({
38+
map,
39+
position: { lat: 37.419, lng: -122.02 },
40+
content: pinScaled.element,
41+
});
42+
// [END maps_advanced_markers_basic_style_scale]
43+
44+
// [START maps_advanced_markers_basic_style_background]
45+
// Change the background color.
46+
const pinBackground = new PinElement({
47+
background: '#FBBC04',
48+
});
49+
const markerViewBackground = new AdvancedMarkerElement({
50+
map,
51+
position: { lat: 37.419, lng: -122.01 },
52+
content: pinBackground.element,
53+
});
54+
// [END maps_advanced_markers_basic_style_background]
55+
56+
// [START maps_advanced_markers_basic_style_border]
57+
// Change the border color.
58+
const pinBorder = new PinElement({
59+
borderColor: '#137333',
60+
});
61+
const markerViewBorder = new AdvancedMarkerElement({
62+
map,
63+
position: { lat: 37.415, lng: -122.035 },
64+
content: pinBorder.element,
65+
});
66+
// [END maps_advanced_markers_basic_style_border]
67+
68+
// [START maps_advanced_markers_basic_style_glyph]
69+
// Change the glyph color.
70+
const pinGlyph = new PinElement({
71+
glyphColor: 'white',
72+
});
73+
const markerViewGlyph = new AdvancedMarkerElement({
74+
map,
75+
position: { lat: 37.415, lng: -122.025 },
76+
content: pinGlyph.element,
77+
});
78+
// [END maps_advanced_markers_basic_style_glyph]
79+
80+
// [START maps_advanced_markers_basic_style_text_glyph]
81+
const pinTextGlyph = new PinElement({
82+
glyph: 'T',
83+
glyphColor: 'white',
84+
});
85+
const markerViewGlyphText = new AdvancedMarkerElement({
86+
map,
87+
position: { lat: 37.415, lng: -122.015 },
88+
content: pinTextGlyph.element,
89+
});
90+
// [END maps_advanced_markers_basic_style_text_glyph]
91+
92+
// [START maps_advanced_markers_basic_style_hide_glyph]
93+
// Hide the glyph.
94+
const pinNoGlyph = new PinElement({
95+
glyph: '',
96+
});
97+
const markerViewNoGlyph = new AdvancedMarkerElement({
98+
map,
99+
position: { lat: 37.415, lng: -122.005 },
100+
content: pinNoGlyph.element,
101+
});
102+
// [END maps_advanced_markers_basic_style_hide_glyph]
103+
104+
}
105+
106+
initMap();
107+
// [END maps_advanced_markers_basic_style]
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-basic-style",
3+
"version": "1.0.0",
4+
"scripts": {
5+
"build": "tsc && bash ../jsfiddle.sh advanced-markers-basic-style && bash ../app.sh advanced-markers-basic-style && bash ../docs.sh advanced-markers-basic-style && npm run build:vite --workspace=. && bash ../dist.sh advanced-markers-basic-style",
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_basic_style] */
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_basic_style] */
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+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
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+
First `cd` to the folder for the sample to run, then:
15+
16+
`npm start`
17+
18+
### Build an individual example
19+
20+
From `samples/`:
21+
22+
`npm run build --workspace=sample-name/`
23+
24+
### Build all of the examples.
25+
26+
From `samples/`:
27+
28+
`npm run build-all`
29+
30+
## Feedback
31+
32+
For feedback related to this sample, please open a new issue on
33+
[GitHub](https://github.com/googlemaps-samples/js-api-samples/issues).
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
2+
{% spaceless %}{% include "maps/documentation/javascript/examples/full/_apikey.html" %}{% endspaceless %}<!DOCTYPE html>
3+
<html>
4+
<head>
5+
<meta name="viewport" content="initial-scale=1.0, user-scalable=no">
6+
<meta charset="utf-8">
7+
<title>Advanced markers collision management.</title>
8+
<style>
9+
{% includecode content_path="maps/documentation/javascript/examples/samples/advanced-markers-collision/style.css" region_tag="maps_advanced_markers_collision" html_escape="False" %}
10+
</style>
11+
</head>
12+
<body>
13+
{% includecode content_path="maps/documentation/javascript/examples/samples/advanced-markers-collision/index.html" region_tag="maps_advanced_markers_collision_body" html_escape="False" %}
14+
{{ api_loader_dynamic }}
15+
<script>
16+
{% includecode content_path="maps/documentation/javascript/examples/samples/advanced-markers-collision/index.js" region_tag="maps_advanced_markers_collision" html_escape="False" %}
17+
</script>
18+
</body>
19+
</html>
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
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_collision] -->
8+
<html>
9+
<head>
10+
<title>Advanced Marker Collision Management</title>
11+
12+
<link
13+
href="https://unpkg.com/[email protected]/dist/material-components-web.css"
14+
rel="stylesheet"
15+
/>
16+
<script src="https://unpkg.com/[email protected]/dist/material-components-web.min.js"></script>
17+
<link
18+
rel="stylesheet"
19+
href="https://fonts.googleapis.com/icon?family=Material+Icons"
20+
/>
21+
22+
<link rel="stylesheet" type="text/css" href="./style.css" />
23+
<script type="module" src="./index.js"></script>
24+
</head>
25+
<body>
26+
<div id="container">
27+
<div id="map"></div>
28+
<div id="sidebar">
29+
<div class="mdc-select mdc-select--outlined">
30+
<div
31+
class="mdc-select__anchor"
32+
aria-labelledby="outlined-select-label"
33+
>
34+
<input
35+
type="text"
36+
disabled
37+
readonly
38+
id="demo-selected-text"
39+
class="mdc-select__selected-text"
40+
/>
41+
<i class="mdc-select__dropdown-icon"></i>
42+
<span class="mdc-notched-outline">
43+
<span class="mdc-notched-outline__leading"></span>
44+
<span class="mdc-notched-outline__notch">
45+
<span
46+
id="outlined-select-label"
47+
class="mdc-floating-label mdc-theme--primary"
48+
>Pick a Collision Behavior</span
49+
>
50+
</span>
51+
<span class="mdc-notched-outline__trailing"></span>
52+
</span>
53+
</div>
54+
<div class="mdc-select__menu mdc-menu mdc-menu-surface">
55+
<ul class="mdc-list">
56+
<li class="mdc-list-item" data-value="REQUIRED">Required</li>
57+
<li
58+
class="mdc-list-item"
59+
data-value="REQUIRED_AND_HIDES_OPTIONAL"
60+
>
61+
Required and hides optional
62+
</li>
63+
<li
64+
class="mdc-list-item"
65+
data-value="OPTIONAL_AND_HIDES_LOWER_PRIORITY"
66+
>
67+
Optional and hides lower priority
68+
</li>
69+
</ul>
70+
</div>
71+
</div>
72+
</div>
73+
</div>
74+
75+
<!-- prettier-ignore -->
76+
<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))})
77+
({key: "AIzaSyA6myHzS10YXdcazAFalmXvDkrYCp5cLc8", v: "weekly"});</script>
78+
</body>
79+
</html>
80+
<!-- [END maps_advanced_markers_collision] -->

0 commit comments

Comments
 (0)