Skip to content

Commit 22368ea

Browse files
authored
fix: Migrates the layer data sample; adds hardcoded data. (#781)
* fix: Migrates the layer data sample; adds hardcoded data. Change-Id: I65d6a637af0e24fdd68aa0895aafc82ebb08c988 * Update GeoJSON URL to use local file * Refactor map initialization in index.ts * Refactor string quotes and formatting in initMap
1 parent 7e829ba commit 22368ea

File tree

7 files changed

+281
-0
lines changed

7 files changed

+281
-0
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/layer-data-simple`
15+
`npm start`
16+
17+
### Build an individual example
18+
19+
`cd samples/layer-data-simple`
20+
`npm run build`
21+
22+
From 'samples':
23+
24+
`npm run build --workspace=layer-data-simple/`
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/layer-data-simple`
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: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
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_layer_data_simple] -->
8+
<html>
9+
<head>
10+
<title>Data Layer: Simple</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+
<!-- Add a comment. -->
17+
<gmp-map center="-28,137" zoom="4"></gmp-map>
18+
19+
<!-- prettier-ignore -->
20+
<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))})
21+
({key: "AIzaSyA6myHzS10YXdcazAFalmXvDkrYCp5cLc8", v: "weekly"});</script>
22+
</body>
23+
</html>
24+
<!-- [END maps_layer_data_simple] -->

samples/layer-data-simple/index.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/**
2+
* @license
3+
* Copyright 2019 Google LLC. All Rights Reserved.
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
// [START maps_layer_data_simple]
8+
async function initMap() {
9+
(await google.maps.importLibrary("maps")) as google.maps.MapsLibrary;
10+
11+
const mapElement = document.querySelector(
12+
"gmp-map"
13+
) as google.maps.MapElement;
14+
15+
let innerMap = mapElement.innerMap;
16+
17+
google.maps.event.addListenerOnce(innerMap, "idle", () => {
18+
innerMap.data.loadGeoJson("google.json");
19+
});
20+
}
21+
22+
initMap();
23+
// [END maps_layer_data_simple]
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"name": "@js-api-samples/layer-data-simple",
3+
"version": "1.0.0",
4+
"scripts": {
5+
"build": "tsc && bash ../jsfiddle.sh layer-data-simple && bash ../app.sh layer-data-simple && bash ../docs.sh layer-data-simple && npm run build:vite --workspace=. && bash ../dist.sh layer-data-simple",
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+
}
Lines changed: 146 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,146 @@
1+
{
2+
"type": "FeatureCollection",
3+
"features": [
4+
{
5+
"type": "Feature",
6+
"properties": {
7+
"letter": "G",
8+
"color": "blue",
9+
"rank": "7",
10+
"ascii": "71"
11+
},
12+
"geometry": {
13+
"type": "Polygon",
14+
"coordinates": [
15+
[
16+
[123.61, -22.14], [122.38, -21.73], [121.06, -21.69], [119.66, -22.22], [119.00, -23.40],
17+
[118.65, -24.76], [118.43, -26.07], [118.78, -27.56], [119.22, -28.57], [120.23, -29.49],
18+
[121.77, -29.87], [123.57, -29.64], [124.45, -29.03], [124.71, -27.95], [124.80, -26.70],
19+
[124.80, -25.60], [123.61, -25.64], [122.56, -25.64], [121.72, -25.72], [121.81, -26.62],
20+
[121.86, -26.98], [122.60, -26.90], [123.57, -27.05], [123.57, -27.68], [123.35, -28.18],
21+
[122.51, -28.38], [121.77, -28.26], [121.02, -27.91], [120.49, -27.21], [120.14, -26.50],
22+
[120.10, -25.64], [120.27, -24.52], [120.67, -23.68], [121.72, -23.32], [122.43, -23.48],
23+
[123.04, -24.04], [124.54, -24.28], [124.58, -23.20], [123.61, -22.14]
24+
]
25+
]
26+
}
27+
},
28+
{
29+
"type": "Feature",
30+
"properties": {
31+
"letter": "o",
32+
"color": "red",
33+
"rank": "15",
34+
"ascii": "111"
35+
},
36+
"geometry": {
37+
"type": "Polygon",
38+
"coordinates": [
39+
[
40+
[128.84, -25.76], [128.18, -25.60], [127.96, -25.52], [127.88, -25.52], [127.70, -25.60],
41+
[127.26, -25.79], [126.60, -26.11], [126.16, -26.78], [126.12, -27.68], [126.21, -28.42],
42+
[126.69, -29.49], [127.74, -29.80], [128.80, -29.72], [129.41, -29.03], [129.72, -27.95],
43+
[129.68, -27.21], [129.33, -26.23], [128.84, -25.76]
44+
],
45+
[
46+
[128.45, -27.44], [128.32, -26.94], [127.70, -26.82], [127.35, -27.05], [127.17, -27.80],
47+
[127.57, -28.22], [128.10, -28.42], [128.49, -27.80], [128.45, -27.44]
48+
]
49+
]
50+
}
51+
},
52+
{
53+
"type": "Feature",
54+
"properties": {
55+
"letter": "o",
56+
"color": "yellow",
57+
"rank": "15",
58+
"ascii": "111"
59+
},
60+
"geometry": {
61+
"type": "Polygon",
62+
"coordinates": [
63+
[
64+
[131.87, -25.76], [131.35, -26.07], [130.95, -26.78], [130.82, -27.64], [130.86, -28.53],
65+
[131.26, -29.22], [131.92, -29.76], [132.45, -29.87], [133.06, -29.76], [133.72, -29.34],
66+
[134.07, -28.80], [134.20, -27.91], [134.07, -27.21], [133.81, -26.31], [133.37, -25.83],
67+
[132.71, -25.64], [131.87, -25.76]
68+
],
69+
[
70+
[133.15, -27.17], [132.71, -26.86], [132.09, -26.90], [131.74, -27.56], [131.79, -28.26],
71+
[132.36, -28.45], [132.93, -28.34], [133.15, -27.76], [133.15, -27.17]
72+
]
73+
]
74+
}
75+
},
76+
{
77+
"type": "Feature",
78+
"properties": {
79+
"letter": "g",
80+
"color": "blue",
81+
"rank": "7",
82+
"ascii": "103"
83+
},
84+
"geometry": {
85+
"type": "Polygon",
86+
"coordinates": [
87+
[
88+
[138.12, -25.04], [136.84, -25.16], [135.96, -25.36], [135.26, -25.99], [135, -26.90],
89+
[135.04, -27.91], [135.26, -28.88], [136.05, -29.45], [137.02, -29.49], [137.81, -29.49],
90+
[137.94, -29.99], [137.90, -31.20], [137.85, -32.24], [136.88, -32.69], [136.45, -32.36],
91+
[136.27, -31.80], [134.95, -31.84], [135.17, -32.99], [135.52, -33.43], [136.14, -33.76],
92+
[137.06, -33.83], [138.12, -33.65], [138.86, -33.21], [139.30, -32.28], [139.30, -31.24],
93+
[139.30, -30.14], [139.21, -28.96], [139.17, -28.22], [139.08, -27.41], [139.08, -26.47],
94+
[138.99, -25.40], [138.73, -25.00 ], [138.12, -25.04]
95+
],
96+
[
97+
[137.50, -26.54], [136.97, -26.47], [136.49, -26.58], [136.31, -27.13], [136.31, -27.72],
98+
[136.58, -27.99], [137.50, -28.03], [137.68, -27.68], [137.59, -26.78], [137.50, -26.54]
99+
]
100+
]
101+
}
102+
},
103+
{
104+
"type": "Feature",
105+
"properties": {
106+
"letter": "l",
107+
"color": "green",
108+
"rank": "12",
109+
"ascii": "108"
110+
},
111+
"geometry": {
112+
"type": "Polygon",
113+
"coordinates": [
114+
[
115+
[140.14,-21.04], [140.31,-29.42], [141.67,-29.49], [141.59,-20.92], [140.14,-21.04]
116+
]
117+
]
118+
}
119+
},
120+
{
121+
"type": "Feature",
122+
"properties": {
123+
"letter": "e",
124+
"color": "red",
125+
"rank": "5",
126+
"ascii": "101"
127+
},
128+
"geometry": {
129+
"type": "Polygon",
130+
"coordinates": [
131+
[
132+
[144.14, -27.41], [145.67, -27.52], [146.86, -27.09], [146.82, -25.64], [146.25, -25.04],
133+
[145.45, -24.68], [144.66, -24.60], [144.09, -24.76], [143.43, -25.08], [142.99, -25.40],
134+
[142.64, -26.03], [142.64, -27.05], [142.64, -28.26], [143.30, -29.11], [144.18, -29.57],
135+
[145.41, -29.64], [146.46, -29.19], [146.64, -28.72], [146.82, -28.14], [144.84, -28.42],
136+
[144.31, -28.26], [144.14, -27.41]
137+
],
138+
[
139+
[144.18, -26.39], [144.53, -26.58], [145.19, -26.62], [145.72, -26.35], [145.81, -25.91],
140+
[145.41, -25.68], [144.97, -25.68], [144.49, -25.64], [144, -25.99], [144.18, -26.39]
141+
]
142+
]
143+
}
144+
}
145+
]
146+
}
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_layer_data_simple] */
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_layer_data_simple] */
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"compilerOptions": {
3+
"module": "esnext",
4+
"target": "esnext",
5+
"strict": true,
6+
"noImplicitAny": false,
7+
"lib": ["es2015", "esnext", "es6", "dom", "dom.iterable"],
8+
"moduleResolution": "Node",
9+
"jsx": "preserve"
10+
}
11+
}

0 commit comments

Comments
 (0)