diff --git a/.github/workflows/e2e.yml b/.github/workflows/e2e.yml index b84b08e205..653a59785b 100644 --- a/.github/workflows/e2e.yml +++ b/.github/workflows/e2e.yml @@ -66,7 +66,7 @@ jobs: env: CI: true - name: Push test report to artifacts - uses: actions/upload-artifact@v2 + uses: actions/upload-artifact@v4 if: failure() with: name: Test Results diff --git a/dist/index.html b/dist/index.html index cd99e5dd78..9bd9adf22f 100644 --- a/dist/index.html +++ b/dist/index.html @@ -4284,6 +4284,64 @@

overlay-symbol-dashed

+
+

place-autocomplete-data-session

+ +
+ +
+

place-autocomplete-data-simple

+ +
+

place-autocomplete-element

+
+

place-photos

+ +
+ +
+

place-reviews

+ +
+

place-search

+
+

rgm-autocomplete

+ +
+

rgm-basic-map

+
+

rgm-college-picker

+ +
+

split-map-panes

+
+

web-components-accessibility

+ +
+

web-components-events

+
+
+ +
- - - - + +    +
@@ -76,10 +83,10 @@
@@ -45,6 +44,7 @@ +
+
+ +
- - - - + +    +
@@ -77,10 +84,10 @@ - - + +
@@ -44,6 +43,7 @@
+
+
+ +
- - - - + +    +
@@ -76,10 +83,10 @@ + @@ -42,6 +42,7 @@ +
+
+ +
- - - - + +    +
@@ -74,10 +82,10 @@ + + @@ -18,10 +18,10 @@
+ @@ -19,10 +19,10 @@
+ - - + +
+ @@ -17,10 +17,10 @@
+ @@ -20,10 +20,10 @@
+ + + - - + +
+ + + @@ -18,10 +18,10 @@
+ @@ -19,10 +19,10 @@
+ - - + +
+ @@ -17,10 +17,10 @@
+ @@ -20,10 +20,10 @@
@@ -16,10 +15,10 @@
@@ -17,10 +16,10 @@
- - + +
+
+ @@ -51,10 +50,10 @@
@@ -52,10 +51,10 @@
- - + +
@@ -51,10 +50,10 @@
+ @@ -49,10 +49,10 @@
+ @@ -22,10 +21,10 @@
@@ -23,10 +22,10 @@ - - + +
@@ -22,10 +21,10 @@
+ @@ -20,10 +20,10 @@ + @@ -87,10 +86,10 @@ @@ -88,10 +87,10 @@ - - + +
@@ -87,10 +86,10 @@
+ @@ -85,10 +85,10 @@ + @@ -48,10 +47,10 @@
@@ -49,10 +48,10 @@
- - + +
@@ -48,10 +47,10 @@
+ @@ -46,10 +46,10 @@
+ @@ -25,10 +24,10 @@
@@ -26,10 +25,10 @@
- - + +
@@ -25,10 +24,10 @@
+ @@ -23,10 +23,10 @@
+ @@ -52,10 +51,10 @@
@@ -53,10 +52,10 @@
- - + +
@@ -52,10 +51,10 @@
+ @@ -50,10 +50,10 @@ + @@ -16,10 +15,10 @@
@@ -17,10 +16,10 @@
- - + +
+
+ @@ -24,10 +23,10 @@

Response

@@ -25,10 +24,10 @@

Response

- - + +
@@ -24,10 +23,10 @@

Response

+ @@ -22,10 +22,10 @@

Response

+ @@ -16,10 +15,10 @@
@@ -17,10 +16,10 @@
- - + +
+
+ @@ -16,10 +15,10 @@
@@ -17,10 +16,10 @@
- - + +
+
+ @@ -16,10 +15,10 @@
@@ -17,10 +16,10 @@
- - + +
+
+ @@ -16,10 +15,10 @@
@@ -17,10 +16,10 @@
- - + +
+
+ + @@ -20,10 +20,10 @@ + @@ -21,10 +21,10 @@ + - - + +
@@ -20,10 +20,10 @@
+ @@ -19,10 +19,10 @@ + @@ -22,10 +22,10 @@ @@ -16,10 +15,10 @@
@@ -17,10 +16,10 @@
- - + +
+
+ diff --git a/dist/samples/event-arguments/app/package.json b/dist/samples/event-arguments/app/package.json index 71af24304f..fa7e7e632a 100644 --- a/dist/samples/event-arguments/app/package.json +++ b/dist/samples/event-arguments/app/package.json @@ -27,8 +27,8 @@ }, "devDependencies": { "@types/google.maps": "^3.53.5", - "typescript": "^5.2.2", - "vite": "^5.0.13" + "typescript": "^5.5.3", + "vite": "^5.4.6" }, "private": true, "dependencies": {} diff --git a/dist/samples/event-arguments/docs/index.html b/dist/samples/event-arguments/docs/index.html index 71a8d6ed42..6f61b0d91b 100644 --- a/dist/samples/event-arguments/docs/index.html +++ b/dist/samples/event-arguments/docs/index.html @@ -8,7 +8,6 @@ Accessing Arguments in UI Events - diff --git a/dist/samples/event-arguments/iframe/index.html b/dist/samples/event-arguments/iframe/index.html index 31426a7b98..deda446223 100644 --- a/dist/samples/event-arguments/iframe/index.html +++ b/dist/samples/event-arguments/iframe/index.html @@ -7,10 +7,9 @@ Accessing Arguments in UI Events - - - + +
diff --git a/dist/samples/event-arguments/jsfiddle/demo.html b/dist/samples/event-arguments/jsfiddle/demo.html index b8b88b79df..542da0f2de 100644 --- a/dist/samples/event-arguments/jsfiddle/demo.html +++ b/dist/samples/event-arguments/jsfiddle/demo.html @@ -7,7 +7,7 @@ Accessing Arguments in UI Events - + diff --git a/dist/samples/event-arguments/playground/index.html b/dist/samples/event-arguments/playground/index.html index 7d4beee25e..e37a6fb98a 100644 --- a/dist/samples/event-arguments/playground/index.html +++ b/dist/samples/event-arguments/playground/index.html @@ -1,7 +1,7 @@ Accessing Arguments in UI Events - + diff --git a/dist/samples/event-click-latlng/app/package.json b/dist/samples/event-click-latlng/app/package.json index dedc245118..214738c346 100644 --- a/dist/samples/event-click-latlng/app/package.json +++ b/dist/samples/event-click-latlng/app/package.json @@ -27,8 +27,8 @@ }, "devDependencies": { "@types/google.maps": "^3.53.5", - "typescript": "^5.2.2", - "vite": "^5.0.13" + "typescript": "^5.5.3", + "vite": "^5.4.6" }, "private": true, "dependencies": {} diff --git a/dist/samples/event-click-latlng/docs/index.html b/dist/samples/event-click-latlng/docs/index.html index bfc2e4b57c..5c966e39b7 100644 --- a/dist/samples/event-click-latlng/docs/index.html +++ b/dist/samples/event-click-latlng/docs/index.html @@ -8,7 +8,6 @@ Event Click LatLng - diff --git a/dist/samples/event-click-latlng/iframe/index.html b/dist/samples/event-click-latlng/iframe/index.html index 9c4a464c20..69de9b01a9 100644 --- a/dist/samples/event-click-latlng/iframe/index.html +++ b/dist/samples/event-click-latlng/iframe/index.html @@ -7,10 +7,9 @@ Event Click LatLng - - - + +
diff --git a/dist/samples/event-click-latlng/jsfiddle/demo.html b/dist/samples/event-click-latlng/jsfiddle/demo.html index 39343e8d63..b1a5afe401 100644 --- a/dist/samples/event-click-latlng/jsfiddle/demo.html +++ b/dist/samples/event-click-latlng/jsfiddle/demo.html @@ -7,7 +7,7 @@ Event Click LatLng - + diff --git a/dist/samples/event-click-latlng/playground/index.html b/dist/samples/event-click-latlng/playground/index.html index 4550d6c427..ee75ca1f50 100644 --- a/dist/samples/event-click-latlng/playground/index.html +++ b/dist/samples/event-click-latlng/playground/index.html @@ -1,7 +1,7 @@ Event Click LatLng - + diff --git a/dist/samples/event-closure/app/package.json b/dist/samples/event-closure/app/package.json index e190412c0a..2b5e8c0c73 100644 --- a/dist/samples/event-closure/app/package.json +++ b/dist/samples/event-closure/app/package.json @@ -27,8 +27,8 @@ }, "devDependencies": { "@types/google.maps": "^3.53.5", - "typescript": "^5.2.2", - "vite": "^5.0.13" + "typescript": "^5.5.3", + "vite": "^5.4.6" }, "private": true, "dependencies": {} diff --git a/dist/samples/event-closure/docs/index.html b/dist/samples/event-closure/docs/index.html index 2caf91f540..8f69c683c7 100644 --- a/dist/samples/event-closure/docs/index.html +++ b/dist/samples/event-closure/docs/index.html @@ -8,7 +8,6 @@ Using Closures in Event Listeners - diff --git a/dist/samples/event-closure/iframe/index.html b/dist/samples/event-closure/iframe/index.html index 170df5f029..a2b8b31254 100644 --- a/dist/samples/event-closure/iframe/index.html +++ b/dist/samples/event-closure/iframe/index.html @@ -7,10 +7,9 @@ Using Closures in Event Listeners - - - + +
diff --git a/dist/samples/event-closure/jsfiddle/demo.html b/dist/samples/event-closure/jsfiddle/demo.html index efb907b999..f97b2b9ac6 100644 --- a/dist/samples/event-closure/jsfiddle/demo.html +++ b/dist/samples/event-closure/jsfiddle/demo.html @@ -7,7 +7,7 @@ Using Closures in Event Listeners - + diff --git a/dist/samples/event-closure/playground/index.html b/dist/samples/event-closure/playground/index.html index b8b1f7c4c7..67ff78024a 100644 --- a/dist/samples/event-closure/playground/index.html +++ b/dist/samples/event-closure/playground/index.html @@ -1,7 +1,7 @@ Using Closures in Event Listeners - + diff --git a/dist/samples/event-domListener/app/package.json b/dist/samples/event-domListener/app/package.json index e93d3cfee0..06e057bd63 100644 --- a/dist/samples/event-domListener/app/package.json +++ b/dist/samples/event-domListener/app/package.json @@ -27,8 +27,8 @@ }, "devDependencies": { "@types/google.maps": "^3.53.5", - "typescript": "^5.2.2", - "vite": "^5.0.13" + "typescript": "^5.5.3", + "vite": "^5.4.6" }, "private": true, "dependencies": {} diff --git a/dist/samples/event-domListener/docs/index.html b/dist/samples/event-domListener/docs/index.html index 034e780871..f4d0a91124 100644 --- a/dist/samples/event-domListener/docs/index.html +++ b/dist/samples/event-domListener/docs/index.html @@ -8,7 +8,6 @@ Listening to DOM Events - diff --git a/dist/samples/event-domListener/iframe/index.html b/dist/samples/event-domListener/iframe/index.html index d567ca0a2d..717aa2093c 100644 --- a/dist/samples/event-domListener/iframe/index.html +++ b/dist/samples/event-domListener/iframe/index.html @@ -7,10 +7,9 @@ Listening to DOM Events - - - + +
diff --git a/dist/samples/event-domListener/jsfiddle/demo.html b/dist/samples/event-domListener/jsfiddle/demo.html index a114f124fe..6e601df6e1 100644 --- a/dist/samples/event-domListener/jsfiddle/demo.html +++ b/dist/samples/event-domListener/jsfiddle/demo.html @@ -7,7 +7,7 @@ Listening to DOM Events - + diff --git a/dist/samples/event-domListener/playground/index.html b/dist/samples/event-domListener/playground/index.html index d67637f9f9..2145e661e2 100644 --- a/dist/samples/event-domListener/playground/index.html +++ b/dist/samples/event-domListener/playground/index.html @@ -1,7 +1,7 @@ Listening to DOM Events - + @@ -22,10 +21,10 @@ @@ -23,10 +22,10 @@ - - + +
@@ -22,10 +21,10 @@ + @@ -20,10 +20,10 @@ + diff --git a/dist/samples/event-properties/app/package.json b/dist/samples/event-properties/app/package.json index 44385f4af3..32a8f0aeae 100644 --- a/dist/samples/event-properties/app/package.json +++ b/dist/samples/event-properties/app/package.json @@ -27,8 +27,8 @@ }, "devDependencies": { "@types/google.maps": "^3.53.5", - "typescript": "^5.2.2", - "vite": "^5.0.13" + "typescript": "^5.5.3", + "vite": "^5.4.6" }, "private": true, "dependencies": {} diff --git a/dist/samples/event-properties/docs/index.html b/dist/samples/event-properties/docs/index.html index 0bc718a512..6194ac2ac6 100644 --- a/dist/samples/event-properties/docs/index.html +++ b/dist/samples/event-properties/docs/index.html @@ -8,7 +8,6 @@ Getting Properties With Event Handlers - diff --git a/dist/samples/event-properties/iframe/index.html b/dist/samples/event-properties/iframe/index.html index 4dba7b8ea5..c2d4eea2fc 100644 --- a/dist/samples/event-properties/iframe/index.html +++ b/dist/samples/event-properties/iframe/index.html @@ -7,10 +7,9 @@ Getting Properties With Event Handlers - - - + +
diff --git a/dist/samples/event-properties/jsfiddle/demo.html b/dist/samples/event-properties/jsfiddle/demo.html index 565ba671f4..220dea5f07 100644 --- a/dist/samples/event-properties/jsfiddle/demo.html +++ b/dist/samples/event-properties/jsfiddle/demo.html @@ -7,7 +7,7 @@ Getting Properties With Event Handlers - + diff --git a/dist/samples/event-properties/playground/index.html b/dist/samples/event-properties/playground/index.html index 88c826a2e8..c2fc64c329 100644 --- a/dist/samples/event-properties/playground/index.html +++ b/dist/samples/event-properties/playground/index.html @@ -1,7 +1,7 @@ Getting Properties With Event Handlers - + diff --git a/dist/samples/event-simple/app/package.json b/dist/samples/event-simple/app/package.json index c42908a46e..0386e5158b 100644 --- a/dist/samples/event-simple/app/package.json +++ b/dist/samples/event-simple/app/package.json @@ -27,8 +27,8 @@ }, "devDependencies": { "@types/google.maps": "^3.53.5", - "typescript": "^5.2.2", - "vite": "^5.0.13" + "typescript": "^5.5.3", + "vite": "^5.4.6" }, "private": true, "dependencies": {} diff --git a/dist/samples/event-simple/docs/index.html b/dist/samples/event-simple/docs/index.html index fb72ed2683..518a81352c 100644 --- a/dist/samples/event-simple/docs/index.html +++ b/dist/samples/event-simple/docs/index.html @@ -8,7 +8,6 @@ Simple Click Events - diff --git a/dist/samples/event-simple/iframe/index.html b/dist/samples/event-simple/iframe/index.html index 73ef0ff7cd..99b807d54e 100644 --- a/dist/samples/event-simple/iframe/index.html +++ b/dist/samples/event-simple/iframe/index.html @@ -7,10 +7,9 @@ Simple Click Events - - - + +
diff --git a/dist/samples/event-simple/jsfiddle/demo.html b/dist/samples/event-simple/jsfiddle/demo.html index bcacaa0f86..7012244739 100644 --- a/dist/samples/event-simple/jsfiddle/demo.html +++ b/dist/samples/event-simple/jsfiddle/demo.html @@ -7,7 +7,7 @@ Simple Click Events - + diff --git a/dist/samples/event-simple/playground/index.html b/dist/samples/event-simple/playground/index.html index cb01430879..b12f7d283c 100644 --- a/dist/samples/event-simple/playground/index.html +++ b/dist/samples/event-simple/playground/index.html @@ -1,7 +1,7 @@ Simple Click Events - + @@ -21,10 +20,10 @@
@@ -22,10 +21,10 @@
- - + +
@@ -21,10 +20,10 @@
+ @@ -19,10 +19,10 @@
+ @@ -21,10 +20,10 @@
@@ -22,10 +21,10 @@
- - + +
@@ -21,10 +20,10 @@
+ @@ -19,10 +19,10 @@
+ @@ -16,10 +15,10 @@
@@ -17,10 +16,10 @@
- - + +
+
+ @@ -16,10 +15,10 @@
@@ -17,10 +16,10 @@
- - + +
+
+ @@ -20,10 +19,10 @@
@@ -21,10 +20,10 @@
- - + +
@@ -20,10 +19,10 @@
+ @@ -18,10 +18,10 @@
+ @@ -16,10 +15,10 @@
@@ -17,10 +16,10 @@
- - + +
+
+ @@ -22,10 +21,10 @@
@@ -23,10 +22,10 @@
- - + +
@@ -22,10 +21,10 @@
+ @@ -20,10 +20,10 @@
+ @@ -21,10 +20,10 @@ @@ -22,10 +21,10 @@ - - + +
@@ -21,10 +20,10 @@ + @@ -19,10 +19,10 @@ + @@ -16,10 +15,10 @@
@@ -17,10 +16,10 @@
- - + +
+
+ @@ -33,10 +32,10 @@
@@ -34,10 +33,10 @@
- - + +
@@ -33,10 +32,10 @@
+ @@ -31,10 +31,10 @@
+ @@ -16,10 +15,10 @@
@@ -17,10 +16,10 @@
- - + +
+
+ @@ -16,10 +15,10 @@
@@ -17,10 +16,10 @@
- - + +
+
+ @@ -16,10 +15,10 @@
@@ -17,10 +16,10 @@
- - + +
+
+ @@ -16,10 +15,10 @@
@@ -17,10 +16,10 @@
- - + +
+
+ @@ -19,10 +18,10 @@
@@ -20,10 +19,10 @@ - - + +
@@ -19,10 +18,10 @@
+ @@ -17,10 +17,10 @@ + @@ -16,10 +15,10 @@
@@ -17,10 +16,10 @@
- - + +
+
+ @@ -16,10 +15,10 @@
@@ -17,10 +16,10 @@
- - + +
+
+ @@ -16,10 +15,10 @@
@@ -17,10 +16,10 @@
- - + +
+
+ @@ -16,10 +15,10 @@
@@ -17,10 +16,10 @@
- - + +
+
+ @@ -16,10 +15,10 @@
@@ -17,10 +16,10 @@
- - + +
+
+ @@ -16,10 +15,10 @@
@@ -17,10 +16,10 @@
- - + +
+
+ @@ -16,10 +15,10 @@
@@ -17,10 +16,10 @@
- - + +
+
+ @@ -16,10 +15,10 @@
@@ -17,10 +16,10 @@
- - + +
+
+ + + + - - + +
@@ -40,10 +40,10 @@
+ + @@ -16,10 +15,10 @@
@@ -17,10 +16,10 @@
- - + +
+
+ @@ -17,10 +16,10 @@
?
@@ -18,10 +17,10 @@
?
- - + +
?
+ @@ -15,10 +15,10 @@
?
+ @@ -16,10 +15,10 @@
@@ -17,10 +16,10 @@
- - + +
+
+ @@ -16,10 +15,10 @@
@@ -17,10 +16,10 @@
- - + +
+
+ @@ -16,10 +15,10 @@
@@ -17,10 +16,10 @@
- - + +
+
+ @@ -16,10 +15,10 @@
@@ -17,10 +16,10 @@
- - + +
+
+ @@ -16,10 +15,10 @@
@@ -17,10 +16,10 @@
- - + +
+
+ @@ -16,10 +15,10 @@
@@ -17,10 +16,10 @@
- - + +
+
+ @@ -16,10 +15,10 @@
@@ -17,10 +16,10 @@
- - + +
+
+ @@ -22,10 +21,10 @@
@@ -23,10 +22,10 @@
- - + +
@@ -22,10 +21,10 @@
+ @@ -20,10 +20,10 @@
+ @@ -19,10 +18,10 @@
@@ -20,10 +19,10 @@ - - + +
@@ -19,10 +18,10 @@
+ @@ -17,10 +17,10 @@ + @@ -16,10 +15,10 @@
@@ -17,10 +16,10 @@
- - + +
+
+ @@ -16,10 +15,10 @@
@@ -17,10 +16,10 @@
- - + +
+
+ @@ -16,10 +15,10 @@
@@ -17,10 +16,10 @@
- - + +
+
+ @@ -17,10 +16,10 @@

Legend

@@ -18,10 +17,10 @@

Legend

- - + +

Legend

+ @@ -15,10 +15,10 @@

Legend

+ @@ -16,10 +15,10 @@
@@ -17,10 +16,10 @@
- - + +
+
+ @@ -16,10 +15,10 @@
@@ -17,10 +16,10 @@
- - + +
+
+ @@ -17,10 +16,10 @@
@@ -18,10 +17,10 @@
- - + +
+ @@ -15,10 +15,10 @@
+ @@ -16,10 +15,10 @@
@@ -17,10 +16,10 @@
- - + +
+
+ @@ -16,10 +15,10 @@
@@ -17,10 +16,10 @@
- - + +
+
+ @@ -16,10 +15,10 @@
@@ -17,10 +16,10 @@
- - + +
+
+ diff --git a/dist/samples/map-events/app/package.json b/dist/samples/map-events/app/package.json index 7435a8f5e1..81b52dcd22 100644 --- a/dist/samples/map-events/app/package.json +++ b/dist/samples/map-events/app/package.json @@ -27,8 +27,8 @@ }, "devDependencies": { "@types/google.maps": "^3.53.5", - "typescript": "^5.2.2", - "vite": "^5.0.13" + "typescript": "^5.5.3", + "vite": "^5.4.6" }, "private": true, "dependencies": {} diff --git a/dist/samples/map-events/docs/index.html b/dist/samples/map-events/docs/index.html index 63cc01dc3f..a6023c7cd3 100644 --- a/dist/samples/map-events/docs/index.html +++ b/dist/samples/map-events/docs/index.html @@ -8,7 +8,6 @@ Map Events - diff --git a/dist/samples/map-events/docs/index.js b/dist/samples/map-events/docs/index.js index 7364638d10..bbbd3a086d 100644 --- a/dist/samples/map-events/docs/index.js +++ b/dist/samples/map-events/docs/index.js @@ -22,7 +22,7 @@ const events = [ "mouseover", "projection_changed", "resize", - "rightclick", + "rightclick", // use contextmenu "tilesloaded", "tilt_changed", "zoom_changed", diff --git a/dist/samples/map-events/iframe/index.html b/dist/samples/map-events/iframe/index.html index 14f90bb191..bd80d249a5 100644 --- a/dist/samples/map-events/iframe/index.html +++ b/dist/samples/map-events/iframe/index.html @@ -7,10 +7,9 @@ Map Events - - - + +
diff --git a/dist/samples/map-events/jsfiddle/demo.html b/dist/samples/map-events/jsfiddle/demo.html index 49930bea86..1ab56cea7a 100644 --- a/dist/samples/map-events/jsfiddle/demo.html +++ b/dist/samples/map-events/jsfiddle/demo.html @@ -7,7 +7,7 @@ Map Events - + diff --git a/dist/samples/map-events/jsfiddle/demo.js b/dist/samples/map-events/jsfiddle/demo.js index 3846a46989..42ed99caa2 100644 --- a/dist/samples/map-events/jsfiddle/demo.js +++ b/dist/samples/map-events/jsfiddle/demo.js @@ -20,7 +20,7 @@ const events = [ "mouseover", "projection_changed", "resize", - "rightclick", + "rightclick", // use contextmenu "tilesloaded", "tilt_changed", "zoom_changed", diff --git a/dist/samples/map-events/playground/index.html b/dist/samples/map-events/playground/index.html index a6970af9a3..32e9f05da7 100644 --- a/dist/samples/map-events/playground/index.html +++ b/dist/samples/map-events/playground/index.html @@ -1,7 +1,7 @@ Map Events - + @@ -16,10 +15,10 @@
@@ -17,10 +16,10 @@
- - + +
+
+ @@ -16,10 +15,10 @@
@@ -17,10 +16,10 @@
- - + +
+
+ @@ -16,10 +15,10 @@
@@ -17,10 +16,10 @@
- - + +
+
+ @@ -16,10 +15,10 @@
@@ -17,10 +16,10 @@
- - + +
+
+ @@ -17,10 +16,10 @@
@@ -18,10 +17,10 @@
- - + +
+ @@ -15,10 +15,10 @@
+ @@ -16,10 +15,10 @@
@@ -17,10 +16,10 @@
- - + +
+
+ @@ -16,10 +15,10 @@
@@ -17,10 +16,10 @@
- - + +
+
+ diff --git a/dist/samples/map-simple/app/package.json b/dist/samples/map-simple/app/package.json index c4d2ca1183..a3850fdca5 100644 --- a/dist/samples/map-simple/app/package.json +++ b/dist/samples/map-simple/app/package.json @@ -27,8 +27,8 @@ }, "devDependencies": { "@types/google.maps": "^3.53.5", - "typescript": "^5.2.2", - "vite": "^5.0.13" + "typescript": "^5.5.3", + "vite": "^5.4.6" }, "private": true, "dependencies": {} diff --git a/dist/samples/map-simple/docs/index.html b/dist/samples/map-simple/docs/index.html index 8da684202c..bc9b11b209 100644 --- a/dist/samples/map-simple/docs/index.html +++ b/dist/samples/map-simple/docs/index.html @@ -8,7 +8,6 @@ Simple Map - diff --git a/dist/samples/map-simple/iframe/index.html b/dist/samples/map-simple/iframe/index.html index 8c777378b8..0a43ba8744 100644 --- a/dist/samples/map-simple/iframe/index.html +++ b/dist/samples/map-simple/iframe/index.html @@ -7,10 +7,9 @@ Simple Map - - - + +
diff --git a/dist/samples/map-simple/jsfiddle/demo.html b/dist/samples/map-simple/jsfiddle/demo.html index 6ed7518914..10902cbf2b 100644 --- a/dist/samples/map-simple/jsfiddle/demo.html +++ b/dist/samples/map-simple/jsfiddle/demo.html @@ -7,7 +7,7 @@ Simple Map - + diff --git a/dist/samples/map-simple/playground/index.html b/dist/samples/map-simple/playground/index.html index f1264f8e07..449bf59420 100644 --- a/dist/samples/map-simple/playground/index.html +++ b/dist/samples/map-simple/playground/index.html @@ -1,7 +1,7 @@ Simple Map - + diff --git a/dist/samples/map-sync/app/package.json b/dist/samples/map-sync/app/package.json index 7285d1b12f..dc465b5323 100644 --- a/dist/samples/map-sync/app/package.json +++ b/dist/samples/map-sync/app/package.json @@ -27,8 +27,8 @@ }, "devDependencies": { "@types/google.maps": "^3.53.5", - "typescript": "^5.2.2", - "vite": "^5.0.13" + "typescript": "^5.5.3", + "vite": "^5.4.6" }, "private": true, "dependencies": {} diff --git a/dist/samples/map-sync/docs/index.html b/dist/samples/map-sync/docs/index.html index 48adcb858a..4e971cab04 100644 --- a/dist/samples/map-sync/docs/index.html +++ b/dist/samples/map-sync/docs/index.html @@ -8,7 +8,6 @@ Synchronous Loading - diff --git a/dist/samples/map-sync/iframe/index.html b/dist/samples/map-sync/iframe/index.html index 912056bca5..022135fa92 100644 --- a/dist/samples/map-sync/iframe/index.html +++ b/dist/samples/map-sync/iframe/index.html @@ -7,10 +7,9 @@ Synchronous Loading - - - + +
diff --git a/dist/samples/map-sync/jsfiddle/demo.html b/dist/samples/map-sync/jsfiddle/demo.html index 8b223ae091..ef6b68b060 100644 --- a/dist/samples/map-sync/jsfiddle/demo.html +++ b/dist/samples/map-sync/jsfiddle/demo.html @@ -7,7 +7,7 @@ Synchronous Loading - + diff --git a/dist/samples/map-sync/playground/index.html b/dist/samples/map-sync/playground/index.html index 7ebbb622ae..269c8ee359 100644 --- a/dist/samples/map-sync/playground/index.html +++ b/dist/samples/map-sync/playground/index.html @@ -1,7 +1,7 @@ Synchronous Loading - + @@ -16,10 +15,10 @@
@@ -17,10 +16,10 @@
- - + +
+
+ @@ -16,10 +15,10 @@
@@ -17,10 +16,10 @@
- - + +
+
+ @@ -16,10 +15,10 @@
@@ -17,10 +16,10 @@
- - + +
+
+ @@ -16,10 +15,10 @@
@@ -17,10 +16,10 @@
- - + +
+
+ @@ -16,10 +15,10 @@
@@ -17,10 +16,10 @@
- - + +
+
+ @@ -16,10 +15,10 @@
@@ -17,10 +16,10 @@
- - + +
+
+ @@ -19,10 +18,10 @@
@@ -20,10 +19,10 @@
- - + +
@@ -19,10 +18,10 @@
+ @@ -17,10 +17,10 @@
+ @@ -16,10 +15,10 @@
@@ -17,10 +16,10 @@
- - + +
+
+ diff --git a/dist/samples/marker-clustering/app/package.json b/dist/samples/marker-clustering/app/package.json index 504fc7ece8..9a11a99417 100644 --- a/dist/samples/marker-clustering/app/package.json +++ b/dist/samples/marker-clustering/app/package.json @@ -27,8 +27,8 @@ }, "devDependencies": { "@types/google.maps": "^3.53.5", - "typescript": "^5.2.2", - "vite": "^5.0.13" + "typescript": "^5.5.3", + "vite": "^5.4.6" }, "private": true, "dependencies": { diff --git a/dist/samples/marker-clustering/docs/index.html b/dist/samples/marker-clustering/docs/index.html index 36d9729043..a06a6308f7 100644 --- a/dist/samples/marker-clustering/docs/index.html +++ b/dist/samples/marker-clustering/docs/index.html @@ -8,7 +8,6 @@ Marker Clustering - diff --git a/dist/samples/marker-clustering/docs/index.js b/dist/samples/marker-clustering/docs/index.js index 1ee58b71ab..4ce205ecad 100644 --- a/dist/samples/marker-clustering/docs/index.js +++ b/dist/samples/marker-clustering/docs/index.js @@ -3,9 +3,9 @@ * Copyright 2019 Google LLC. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0 */ +// [START maps_marker_clustering] import { MarkerClusterer } from "@googlemaps/markerclusterer"; -// [START maps_marker_clustering] async function initMap() { // Request needed libraries. const { Map, InfoWindow } = await google.maps.importLibrary("maps"); diff --git a/dist/samples/marker-clustering/iframe/index.html b/dist/samples/marker-clustering/iframe/index.html index f34d982cfd..a2cb8a9e7e 100644 --- a/dist/samples/marker-clustering/iframe/index.html +++ b/dist/samples/marker-clustering/iframe/index.html @@ -7,10 +7,9 @@ Marker Clustering - - - + +
diff --git a/dist/samples/marker-clustering/jsfiddle/demo.html b/dist/samples/marker-clustering/jsfiddle/demo.html index 19c07bc35a..4287e13e97 100644 --- a/dist/samples/marker-clustering/jsfiddle/demo.html +++ b/dist/samples/marker-clustering/jsfiddle/demo.html @@ -7,7 +7,7 @@ Marker Clustering - + diff --git a/dist/samples/marker-clustering/playground/index.html b/dist/samples/marker-clustering/playground/index.html index 7a47fe5bf9..ec6d080265 100644 --- a/dist/samples/marker-clustering/playground/index.html +++ b/dist/samples/marker-clustering/playground/index.html @@ -1,7 +1,7 @@ Marker Clustering - + @@ -16,10 +15,10 @@
@@ -17,10 +16,10 @@
- - + +
+
+ +
+
+ - - + +
+ + @@ -22,10 +21,10 @@

Click on the map to add markers.

@@ -23,10 +22,10 @@

Click on the map to add markers.

- - + +
@@ -22,10 +21,10 @@

Click on the map to add markers.

+ @@ -20,10 +20,10 @@

Click on the map to add markers.

+ @@ -16,10 +15,10 @@
@@ -17,10 +16,10 @@
- - + +
+
+ @@ -16,10 +15,10 @@
@@ -17,10 +16,10 @@
- - + +
+
+ @@ -16,10 +15,10 @@
@@ -17,10 +16,10 @@
- - + +
+
+ @@ -16,10 +15,10 @@
@@ -17,10 +16,10 @@
- - + +
+
+ @@ -16,10 +15,10 @@
@@ -17,10 +16,10 @@
- - + +
@@ -15,10 +14,10 @@
@@ -16,10 +15,10 @@
@@ -17,10 +16,10 @@
- - + +
+
+ @@ -17,10 +16,10 @@
Hello world!
@@ -18,10 +17,10 @@
Hello world!
- - + +
Hello world!
+ @@ -15,10 +15,10 @@
Hello world!
+ @@ -20,10 +19,10 @@
@@ -21,10 +20,10 @@
- - + +
@@ -20,10 +19,10 @@
+ @@ -18,10 +18,10 @@
+ @@ -16,10 +15,10 @@
@@ -17,10 +16,10 @@
- - + +
+
+ @@ -16,10 +15,10 @@
@@ -17,10 +16,10 @@
- - + +
+
+ @@ -16,10 +15,10 @@
@@ -17,10 +16,10 @@
- - + +
+
+ @@ -16,10 +15,10 @@
@@ -17,10 +16,10 @@
- - + +
+
+ @@ -16,10 +15,10 @@
@@ -17,10 +16,10 @@
- - + +
+
+ + + + +
+ + Powered by Google + + + + + diff --git a/dist/samples/place-autocomplete-data-session/app/index.ts b/dist/samples/place-autocomplete-data-session/app/index.ts new file mode 100644 index 0000000000..8b2817a873 --- /dev/null +++ b/dist/samples/place-autocomplete-data-session/app/index.ts @@ -0,0 +1,95 @@ +/** + * @license + * Copyright 2024 Google LLC. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 + */ + +let title; +let results; +let input; +let token; + +// Add an initial request body. +let request = { + input: "", + locationRestriction: { west: -122.44, north: 37.8, east: -122.39, south: 37.78 }, + origin: { lat: 37.7893, lng: -122.4039 }, + includedPrimaryTypes: ["restaurant"], + language: "en-US", + region: "us", +}; + +async function init() { + token = new google.maps.places.AutocompleteSessionToken(); + + title = document.getElementById('title'); + results = document.getElementById('results'); + input = document.querySelector("input"); + input.addEventListener("input", makeAcRequest); + request = refreshToken(request) as any; +} + +async function makeAcRequest(input) { + // Reset elements and exit if an empty string is received. + if (input.target.value == '') { + title.innerText = ''; + results.replaceChildren(); + return; + } + + // Add the latest char sequence to the request. + request.input = input.target.value; + + // Fetch autocomplete suggestions and show them in a list. + // @ts-ignore + const { suggestions } = await google.maps.places.AutocompleteSuggestion.fetchAutocompleteSuggestions(request); + + title.innerText = 'Query predictions for "' + request.input + '"'; + + // Clear the list first. + results.replaceChildren(); + + for (const suggestion of suggestions) { + const placePrediction = suggestion.placePrediction; + + // Create a link for the place, add an event handler to fetch the place. + const a = document.createElement('a'); + a.addEventListener('click', () => { + onPlaceSelected(placePrediction!.toPlace()); + }); + a.innerText = placePrediction!.text.toString(); + + // Create a new list element. + const li = document.createElement('li'); + li.appendChild(a); + results.appendChild(li); + } +} + +// Event handler for clicking on a suggested place. +async function onPlaceSelected(place) { + await place.fetchFields({ + fields: ['displayName', 'formattedAddress'], + }); + let placeText = document.createTextNode(place.displayName + ': ' + place.formattedAddress); + results.replaceChildren(placeText); + title.innerText = 'Selected Place:'; + input.value = ''; + refreshToken(request); +} + +// Helper function to refresh the session token. +async function refreshToken(request) { + // Create a new session token and add it to the request. + token = new google.maps.places.AutocompleteSessionToken(); + request.sessionToken = token; + return request; +} + +declare global { + interface Window { + init: () => void; + } + } + window.init = init; +export { }; \ No newline at end of file diff --git a/dist/samples/place-autocomplete-data-session/app/package.json b/dist/samples/place-autocomplete-data-session/app/package.json new file mode 100644 index 0000000000..3de8d10425 --- /dev/null +++ b/dist/samples/place-autocomplete-data-session/app/package.json @@ -0,0 +1,35 @@ +{ + "name": "place-autocomplete-data-session", + "description": "Samples for Google Maps JavaScript", + "version": "2.1.4", + "keywords": [ + "google", + "javascript", + "maps", + "samples" + ], + "homepage": "https://github.com/googlemaps/js-samples#readme", + "bugs": { + "url": "https://github.com/googlemaps/js-samples/issues" + }, + "repository": { + "type": "git", + "url": "git+https://github.com/googlemaps/js-samples.git" + }, + "files": [], + "license": "Apache-2.0", + "scripts": { + "dev": "vite", + "start": "vite", + "build": "vite build --outDir dist --base './'", + "test": "tsc --no-emit", + "preview": "vite preview" + }, + "devDependencies": { + "@types/google.maps": "^3.53.5", + "typescript": "^5.5.3", + "vite": "^5.4.6" + }, + "private": true, + "dependencies": {} +} \ No newline at end of file diff --git a/dist/samples/place-autocomplete-data-session/app/style.css b/dist/samples/place-autocomplete-data-session/app/style.css new file mode 100644 index 0000000000..d3245cacbd --- /dev/null +++ b/dist/samples/place-autocomplete-data-session/app/style.css @@ -0,0 +1,33 @@ +/** + * @license + * Copyright 2019 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. + */ +#map { + height: 100%; +} + +/* + * Optional: Makes the sample page fill the window. + */ +html, +body { + height: 100%; + margin: 0; + padding: 0; +} + +a { + cursor: pointer; + text-decoration: underline; + color: blue; +} + +input { + width: 300px; +} + diff --git a/dist/samples/place-autocomplete-data-session/app/tsconfig.json b/dist/samples/place-autocomplete-data-session/app/tsconfig.json new file mode 100644 index 0000000000..b405998dad --- /dev/null +++ b/dist/samples/place-autocomplete-data-session/app/tsconfig.json @@ -0,0 +1,16 @@ +{ + "compilerOptions": { + "module": "esnext", + "target": "esnext", + "strict": true, + "noImplicitAny": false, + "lib": [ + "esnext", + "es6", + "dom", + "dom.iterable" + ], + "moduleResolution": "Node", + "jsx": "preserve" + } +} \ No newline at end of file diff --git a/dist/samples/place-autocomplete-data-session/app/vite.config.js b/dist/samples/place-autocomplete-data-session/app/vite.config.js new file mode 100644 index 0000000000..d49e45cd7e --- /dev/null +++ b/dist/samples/place-autocomplete-data-session/app/vite.config.js @@ -0,0 +1,11 @@ +import { defineConfig } from "vite"; + +// https://vitejs.dev/config/ +export default defineConfig({ + server: { + hmr: + process.env.CODESANDBOX_SSE || process.env.GITPOD_WORKSPACE_ID + ? 443 + : undefined, + }, +}); diff --git a/dist/samples/place-autocomplete-data-session/docs/index.html b/dist/samples/place-autocomplete-data-session/docs/index.html new file mode 100644 index 0000000000..3fd5df3f21 --- /dev/null +++ b/dist/samples/place-autocomplete-data-session/docs/index.html @@ -0,0 +1,40 @@ + + + + + + Place Autocomplete Data API Session + + + + + + + +
+ + Powered by Google + + + + + + + diff --git a/dist/samples/place-autocomplete-data-session/docs/index.js b/dist/samples/place-autocomplete-data-session/docs/index.js new file mode 100644 index 0000000000..fead582dbb --- /dev/null +++ b/dist/samples/place-autocomplete-data-session/docs/index.js @@ -0,0 +1,100 @@ +/** + * @license + * Copyright 2024 Google LLC. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 + */ +// [START maps_place_autocomplete_data_session] +let title; +let results; +let input; +let token; +// Add an initial request body. +let request = { + input: "", + locationRestriction: { + west: -122.44, + north: 37.8, + east: -122.39, + south: 37.78, + }, + origin: { lat: 37.7893, lng: -122.4039 }, + includedPrimaryTypes: ["restaurant"], + language: "en-US", + region: "us", +}; + +async function init() { + token = new google.maps.places.AutocompleteSessionToken(); + title = document.getElementById("title"); + results = document.getElementById("results"); + input = document.querySelector("input"); + input.addEventListener("input", makeAcRequest); + request = refreshToken(request); +} + +async function makeAcRequest(input) { + // Reset elements and exit if an empty string is received. + if (input.target.value == "") { + title.innerText = ""; + results.replaceChildren(); + return; + } + + // Add the latest char sequence to the request. + request.input = input.target.value; + + // Fetch autocomplete suggestions and show them in a list. + // @ts-ignore + const { suggestions } = + await google.maps.places.AutocompleteSuggestion.fetchAutocompleteSuggestions( + request, + ); + + title.innerText = 'Query predictions for "' + request.input + '"'; + // Clear the list first. + results.replaceChildren(); + + for (const suggestion of suggestions) { + const placePrediction = suggestion.placePrediction; + // Create a link for the place, add an event handler to fetch the place. + const a = document.createElement("a"); + + a.addEventListener("click", () => { + onPlaceSelected(placePrediction.toPlace()); + }); + a.innerText = placePrediction.text.toString(); + + // Create a new list element. + const li = document.createElement("li"); + + li.appendChild(a); + results.appendChild(li); + } +} + +// Event handler for clicking on a suggested place. +async function onPlaceSelected(place) { + await place.fetchFields({ + fields: ["displayName", "formattedAddress"], + }); + + let placeText = document.createTextNode( + place.displayName + ": " + place.formattedAddress, + ); + + results.replaceChildren(placeText); + title.innerText = "Selected Place:"; + input.value = ""; + refreshToken(request); +} + +// Helper function to refresh the session token. +async function refreshToken(request) { + // Create a new session token and add it to the request. + token = new google.maps.places.AutocompleteSessionToken(); + request.sessionToken = token; + return request; +} + +window.init = init; +// [END maps_place_autocomplete_data_session] diff --git a/dist/samples/place-autocomplete-data-session/docs/style.css b/dist/samples/place-autocomplete-data-session/docs/style.css new file mode 100644 index 0000000000..3f89029133 --- /dev/null +++ b/dist/samples/place-autocomplete-data-session/docs/style.css @@ -0,0 +1,35 @@ +/** + * @license + * Copyright 2019 Google LLC. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 + */ +/* [START maps_place_autocomplete_data_session] */ +/* + * Always set the map height explicitly to define the size of the div element + * that contains the map. + */ +#map { + height: 100%; +} + +/* + * Optional: Makes the sample page fill the window. + */ +html, +body { + height: 100%; + margin: 0; + padding: 0; +} + +a { + cursor: pointer; + text-decoration: underline; + color: blue; +} + +input { + width: 300px; +} + +/* [END maps_place_autocomplete_data_session] */ \ No newline at end of file diff --git a/dist/samples/place-autocomplete-data-session/iframe/index.html b/dist/samples/place-autocomplete-data-session/iframe/index.html new file mode 100644 index 0000000000..dcb02e39a9 --- /dev/null +++ b/dist/samples/place-autocomplete-data-session/iframe/index.html @@ -0,0 +1,36 @@ + + + + + Place Autocomplete Data API Session + + + + + + +
+ + Powered by Google + + + + + diff --git a/dist/samples/place-autocomplete-data-session/jsfiddle/demo.css b/dist/samples/place-autocomplete-data-session/jsfiddle/demo.css new file mode 100644 index 0000000000..d3245cacbd --- /dev/null +++ b/dist/samples/place-autocomplete-data-session/jsfiddle/demo.css @@ -0,0 +1,33 @@ +/** + * @license + * Copyright 2019 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. + */ +#map { + height: 100%; +} + +/* + * Optional: Makes the sample page fill the window. + */ +html, +body { + height: 100%; + margin: 0; + padding: 0; +} + +a { + cursor: pointer; + text-decoration: underline; + color: blue; +} + +input { + width: 300px; +} + diff --git a/dist/samples/place-autocomplete-data-session/jsfiddle/demo.details b/dist/samples/place-autocomplete-data-session/jsfiddle/demo.details new file mode 100644 index 0000000000..273703e93e --- /dev/null +++ b/dist/samples/place-autocomplete-data-session/jsfiddle/demo.details @@ -0,0 +1,7 @@ +name: Place Autocomplete Data API Session +authors: + - Justin Poehnelt +tags: + - google maps +load_type: h +description: Sample code for Google Maps Platform JavaScript API diff --git a/dist/samples/place-autocomplete-data-session/jsfiddle/demo.html b/dist/samples/place-autocomplete-data-session/jsfiddle/demo.html new file mode 100644 index 0000000000..9fad214a50 --- /dev/null +++ b/dist/samples/place-autocomplete-data-session/jsfiddle/demo.html @@ -0,0 +1,35 @@ + + + + + Place Autocomplete Data API Session + + + + + +
+ + Powered by Google + + + + + diff --git a/dist/samples/place-autocomplete-data-session/jsfiddle/demo.js b/dist/samples/place-autocomplete-data-session/jsfiddle/demo.js new file mode 100644 index 0000000000..e4a804a0a9 --- /dev/null +++ b/dist/samples/place-autocomplete-data-session/jsfiddle/demo.js @@ -0,0 +1,98 @@ +/** + * @license + * Copyright 2024 Google LLC. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 + */ +let title; +let results; +let input; +let token; +// Add an initial request body. +let request = { + input: "", + locationRestriction: { + west: -122.44, + north: 37.8, + east: -122.39, + south: 37.78, + }, + origin: { lat: 37.7893, lng: -122.4039 }, + includedPrimaryTypes: ["restaurant"], + language: "en-US", + region: "us", +}; + +async function init() { + token = new google.maps.places.AutocompleteSessionToken(); + title = document.getElementById("title"); + results = document.getElementById("results"); + input = document.querySelector("input"); + input.addEventListener("input", makeAcRequest); + request = refreshToken(request); +} + +async function makeAcRequest(input) { + // Reset elements and exit if an empty string is received. + if (input.target.value == "") { + title.innerText = ""; + results.replaceChildren(); + return; + } + + // Add the latest char sequence to the request. + request.input = input.target.value; + + // Fetch autocomplete suggestions and show them in a list. + // @ts-ignore + const { suggestions } = + await google.maps.places.AutocompleteSuggestion.fetchAutocompleteSuggestions( + request, + ); + + title.innerText = 'Query predictions for "' + request.input + '"'; + // Clear the list first. + results.replaceChildren(); + + for (const suggestion of suggestions) { + const placePrediction = suggestion.placePrediction; + // Create a link for the place, add an event handler to fetch the place. + const a = document.createElement("a"); + + a.addEventListener("click", () => { + onPlaceSelected(placePrediction.toPlace()); + }); + a.innerText = placePrediction.text.toString(); + + // Create a new list element. + const li = document.createElement("li"); + + li.appendChild(a); + results.appendChild(li); + } +} + +// Event handler for clicking on a suggested place. +async function onPlaceSelected(place) { + await place.fetchFields({ + fields: ["displayName", "formattedAddress"], + }); + + let placeText = document.createTextNode( + place.displayName + ": " + place.formattedAddress, + ); + + results.replaceChildren(placeText); + title.innerText = "Selected Place:"; + input.value = ""; + refreshToken(request); +} + +// Helper function to refresh the session token. +async function refreshToken(request) { + // Create a new session token and add it to the request. + token = new google.maps.places.AutocompleteSessionToken(); + request.sessionToken = token; + return request; +} + +window.init = init; diff --git a/dist/samples/place-autocomplete-data-session/playground/index.html b/dist/samples/place-autocomplete-data-session/playground/index.html new file mode 100644 index 0000000000..891575eb65 --- /dev/null +++ b/dist/samples/place-autocomplete-data-session/playground/index.html @@ -0,0 +1,38 @@ + + + Place Autocomplete Data API Session + + + + + + + + + + +
+ + Powered by Google + + + + + diff --git a/dist/samples/place-autocomplete-data-session/playground/index.ts b/dist/samples/place-autocomplete-data-session/playground/index.ts new file mode 100644 index 0000000000..baa341a713 --- /dev/null +++ b/dist/samples/place-autocomplete-data-session/playground/index.ts @@ -0,0 +1,99 @@ +let title; +let results; +let input; +let token; + +// Add an initial request body. +let request = { + input: "", + locationRestriction: { + west: -122.44, + north: 37.8, + east: -122.39, + south: 37.78, + }, + origin: { lat: 37.7893, lng: -122.4039 }, + includedPrimaryTypes: ["restaurant"], + language: "en-US", + region: "us", +}; + +async function init() { + token = new google.maps.places.AutocompleteSessionToken(); + + title = document.getElementById("title"); + results = document.getElementById("results"); + input = document.querySelector("input"); + input.addEventListener("input", makeAcRequest); + request = refreshToken(request) as any; +} + +async function makeAcRequest(input) { + // Reset elements and exit if an empty string is received. + if (input.target.value == "") { + title.innerText = ""; + results.replaceChildren(); + return; + } + + // Add the latest char sequence to the request. + request.input = input.target.value; + + // Fetch autocomplete suggestions and show them in a list. + // @ts-ignore + const { suggestions } = + await google.maps.places.AutocompleteSuggestion.fetchAutocompleteSuggestions( + request, + ); + + title.innerText = 'Query predictions for "' + request.input + '"'; + + // Clear the list first. + results.replaceChildren(); + + for (const suggestion of suggestions) { + const placePrediction = suggestion.placePrediction; + + // Create a link for the place, add an event handler to fetch the place. + const a = document.createElement("a"); + a.addEventListener("click", () => { + onPlaceSelected(placePrediction!.toPlace()); + }); + a.innerText = placePrediction!.text.toString(); + + // Create a new list element. + const li = document.createElement("li"); + li.appendChild(a); + results.appendChild(li); + } +} + +// Event handler for clicking on a suggested place. +async function onPlaceSelected(place) { + await place.fetchFields({ + fields: ["displayName", "formattedAddress"], + }); + let placeText = document.createTextNode( + place.displayName + ": " + place.formattedAddress, + ); + results.replaceChildren(placeText); + title.innerText = "Selected Place:"; + input.value = ""; + refreshToken(request); +} + +// Helper function to refresh the session token. +async function refreshToken(request) { + // Create a new session token and add it to the request. + token = new google.maps.places.AutocompleteSessionToken(); + request.sessionToken = token; + return request; +} + +declare global { + interface Window { + init: () => void; + } +} +window.init = init; +export {}; diff --git a/dist/samples/place-autocomplete-data-session/playground/package.json b/dist/samples/place-autocomplete-data-session/playground/package.json new file mode 100644 index 0000000000..33703d5822 --- /dev/null +++ b/dist/samples/place-autocomplete-data-session/playground/package.json @@ -0,0 +1,3 @@ +{ + "dependencies": {} +} \ No newline at end of file diff --git a/dist/samples/place-autocomplete-data-session/playground/playground.ts.json b/dist/samples/place-autocomplete-data-session/playground/playground.ts.json new file mode 100644 index 0000000000..dfc32121fc --- /dev/null +++ b/dist/samples/place-autocomplete-data-session/playground/playground.ts.json @@ -0,0 +1,17 @@ +{ + "files": { + "index.ts": { + "label": "TypeScript" + }, + "style.css": { + "label": "CSS" + }, + "index.html": { + "label": "HTML" + }, + "../../../types/google-maps/index.d.ts": { + "label": "@types/google.maps", + "hidden": true + } + } +} \ No newline at end of file diff --git a/dist/samples/place-autocomplete-data-session/playground/style.css b/dist/samples/place-autocomplete-data-session/playground/style.css new file mode 100644 index 0000000000..fe4bb863a4 --- /dev/null +++ b/dist/samples/place-autocomplete-data-session/playground/style.css @@ -0,0 +1,28 @@ +/* + * Always set the map height explicitly to define the size of the div element + * that contains the map. + */ +#map { + height: 100%; +} + +/* + * Optional: Makes the sample page fill the window. + */ +html, +body { + height: 100%; + margin: 0; + padding: 0; +} + +a { + cursor: pointer; + text-decoration: underline; + color: blue; +} + +input { + width: 300px; +} + diff --git a/dist/samples/place-autocomplete-data-simple/app/.env b/dist/samples/place-autocomplete-data-simple/app/.env new file mode 100644 index 0000000000..d7474dcb8b --- /dev/null +++ b/dist/samples/place-autocomplete-data-simple/app/.env @@ -0,0 +1 @@ +VITE_GOOGLE_MAPS_API_KEY=AIzaSyB41DRUbKWJHPxaFjMAwdrzWzbVKartNGg \ No newline at end of file diff --git a/dist/samples/place-autocomplete-data-simple/app/.eslintrc.json b/dist/samples/place-autocomplete-data-simple/app/.eslintrc.json new file mode 100644 index 0000000000..841a372aa2 --- /dev/null +++ b/dist/samples/place-autocomplete-data-simple/app/.eslintrc.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 + } +} \ No newline at end of file diff --git a/dist/samples/place-autocomplete-data-simple/app/.gitignore b/dist/samples/place-autocomplete-data-simple/app/.gitignore new file mode 100644 index 0000000000..10ec766622 --- /dev/null +++ b/dist/samples/place-autocomplete-data-simple/app/.gitignore @@ -0,0 +1,4 @@ + +node_modules +dist +package-lock.json diff --git a/dist/samples/place-autocomplete-data-simple/app/README.md b/dist/samples/place-autocomplete-data-simple/app/README.md new file mode 100644 index 0000000000..012fc1859f --- /dev/null +++ b/dist/samples/place-autocomplete-data-simple/app/README.md @@ -0,0 +1,17 @@ +# Google Maps JavaScript Sample + +This sample is generated from @googlemaps/js-samples located at +https://github.com/googlemaps/js-samples. + +## Setup + +```sh +npm i +npm start # development +npm run build # production +``` + +## Feedback + +For feedback related to this sample, please open a new issue on +[GitHub](https://github.com/googlemaps/js-samples/issues). diff --git a/dist/samples/place-autocomplete-data-simple/app/env.d.ts b/dist/samples/place-autocomplete-data-simple/app/env.d.ts new file mode 100644 index 0000000000..2d29a7a6be --- /dev/null +++ b/dist/samples/place-autocomplete-data-simple/app/env.d.ts @@ -0,0 +1,12 @@ +/// + +/** + * @external https://vitejs.dev/guide/env-and-mode.html + */ +interface ImportMetaEnv { + readonly VITE_GOOGLE_MAPS_API_KEY: string; +} + +interface ImportMeta { + readonly env: ImportMetaEnv; +} diff --git a/dist/samples/place-autocomplete-data-simple/app/index.html b/dist/samples/place-autocomplete-data-simple/app/index.html new file mode 100644 index 0000000000..543f5891eb --- /dev/null +++ b/dist/samples/place-autocomplete-data-simple/app/index.html @@ -0,0 +1,28 @@ + + + + + Place Autocomplete Data API Predictions + + + + + +
+
    +

    + Powered by Google + + + + + diff --git a/dist/samples/place-autocomplete-data-simple/app/index.ts b/dist/samples/place-autocomplete-data-simple/app/index.ts new file mode 100644 index 0000000000..c479d38d5d --- /dev/null +++ b/dist/samples/place-autocomplete-data-simple/app/index.ts @@ -0,0 +1,56 @@ +/** + * @license + * Copyright 2024 Google LLC. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 + */ + +/** + * Demonstrates making a single request for Place predictions, then requests Place Details for the first result. + */ +async function init() { + // @ts-ignore + const { Place, AutocompleteSessionToken, AutocompleteSuggestion } = await google.maps.importLibrary("places") as google.maps.PlacesLibrary; + + // Add an initial request body. + let request = { + input: "Tadi", + locationRestriction: { west: -122.44, north: 37.8, east: -122.39, south: 37.78 }, + origin: { lat: 37.7893, lng: -122.4039 }, + includedPrimaryTypes: ["restaurant"], + language: "en-US", + region: "us", + }; + + // Create a session token. + const token = new AutocompleteSessionToken(); + // Add the token to the request. + // @ts-ignore + request.sessionToken = token; + // Fetch autocomplete suggestions. + const { suggestions } = await AutocompleteSuggestion.fetchAutocompleteSuggestions(request); + + const title = document.getElementById('title') as HTMLElement; + title.appendChild(document.createTextNode('Query predictions for "' + request.input + '":')); + + for (let suggestion of suggestions) { + const placePrediction = suggestion.placePrediction; + + // Create a new list element. + const listItem = document.createElement('li'); + const resultsElement = document.getElementById("results") as HTMLElement; + listItem.appendChild(document.createTextNode(placePrediction.text.toString())); + resultsElement.appendChild(listItem); + } + + let place = suggestions[0].placePrediction.toPlace(); // Get first predicted place. + await place.fetchFields({ + fields: ['displayName', 'formattedAddress'], + }); + + const placeInfo = document.getElementById("prediction") as HTMLElement; + placeInfo.textContent = 'First predicted place: ' + place.displayName + ': ' + place.formattedAddress; + +} + +init(); +export { }; diff --git a/dist/samples/place-autocomplete-data-simple/app/package.json b/dist/samples/place-autocomplete-data-simple/app/package.json new file mode 100644 index 0000000000..683cc14d0a --- /dev/null +++ b/dist/samples/place-autocomplete-data-simple/app/package.json @@ -0,0 +1,35 @@ +{ + "name": "place-autocomplete-data-simple", + "description": "Samples for Google Maps JavaScript", + "version": "2.1.4", + "keywords": [ + "google", + "javascript", + "maps", + "samples" + ], + "homepage": "https://github.com/googlemaps/js-samples#readme", + "bugs": { + "url": "https://github.com/googlemaps/js-samples/issues" + }, + "repository": { + "type": "git", + "url": "git+https://github.com/googlemaps/js-samples.git" + }, + "files": [], + "license": "Apache-2.0", + "scripts": { + "dev": "vite", + "start": "vite", + "build": "vite build --outDir dist --base './'", + "test": "tsc --no-emit", + "preview": "vite preview" + }, + "devDependencies": { + "@types/google.maps": "^3.53.5", + "typescript": "^5.5.3", + "vite": "^5.4.6" + }, + "private": true, + "dependencies": {} +} \ No newline at end of file diff --git a/dist/samples/place-autocomplete-data-simple/app/style.css b/dist/samples/place-autocomplete-data-simple/app/style.css new file mode 100644 index 0000000000..c97e14e569 --- /dev/null +++ b/dist/samples/place-autocomplete-data-simple/app/style.css @@ -0,0 +1,23 @@ +/** + * @license + * Copyright 2019 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. + */ +#map { + height: 100%; +} + +/* + * Optional: Makes the sample page fill the window. + */ +html, +body { + height: 100%; + margin: 0; + padding: 0; +} + diff --git a/dist/samples/place-autocomplete-data-simple/app/tsconfig.json b/dist/samples/place-autocomplete-data-simple/app/tsconfig.json new file mode 100644 index 0000000000..b405998dad --- /dev/null +++ b/dist/samples/place-autocomplete-data-simple/app/tsconfig.json @@ -0,0 +1,16 @@ +{ + "compilerOptions": { + "module": "esnext", + "target": "esnext", + "strict": true, + "noImplicitAny": false, + "lib": [ + "esnext", + "es6", + "dom", + "dom.iterable" + ], + "moduleResolution": "Node", + "jsx": "preserve" + } +} \ No newline at end of file diff --git a/dist/samples/place-autocomplete-data-simple/app/vite.config.js b/dist/samples/place-autocomplete-data-simple/app/vite.config.js new file mode 100644 index 0000000000..d49e45cd7e --- /dev/null +++ b/dist/samples/place-autocomplete-data-simple/app/vite.config.js @@ -0,0 +1,11 @@ +import { defineConfig } from "vite"; + +// https://vitejs.dev/config/ +export default defineConfig({ + server: { + hmr: + process.env.CODESANDBOX_SSE || process.env.GITPOD_WORKSPACE_ID + ? 443 + : undefined, + }, +}); diff --git a/dist/samples/place-autocomplete-data-simple/docs/index.html b/dist/samples/place-autocomplete-data-simple/docs/index.html new file mode 100644 index 0000000000..4ef2f47f63 --- /dev/null +++ b/dist/samples/place-autocomplete-data-simple/docs/index.html @@ -0,0 +1,32 @@ + + + + + + Place Autocomplete Data API Predictions + + + + + + +
    +
      +

      + Powered by Google + + + + + + + diff --git a/dist/samples/place-autocomplete-data-simple/docs/index.js b/dist/samples/place-autocomplete-data-simple/docs/index.js new file mode 100644 index 0000000000..1851a7d6a3 --- /dev/null +++ b/dist/samples/place-autocomplete-data-simple/docs/index.js @@ -0,0 +1,84 @@ +/** + * @license + * Copyright 2024 Google LLC. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 + */ +// [START maps_place_autocomplete_data_simple] +/** + * Demonstrates making a single request for Place predictions, then requests Place Details for the first result. + */ +async function init() { + // @ts-ignore + const { Place, AutocompleteSessionToken, AutocompleteSuggestion } = + await google.maps.importLibrary("places"); + // [START maps_place_autocomplete_data_simple_request] + // Add an initial request body. + // [START maps_place_autocomplete_data_simple_request_body] + let request = { + input: "Tadi", + locationRestriction: { + west: -122.44, + north: 37.8, + east: -122.39, + south: 37.78, + }, + origin: { lat: 37.7893, lng: -122.4039 }, + includedPrimaryTypes: ["restaurant"], + language: "en-US", + region: "us", + }; + // [END maps_place_autocomplete_data_simple_request_body] + // [START maps_place_autocomplete_data_simple_token] + // Create a session token. + const token = new AutocompleteSessionToken(); + + // Add the token to the request. + // @ts-ignore + request.sessionToken = token; + + // [END maps_place_autocomplete_data_simple_token] + // [END maps_place_autocomplete_data_simple_request] + // [START maps_place_autocomplete_data_simple_get_suggestions] + // Fetch autocomplete suggestions. + const { suggestions } = + await AutocompleteSuggestion.fetchAutocompleteSuggestions(request); + const title = document.getElementById("title"); + + title.appendChild( + document.createTextNode('Query predictions for "' + request.input + '":'), + ); + + for (let suggestion of suggestions) { + const placePrediction = suggestion.placePrediction; + // Create a new list element. + const listItem = document.createElement("li"); + const resultsElement = document.getElementById("results"); + + listItem.appendChild( + document.createTextNode(placePrediction.text.toString()), + ); + resultsElement.appendChild(listItem); + } + + // [END maps_place_autocomplete_data_simple_get_suggestions] + // [START maps_place_autocomplete_data_simple_prediction] + let place = suggestions[0].placePrediction.toPlace(); // Get first predicted place. + + // [START maps_place_autocomplete_data_simple_fetch] + await place.fetchFields({ + fields: ["displayName", "formattedAddress"], + }); + + // [END maps_place_autocomplete_data_simple_fetch] + const placeInfo = document.getElementById("prediction"); + + placeInfo.textContent = + "First predicted place: " + + place.displayName + + ": " + + place.formattedAddress; + // [END maps_place_autocomplete_data_simple_prediction] +} + +init(); +// [END maps_place_autocomplete_data_simple] diff --git a/dist/samples/place-autocomplete-data-simple/docs/style.css b/dist/samples/place-autocomplete-data-simple/docs/style.css new file mode 100644 index 0000000000..a4ee062627 --- /dev/null +++ b/dist/samples/place-autocomplete-data-simple/docs/style.css @@ -0,0 +1,25 @@ +/** + * @license + * Copyright 2019 Google LLC. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 + */ +/* [START maps_place_autocomplete_data_simple] */ +/* + * Always set the map height explicitly to define the size of the div element + * that contains the map. + */ +#map { + height: 100%; +} + +/* + * Optional: Makes the sample page fill the window. + */ +html, +body { + height: 100%; + margin: 0; + padding: 0; +} + +/* [END maps_place_autocomplete_data_simple] */ \ No newline at end of file diff --git a/dist/samples/place-autocomplete-data-simple/iframe/index.html b/dist/samples/place-autocomplete-data-simple/iframe/index.html new file mode 100644 index 0000000000..832c4f38a5 --- /dev/null +++ b/dist/samples/place-autocomplete-data-simple/iframe/index.html @@ -0,0 +1,28 @@ + + + + + Place Autocomplete Data API Predictions + + + + + +
      +
        +

        + Powered by Google + + + + + diff --git a/dist/samples/place-autocomplete-data-simple/jsfiddle/demo.css b/dist/samples/place-autocomplete-data-simple/jsfiddle/demo.css new file mode 100644 index 0000000000..c97e14e569 --- /dev/null +++ b/dist/samples/place-autocomplete-data-simple/jsfiddle/demo.css @@ -0,0 +1,23 @@ +/** + * @license + * Copyright 2019 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. + */ +#map { + height: 100%; +} + +/* + * Optional: Makes the sample page fill the window. + */ +html, +body { + height: 100%; + margin: 0; + padding: 0; +} + diff --git a/dist/samples/place-autocomplete-data-simple/jsfiddle/demo.details b/dist/samples/place-autocomplete-data-simple/jsfiddle/demo.details new file mode 100644 index 0000000000..f7ab25979e --- /dev/null +++ b/dist/samples/place-autocomplete-data-simple/jsfiddle/demo.details @@ -0,0 +1,7 @@ +name: Place Autocomplete Data API Predictions +authors: + - Justin Poehnelt +tags: + - google maps +load_type: h +description: Sample code for Google Maps Platform JavaScript API diff --git a/dist/samples/place-autocomplete-data-simple/jsfiddle/demo.html b/dist/samples/place-autocomplete-data-simple/jsfiddle/demo.html new file mode 100644 index 0000000000..888101865a --- /dev/null +++ b/dist/samples/place-autocomplete-data-simple/jsfiddle/demo.html @@ -0,0 +1,27 @@ + + + + + Place Autocomplete Data API Predictions + + + + +
        +
          +

          + Powered by Google + + + + + diff --git a/dist/samples/place-autocomplete-data-simple/jsfiddle/demo.js b/dist/samples/place-autocomplete-data-simple/jsfiddle/demo.js new file mode 100644 index 0000000000..5c734a26b9 --- /dev/null +++ b/dist/samples/place-autocomplete-data-simple/jsfiddle/demo.js @@ -0,0 +1,70 @@ +/** + * @license + * Copyright 2024 Google LLC. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 + */ +/** + * Demonstrates making a single request for Place predictions, then requests Place Details for the first result. + */ +async function init() { + // @ts-ignore + const { Place, AutocompleteSessionToken, AutocompleteSuggestion } = + await google.maps.importLibrary("places"); + // Add an initial request body. + let request = { + input: "Tadi", + locationRestriction: { + west: -122.44, + north: 37.8, + east: -122.39, + south: 37.78, + }, + origin: { lat: 37.7893, lng: -122.4039 }, + includedPrimaryTypes: ["restaurant"], + language: "en-US", + region: "us", + }; + // Create a session token. + const token = new AutocompleteSessionToken(); + + // Add the token to the request. + // @ts-ignore + request.sessionToken = token; + + // Fetch autocomplete suggestions. + const { suggestions } = + await AutocompleteSuggestion.fetchAutocompleteSuggestions(request); + const title = document.getElementById("title"); + + title.appendChild( + document.createTextNode('Query predictions for "' + request.input + '":'), + ); + + for (let suggestion of suggestions) { + const placePrediction = suggestion.placePrediction; + // Create a new list element. + const listItem = document.createElement("li"); + const resultsElement = document.getElementById("results"); + + listItem.appendChild( + document.createTextNode(placePrediction.text.toString()), + ); + resultsElement.appendChild(listItem); + } + + let place = suggestions[0].placePrediction.toPlace(); // Get first predicted place. + + await place.fetchFields({ + fields: ["displayName", "formattedAddress"], + }); + + const placeInfo = document.getElementById("prediction"); + + placeInfo.textContent = + "First predicted place: " + + place.displayName + + ": " + + place.formattedAddress; +} + +init(); diff --git a/dist/samples/place-autocomplete-data-simple/playground/index.html b/dist/samples/place-autocomplete-data-simple/playground/index.html new file mode 100644 index 0000000000..95529381a3 --- /dev/null +++ b/dist/samples/place-autocomplete-data-simple/playground/index.html @@ -0,0 +1,30 @@ + + + Place Autocomplete Data API Predictions + + + + + + + + + +
          +
            +

            + Powered by Google + + + + + diff --git a/dist/samples/place-autocomplete-data-simple/playground/index.ts b/dist/samples/place-autocomplete-data-simple/playground/index.ts new file mode 100644 index 0000000000..87236cd8dc --- /dev/null +++ b/dist/samples/place-autocomplete-data-simple/playground/index.ts @@ -0,0 +1,64 @@ +/** + * Demonstrates making a single request for Place predictions, then requests Place Details for the first result. + */ +async function init() { + // @ts-ignore + const { Place, AutocompleteSessionToken, AutocompleteSuggestion } = + (await google.maps.importLibrary("places")) as google.maps.PlacesLibrary; + + // Add an initial request body. + let request = { + input: "Tadi", + locationRestriction: { + west: -122.44, + north: 37.8, + east: -122.39, + south: 37.78, + }, + origin: { lat: 37.7893, lng: -122.4039 }, + includedPrimaryTypes: ["restaurant"], + language: "en-US", + region: "us", + }; + + // Create a session token. + const token = new AutocompleteSessionToken(); + // Add the token to the request. + // @ts-ignore + request.sessionToken = token; + // Fetch autocomplete suggestions. + const { suggestions } = + await AutocompleteSuggestion.fetchAutocompleteSuggestions(request); + + const title = document.getElementById("title") as HTMLElement; + title.appendChild( + document.createTextNode('Query predictions for "' + request.input + '":'), + ); + + for (let suggestion of suggestions) { + const placePrediction = suggestion.placePrediction; + + // Create a new list element. + const listItem = document.createElement("li"); + const resultsElement = document.getElementById("results") as HTMLElement; + listItem.appendChild( + document.createTextNode(placePrediction.text.toString()), + ); + resultsElement.appendChild(listItem); + } + + let place = suggestions[0].placePrediction.toPlace(); // Get first predicted place. + await place.fetchFields({ + fields: ["displayName", "formattedAddress"], + }); + + const placeInfo = document.getElementById("prediction") as HTMLElement; + placeInfo.textContent = + "First predicted place: " + + place.displayName + + ": " + + place.formattedAddress; +} + +init(); +export {}; diff --git a/dist/samples/place-autocomplete-data-simple/playground/package.json b/dist/samples/place-autocomplete-data-simple/playground/package.json new file mode 100644 index 0000000000..33703d5822 --- /dev/null +++ b/dist/samples/place-autocomplete-data-simple/playground/package.json @@ -0,0 +1,3 @@ +{ + "dependencies": {} +} \ No newline at end of file diff --git a/dist/samples/place-autocomplete-data-simple/playground/playground.ts.json b/dist/samples/place-autocomplete-data-simple/playground/playground.ts.json new file mode 100644 index 0000000000..dfc32121fc --- /dev/null +++ b/dist/samples/place-autocomplete-data-simple/playground/playground.ts.json @@ -0,0 +1,17 @@ +{ + "files": { + "index.ts": { + "label": "TypeScript" + }, + "style.css": { + "label": "CSS" + }, + "index.html": { + "label": "HTML" + }, + "../../../types/google-maps/index.d.ts": { + "label": "@types/google.maps", + "hidden": true + } + } +} \ No newline at end of file diff --git a/dist/samples/place-autocomplete-data-simple/playground/style.css b/dist/samples/place-autocomplete-data-simple/playground/style.css new file mode 100644 index 0000000000..a8d59c808e --- /dev/null +++ b/dist/samples/place-autocomplete-data-simple/playground/style.css @@ -0,0 +1,18 @@ +/* + * Always set the map height explicitly to define the size of the div element + * that contains the map. + */ +#map { + height: 100%; +} + +/* + * Optional: Makes the sample page fill the window. + */ +html, +body { + height: 100%; + margin: 0; + padding: 0; +} + diff --git a/dist/samples/place-autocomplete-element/app/index.html b/dist/samples/place-autocomplete-element/app/index.html index 7ff8e85a04..7e9bea96eb 100644 --- a/dist/samples/place-autocomplete-element/app/index.html +++ b/dist/samples/place-autocomplete-element/app/index.html @@ -7,7 +7,6 @@ Place Autocomplete element - diff --git a/dist/samples/place-autocomplete-element/app/index.ts b/dist/samples/place-autocomplete-element/app/index.ts index 9ebc446650..24d79c5d0a 100644 --- a/dist/samples/place-autocomplete-element/app/index.ts +++ b/dist/samples/place-autocomplete-element/app/index.ts @@ -7,9 +7,7 @@ async function initMap(): Promise { // Request needed libraries. //@ts-ignore - const [{ Map }] = await Promise.all([ - google.maps.importLibrary("places"), - ]); + await google.maps.importLibrary("places") as google.maps.PlacesLibrary; // Create the input HTML element, and append it. //@ts-ignore const placeAutocomplete = new google.maps.places.PlaceAutocompleteElement(); diff --git a/dist/samples/place-autocomplete-element/app/package.json b/dist/samples/place-autocomplete-element/app/package.json index 7ff4a1b83a..5e36cf283f 100644 --- a/dist/samples/place-autocomplete-element/app/package.json +++ b/dist/samples/place-autocomplete-element/app/package.json @@ -27,8 +27,8 @@ }, "devDependencies": { "@types/google.maps": "^3.53.5", - "typescript": "^5.2.2", - "vite": "^5.0.13" + "typescript": "^5.5.3", + "vite": "^5.4.6" }, "private": true, "dependencies": {} diff --git a/dist/samples/place-autocomplete-element/docs/index.html b/dist/samples/place-autocomplete-element/docs/index.html index 6769c960bf..6fbea7bc5d 100644 --- a/dist/samples/place-autocomplete-element/docs/index.html +++ b/dist/samples/place-autocomplete-element/docs/index.html @@ -8,7 +8,6 @@ Place Autocomplete element - diff --git a/dist/samples/place-autocomplete-element/docs/index.js b/dist/samples/place-autocomplete-element/docs/index.js index 38cc48eb55..07215ae358 100644 --- a/dist/samples/place-autocomplete-element/docs/index.js +++ b/dist/samples/place-autocomplete-element/docs/index.js @@ -8,7 +8,8 @@ async function initMap() { // [START maps_place_autocomplete_element_add] // Request needed libraries. //@ts-ignore - const [{ Map }] = await Promise.all([google.maps.importLibrary("places")]); + await google.maps.importLibrary("places"); + // Create the input HTML element, and append it. //@ts-ignore const placeAutocomplete = new google.maps.places.PlaceAutocompleteElement(); diff --git a/dist/samples/place-autocomplete-element/iframe/index.html b/dist/samples/place-autocomplete-element/iframe/index.html index a55441e436..252cc9b50b 100644 --- a/dist/samples/place-autocomplete-element/iframe/index.html +++ b/dist/samples/place-autocomplete-element/iframe/index.html @@ -7,10 +7,9 @@ Place Autocomplete element - - - + +

            Search for a place here:

            diff --git a/dist/samples/place-autocomplete-element/jsfiddle/demo.html b/dist/samples/place-autocomplete-element/jsfiddle/demo.html index c9a4121800..8ad57bb2ba 100644 --- a/dist/samples/place-autocomplete-element/jsfiddle/demo.html +++ b/dist/samples/place-autocomplete-element/jsfiddle/demo.html @@ -7,7 +7,7 @@ Place Autocomplete element - + diff --git a/dist/samples/place-autocomplete-element/jsfiddle/demo.js b/dist/samples/place-autocomplete-element/jsfiddle/demo.js index 5537a6333c..c12ca349a0 100644 --- a/dist/samples/place-autocomplete-element/jsfiddle/demo.js +++ b/dist/samples/place-autocomplete-element/jsfiddle/demo.js @@ -6,7 +6,8 @@ async function initMap() { // Request needed libraries. //@ts-ignore - const [{ Map }] = await Promise.all([google.maps.importLibrary("places")]); + await google.maps.importLibrary("places"); + // Create the input HTML element, and append it. //@ts-ignore const placeAutocomplete = new google.maps.places.PlaceAutocompleteElement(); diff --git a/dist/samples/place-autocomplete-element/playground/index.html b/dist/samples/place-autocomplete-element/playground/index.html index dccbfee61c..3e309599e9 100644 --- a/dist/samples/place-autocomplete-element/playground/index.html +++ b/dist/samples/place-autocomplete-element/playground/index.html @@ -1,7 +1,7 @@ Place Autocomplete element - + diff --git a/dist/samples/place-autocomplete-map/app/package.json b/dist/samples/place-autocomplete-map/app/package.json index a683207f8a..43a3162721 100644 --- a/dist/samples/place-autocomplete-map/app/package.json +++ b/dist/samples/place-autocomplete-map/app/package.json @@ -27,8 +27,8 @@ }, "devDependencies": { "@types/google.maps": "^3.53.5", - "typescript": "^5.2.2", - "vite": "^5.0.13" + "typescript": "^5.5.3", + "vite": "^5.4.6" }, "private": true, "dependencies": {} diff --git a/dist/samples/place-autocomplete-map/docs/index.html b/dist/samples/place-autocomplete-map/docs/index.html index 0059e58e76..80dd8f090c 100644 --- a/dist/samples/place-autocomplete-map/docs/index.html +++ b/dist/samples/place-autocomplete-map/docs/index.html @@ -8,7 +8,6 @@ Place Autocomplete map - diff --git a/dist/samples/place-autocomplete-map/iframe/index.html b/dist/samples/place-autocomplete-map/iframe/index.html index b3c8b2e198..ee83656d86 100644 --- a/dist/samples/place-autocomplete-map/iframe/index.html +++ b/dist/samples/place-autocomplete-map/iframe/index.html @@ -7,10 +7,9 @@ Place Autocomplete map - - - + +
            diff --git a/dist/samples/place-autocomplete-map/jsfiddle/demo.html b/dist/samples/place-autocomplete-map/jsfiddle/demo.html index fcff856969..0160efdd51 100644 --- a/dist/samples/place-autocomplete-map/jsfiddle/demo.html +++ b/dist/samples/place-autocomplete-map/jsfiddle/demo.html @@ -7,7 +7,7 @@ Place Autocomplete map - + diff --git a/dist/samples/place-autocomplete-map/playground/index.html b/dist/samples/place-autocomplete-map/playground/index.html index a9d398d35e..1342f5752c 100644 --- a/dist/samples/place-autocomplete-map/playground/index.html +++ b/dist/samples/place-autocomplete-map/playground/index.html @@ -1,7 +1,7 @@ Place Autocomplete map - + diff --git a/dist/samples/place-class/app/index.ts b/dist/samples/place-class/app/index.ts index cf0d81df65..acdfff5aa4 100644 --- a/dist/samples/place-class/app/index.ts +++ b/dist/samples/place-class/app/index.ts @@ -9,7 +9,6 @@ let centerCoordinates = { lat: 37.4161493, lng: -122.0812166 }; async function initMap() { const { Map } = await google.maps.importLibrary("maps") as google.maps.MapsLibrary; - const { Place } = await google.maps.importLibrary("places") as google.maps.PlacesLibrary; map = new Map(document.getElementById('map') as HTMLElement, { center: centerCoordinates, @@ -19,10 +18,11 @@ async function initMap() { // [END_EXCLUDE] }); - getPlaceDetails(Place); + getPlaceDetails(); } -async function getPlaceDetails(Place) { +async function getPlaceDetails() { + const { Place } = await google.maps.importLibrary("places") as google.maps.PlacesLibrary; const { AdvancedMarkerElement } = await google.maps.importLibrary("marker") as google.maps.MarkerLibrary; // Use place ID to create a new Place instance. const place = new Place({ @@ -46,4 +46,4 @@ async function getPlaceDetails(Place) { } initMap(); -export { }; \ No newline at end of file +export { }; diff --git a/dist/samples/place-class/app/package.json b/dist/samples/place-class/app/package.json index 3f75d7e5c8..6df633f37d 100644 --- a/dist/samples/place-class/app/package.json +++ b/dist/samples/place-class/app/package.json @@ -27,8 +27,8 @@ }, "devDependencies": { "@types/google.maps": "^3.53.5", - "typescript": "^5.2.2", - "vite": "^5.0.13" + "typescript": "^5.5.3", + "vite": "^5.4.6" }, "private": true, "dependencies": {} diff --git a/dist/samples/place-class/docs/index.html b/dist/samples/place-class/docs/index.html index ce5f2230c5..ac0b7d96a6 100644 --- a/dist/samples/place-class/docs/index.html +++ b/dist/samples/place-class/docs/index.html @@ -8,7 +8,6 @@ Place Class - diff --git a/dist/samples/place-class/docs/index.js b/dist/samples/place-class/docs/index.js index d549d55a67..0750cd0feb 100644 --- a/dist/samples/place-class/docs/index.js +++ b/dist/samples/place-class/docs/index.js @@ -9,7 +9,6 @@ let centerCoordinates = { lat: 37.4161493, lng: -122.0812166 }; async function initMap() { const { Map } = await google.maps.importLibrary("maps"); - const { Place } = await google.maps.importLibrary("places"); map = new Map(document.getElementById("map"), { center: centerCoordinates, @@ -18,11 +17,12 @@ async function initMap() { mapId: "4504f8b37365c3d0", // [END_EXCLUDE] }); - getPlaceDetails(Place); + getPlaceDetails(); } // [START maps_place_class_fetchfields] -async function getPlaceDetails(Place) { +async function getPlaceDetails() { + const { Place } = await google.maps.importLibrary("places"); const { AdvancedMarkerElement } = await google.maps.importLibrary("marker"); // Use place ID to create a new Place instance. const place = new Place({ diff --git a/dist/samples/place-class/iframe/index.html b/dist/samples/place-class/iframe/index.html index e419742cfe..b01e764dae 100644 --- a/dist/samples/place-class/iframe/index.html +++ b/dist/samples/place-class/iframe/index.html @@ -7,10 +7,9 @@ Place Class - - - + +
            diff --git a/dist/samples/place-class/jsfiddle/demo.html b/dist/samples/place-class/jsfiddle/demo.html index f8cdd2fb53..a371a594b8 100644 --- a/dist/samples/place-class/jsfiddle/demo.html +++ b/dist/samples/place-class/jsfiddle/demo.html @@ -7,7 +7,7 @@ Place Class - + diff --git a/dist/samples/place-class/jsfiddle/demo.js b/dist/samples/place-class/jsfiddle/demo.js index 66ec4e9218..c3b3fb4433 100644 --- a/dist/samples/place-class/jsfiddle/demo.js +++ b/dist/samples/place-class/jsfiddle/demo.js @@ -8,7 +8,6 @@ let centerCoordinates = { lat: 37.4161493, lng: -122.0812166 }; async function initMap() { const { Map } = await google.maps.importLibrary("maps"); - const { Place } = await google.maps.importLibrary("places"); map = new Map(document.getElementById("map"), { center: centerCoordinates, @@ -17,10 +16,11 @@ async function initMap() { mapId: "4504f8b37365c3d0", // [END_EXCLUDE] }); - getPlaceDetails(Place); + getPlaceDetails(); } -async function getPlaceDetails(Place) { +async function getPlaceDetails() { + const { Place } = await google.maps.importLibrary("places"); const { AdvancedMarkerElement } = await google.maps.importLibrary("marker"); // Use place ID to create a new Place instance. const place = new Place({ diff --git a/dist/samples/place-class/playground/index.html b/dist/samples/place-class/playground/index.html index 863c93110b..f4f8643f6b 100644 --- a/dist/samples/place-class/playground/index.html +++ b/dist/samples/place-class/playground/index.html @@ -1,7 +1,7 @@ Place Class - + @@ -16,10 +15,10 @@
            @@ -17,10 +16,10 @@
            - - + +
            +
            + diff --git a/dist/samples/place-nearby-search/app/package.json b/dist/samples/place-nearby-search/app/package.json index a5f6f261d6..ed4ac267ee 100644 --- a/dist/samples/place-nearby-search/app/package.json +++ b/dist/samples/place-nearby-search/app/package.json @@ -27,8 +27,8 @@ }, "devDependencies": { "@types/google.maps": "^3.53.5", - "typescript": "^5.2.2", - "vite": "^5.0.13" + "typescript": "^5.5.3", + "vite": "^5.4.6" }, "private": true, "dependencies": {} diff --git a/dist/samples/place-nearby-search/docs/index.html b/dist/samples/place-nearby-search/docs/index.html index 2200deba02..e9b0e442b8 100644 --- a/dist/samples/place-nearby-search/docs/index.html +++ b/dist/samples/place-nearby-search/docs/index.html @@ -8,7 +8,6 @@ Nearby Search - diff --git a/dist/samples/place-nearby-search/iframe/index.html b/dist/samples/place-nearby-search/iframe/index.html index 135be38b63..8277068f08 100644 --- a/dist/samples/place-nearby-search/iframe/index.html +++ b/dist/samples/place-nearby-search/iframe/index.html @@ -7,10 +7,9 @@ Nearby Search - - - + +
            diff --git a/dist/samples/place-nearby-search/jsfiddle/demo.html b/dist/samples/place-nearby-search/jsfiddle/demo.html index 19fb0de54b..e1dc6aa6a7 100644 --- a/dist/samples/place-nearby-search/jsfiddle/demo.html +++ b/dist/samples/place-nearby-search/jsfiddle/demo.html @@ -7,7 +7,7 @@ Nearby Search - + diff --git a/dist/samples/place-nearby-search/playground/index.html b/dist/samples/place-nearby-search/playground/index.html index 17d06c51af..a5d567eeee 100644 --- a/dist/samples/place-nearby-search/playground/index.html +++ b/dist/samples/place-nearby-search/playground/index.html @@ -1,7 +1,7 @@ Nearby Search - + + + +
            +
            +
            +
            +
            +
            + +
            +
            +
            + + + + + diff --git a/dist/samples/place-photos/app/index.ts b/dist/samples/place-photos/app/index.ts new file mode 100644 index 0000000000..d8f30ffa05 --- /dev/null +++ b/dist/samples/place-photos/app/index.ts @@ -0,0 +1,66 @@ +/** + * @license + * Copyright 2024 Google LLC. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 + */ + +async function init() { + const { Place } = await google.maps.importLibrary('places') as google.maps.PlacesLibrary; + + // Use a place ID to create a new Place instance. + const place = new Place({ + id: 'ChIJydSuSkkUkFQRsqhB-cEtYnw', // Woodland Park Zoo, Seattle WA + }); + + // Call fetchFields, passing the desired data fields. + await place.fetchFields({ fields: ['displayName', 'photos', 'editorialSummary'] }); + + // Get the various HTML elements. + let heading = document.getElementById('heading') as HTMLElement; + let summary = document.getElementById('summary') as HTMLElement; + let gallery = document.getElementById('gallery') as HTMLElement; + let expandedImageDiv = document.getElementById('expanded-image') as HTMLElement; + let attributionLabel; + + // Show the display name and summary for the place. + heading.textContent = place.displayName as string; + summary.textContent = place.editorialSummary as string; + + // Add photos to the gallery. + if (place.photos) { + place.photos?.forEach((photo) => { + const img = document.createElement('img'); + const expandedImage = document.createElement('img'); + img.src = photo.getURI({maxHeight: 380}); + img.addEventListener('click', (event) => { + event.preventDefault(); + expandedImage.src = img.src; + expandedImageDiv.innerHTML = ''; + expandedImageDiv.appendChild(expandedImage); + attributionLabel = createAttribution(photo.authorAttributions); + expandedImageDiv.appendChild(attributionLabel); + }); + + gallery.appendChild(img); + }); + } + + // Display the first photo. + const img = document.createElement('img'); + img.src = place.photos![0].getURI(); + expandedImageDiv.appendChild(img); + attributionLabel = createAttribution(place.photos![0].authorAttributions); + expandedImageDiv.appendChild(attributionLabel); + + // Helper function to create attribution DIV. + function createAttribution(attribution) { + attributionLabel = document.createElement("a"); + attributionLabel.classList.add('attribution-label'); + attributionLabel.textContent = attribution[0].displayName; + attributionLabel.href = attribution[0].uri; + attributionLabel.target = '_blank;' + return attributionLabel; + } +} + +init(); diff --git a/dist/samples/place-photos/app/package.json b/dist/samples/place-photos/app/package.json new file mode 100644 index 0000000000..f025756b15 --- /dev/null +++ b/dist/samples/place-photos/app/package.json @@ -0,0 +1,35 @@ +{ + "name": "place-photos", + "description": "Samples for Google Maps JavaScript", + "version": "2.1.4", + "keywords": [ + "google", + "javascript", + "maps", + "samples" + ], + "homepage": "https://github.com/googlemaps/js-samples#readme", + "bugs": { + "url": "https://github.com/googlemaps/js-samples/issues" + }, + "repository": { + "type": "git", + "url": "git+https://github.com/googlemaps/js-samples.git" + }, + "files": [], + "license": "Apache-2.0", + "scripts": { + "dev": "vite", + "start": "vite", + "build": "vite build --outDir dist --base './'", + "test": "tsc --no-emit", + "preview": "vite preview" + }, + "devDependencies": { + "@types/google.maps": "^3.53.5", + "typescript": "^5.5.3", + "vite": "^5.4.6" + }, + "private": true, + "dependencies": {} +} \ No newline at end of file diff --git a/dist/samples/place-photos/app/style.css b/dist/samples/place-photos/app/style.css new file mode 100644 index 0000000000..5d01c6f576 --- /dev/null +++ b/dist/samples/place-photos/app/style.css @@ -0,0 +1,92 @@ +/** + * @license + * Copyright 2019 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. + */ +#map { + height: 100%; +} + +/* + * Optional: Makes the sample page fill the window. + */ +html, +body { + height: 100%; + margin: 0; + padding: 0; +} + +#container { + display: flex; + padding: 10px; + width: 100%; + height: 100%; + box-sizing: border-box; +} + +.place-overview { + width: 400px; + height: 380px; + overflow-x: auto; + position: relative; + margin-right: 20px; +} + +#info { + font-family: sans-serif; + position: sticky; + position: -webkit-sticky; + left: 0; + padding-bottom: 10px; +} + +#heading { + width: 500px; + font-size: x-large; + margin-bottom: 20px; +} + +#summary { + width: 500px; +} + +#gallery { + display: flex; +} + +#gallery img { + width: 200px; + height: 200px; + margin-right: 10px; + margin-top: 40px; + border-radius: 10px; + cursor: pointer; +} + +#expanded-image { + display: flex; + height: 380px; + overflow: hidden; + background-color: #000; +} + +#expanded-image img { + width: 100%; + height: auto; + object-fit: contain; +} + +.attribution-label { + background-color: #fff; + opacity: 0.7; + font-size: 10px; + font-family: sans-serif; + margin: 2px; + position: absolute; +} + diff --git a/dist/samples/place-photos/app/tsconfig.json b/dist/samples/place-photos/app/tsconfig.json new file mode 100644 index 0000000000..b405998dad --- /dev/null +++ b/dist/samples/place-photos/app/tsconfig.json @@ -0,0 +1,16 @@ +{ + "compilerOptions": { + "module": "esnext", + "target": "esnext", + "strict": true, + "noImplicitAny": false, + "lib": [ + "esnext", + "es6", + "dom", + "dom.iterable" + ], + "moduleResolution": "Node", + "jsx": "preserve" + } +} \ No newline at end of file diff --git a/dist/samples/place-photos/app/vite.config.js b/dist/samples/place-photos/app/vite.config.js new file mode 100644 index 0000000000..d49e45cd7e --- /dev/null +++ b/dist/samples/place-photos/app/vite.config.js @@ -0,0 +1,11 @@ +import { defineConfig } from "vite"; + +// https://vitejs.dev/config/ +export default defineConfig({ + server: { + hmr: + process.env.CODESANDBOX_SSE || process.env.GITPOD_WORKSPACE_ID + ? 443 + : undefined, + }, +}); diff --git a/dist/samples/place-photos/docs/index.html b/dist/samples/place-photos/docs/index.html new file mode 100644 index 0000000000..2fae3ea107 --- /dev/null +++ b/dist/samples/place-photos/docs/index.html @@ -0,0 +1,32 @@ + + + + + + Place Photos + + + + + +
            +
            +
            +
            +
            +
            + +
            +
            +
            + + + + + + diff --git a/dist/samples/place-photos/docs/index.js b/dist/samples/place-photos/docs/index.js new file mode 100644 index 0000000000..571ac43fb5 --- /dev/null +++ b/dist/samples/place-photos/docs/index.js @@ -0,0 +1,70 @@ +"use strict"; + +/** + * @license + * Copyright 2024 Google LLC. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 + */ +// [START maps_place_photos] +async function init() { + const { Place } = await google.maps.importLibrary("places"); + // Use a place ID to create a new Place instance. + const place = new Place({ + id: "ChIJydSuSkkUkFQRsqhB-cEtYnw", // Woodland Park Zoo, Seattle WA + }); + + // Call fetchFields, passing the desired data fields. + await place.fetchFields({ + fields: ["displayName", "photos", "editorialSummary"], + }); + + // Get the various HTML elements. + let heading = document.getElementById("heading"); + let summary = document.getElementById("summary"); + let gallery = document.getElementById("gallery"); + let expandedImageDiv = document.getElementById("expanded-image"); + let attributionLabel; + + // Show the display name and summary for the place. + heading.textContent = place.displayName; + summary.textContent = place.editorialSummary; + // Add photos to the gallery. + if (place.photos) { + place.photos?.forEach((photo) => { + const img = document.createElement("img"); + const expandedImage = document.createElement("img"); + + img.src = photo.getURI({ maxHeight: 380 }); + img.addEventListener("click", (event) => { + event.preventDefault(); + expandedImage.src = img.src; + expandedImageDiv.innerHTML = ""; + expandedImageDiv.appendChild(expandedImage); + attributionLabel = createAttribution(photo.authorAttributions); + expandedImageDiv.appendChild(attributionLabel); + }); + gallery.appendChild(img); + }); + } + + // Display the first photo. + const img = document.createElement("img"); + + img.src = place.photos[0].getURI(); + expandedImageDiv.appendChild(img); + attributionLabel = createAttribution(place.photos[0].authorAttributions); + expandedImageDiv.appendChild(attributionLabel); + + // Helper function to create attribution DIV. + function createAttribution(attribution) { + attributionLabel = document.createElement("a"); + attributionLabel.classList.add("attribution-label"); + attributionLabel.textContent = attribution[0].displayName; + attributionLabel.href = attribution[0].uri; + attributionLabel.target = "_blank;"; + return attributionLabel; + } +} + +init(); +// [END maps_place_photos] diff --git a/dist/samples/place-photos/docs/style.css b/dist/samples/place-photos/docs/style.css new file mode 100644 index 0000000000..0218c5223b --- /dev/null +++ b/dist/samples/place-photos/docs/style.css @@ -0,0 +1,94 @@ +/** + * @license + * Copyright 2019 Google LLC. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 + */ +/* [START maps_place_photos] */ +/* + * Always set the map height explicitly to define the size of the div element + * that contains the map. + */ +#map { + height: 100%; +} + +/* + * Optional: Makes the sample page fill the window. + */ +html, +body { + height: 100%; + margin: 0; + padding: 0; +} + +#container { + display: flex; + padding: 10px; + width: 100%; + height: 100%; + box-sizing: border-box; +} + +.place-overview { + width: 400px; + height: 380px; + overflow-x: auto; + position: relative; + margin-right: 20px; +} + +#info { + font-family: sans-serif; + position: sticky; + position: -webkit-sticky; + left: 0; + padding-bottom: 10px; +} + +#heading { + width: 500px; + font-size: x-large; + margin-bottom: 20px; +} + +#summary { + width: 500px; +} + +#gallery { + display: flex; +} + +#gallery img { + width: 200px; + height: 200px; + margin-right: 10px; + margin-top: 40px; + border-radius: 10px; + cursor: pointer; +} + +#expanded-image { + display: flex; + height: 380px; + overflow: hidden; + background-color: #000; +} + +#expanded-image img { + width: 100%; + height: auto; + object-fit: contain; +} + +.attribution-label { + background-color: #fff; + opacity: 0.7; + font-size: 10px; + font-family: sans-serif; + margin: 2px; + position: absolute; +} + +/* [END maps_place_photos] */ \ No newline at end of file diff --git a/dist/samples/place-photos/iframe/index.html b/dist/samples/place-photos/iframe/index.html new file mode 100644 index 0000000000..0fe139c77e --- /dev/null +++ b/dist/samples/place-photos/iframe/index.html @@ -0,0 +1,30 @@ + + + + + Place Photos + + + + + +
            +
            +
            +
            +
            +
            + +
            +
            +
            + + + + + diff --git a/dist/samples/place-photos/jsfiddle/demo.css b/dist/samples/place-photos/jsfiddle/demo.css new file mode 100644 index 0000000000..5d01c6f576 --- /dev/null +++ b/dist/samples/place-photos/jsfiddle/demo.css @@ -0,0 +1,92 @@ +/** + * @license + * Copyright 2019 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. + */ +#map { + height: 100%; +} + +/* + * Optional: Makes the sample page fill the window. + */ +html, +body { + height: 100%; + margin: 0; + padding: 0; +} + +#container { + display: flex; + padding: 10px; + width: 100%; + height: 100%; + box-sizing: border-box; +} + +.place-overview { + width: 400px; + height: 380px; + overflow-x: auto; + position: relative; + margin-right: 20px; +} + +#info { + font-family: sans-serif; + position: sticky; + position: -webkit-sticky; + left: 0; + padding-bottom: 10px; +} + +#heading { + width: 500px; + font-size: x-large; + margin-bottom: 20px; +} + +#summary { + width: 500px; +} + +#gallery { + display: flex; +} + +#gallery img { + width: 200px; + height: 200px; + margin-right: 10px; + margin-top: 40px; + border-radius: 10px; + cursor: pointer; +} + +#expanded-image { + display: flex; + height: 380px; + overflow: hidden; + background-color: #000; +} + +#expanded-image img { + width: 100%; + height: auto; + object-fit: contain; +} + +.attribution-label { + background-color: #fff; + opacity: 0.7; + font-size: 10px; + font-family: sans-serif; + margin: 2px; + position: absolute; +} + diff --git a/dist/samples/place-photos/jsfiddle/demo.details b/dist/samples/place-photos/jsfiddle/demo.details new file mode 100644 index 0000000000..4dd37859f3 --- /dev/null +++ b/dist/samples/place-photos/jsfiddle/demo.details @@ -0,0 +1,7 @@ +name: Place Photos +authors: + - Justin Poehnelt +tags: + - google maps +load_type: h +description: Sample code for Google Maps Platform JavaScript API diff --git a/dist/samples/place-photos/jsfiddle/demo.html b/dist/samples/place-photos/jsfiddle/demo.html new file mode 100644 index 0000000000..48542ec15f --- /dev/null +++ b/dist/samples/place-photos/jsfiddle/demo.html @@ -0,0 +1,29 @@ + + + + + Place Photos + + + + +
            +
            +
            +
            +
            +
            + +
            +
            +
            + + + + + diff --git a/dist/samples/place-photos/jsfiddle/demo.js b/dist/samples/place-photos/jsfiddle/demo.js new file mode 100644 index 0000000000..ecd554466a --- /dev/null +++ b/dist/samples/place-photos/jsfiddle/demo.js @@ -0,0 +1,68 @@ +"use strict"; + +/** + * @license + * Copyright 2024 Google LLC. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 + */ +async function init() { + const { Place } = await google.maps.importLibrary("places"); + // Use a place ID to create a new Place instance. + const place = new Place({ + id: "ChIJydSuSkkUkFQRsqhB-cEtYnw", // Woodland Park Zoo, Seattle WA + }); + + // Call fetchFields, passing the desired data fields. + await place.fetchFields({ + fields: ["displayName", "photos", "editorialSummary"], + }); + + // Get the various HTML elements. + let heading = document.getElementById("heading"); + let summary = document.getElementById("summary"); + let gallery = document.getElementById("gallery"); + let expandedImageDiv = document.getElementById("expanded-image"); + let attributionLabel; + + // Show the display name and summary for the place. + heading.textContent = place.displayName; + summary.textContent = place.editorialSummary; + // Add photos to the gallery. + if (place.photos) { + place.photos?.forEach((photo) => { + const img = document.createElement("img"); + const expandedImage = document.createElement("img"); + + img.src = photo.getURI({ maxHeight: 380 }); + img.addEventListener("click", (event) => { + event.preventDefault(); + expandedImage.src = img.src; + expandedImageDiv.innerHTML = ""; + expandedImageDiv.appendChild(expandedImage); + attributionLabel = createAttribution(photo.authorAttributions); + expandedImageDiv.appendChild(attributionLabel); + }); + gallery.appendChild(img); + }); + } + + // Display the first photo. + const img = document.createElement("img"); + + img.src = place.photos[0].getURI(); + expandedImageDiv.appendChild(img); + attributionLabel = createAttribution(place.photos[0].authorAttributions); + expandedImageDiv.appendChild(attributionLabel); + + // Helper function to create attribution DIV. + function createAttribution(attribution) { + attributionLabel = document.createElement("a"); + attributionLabel.classList.add("attribution-label"); + attributionLabel.textContent = attribution[0].displayName; + attributionLabel.href = attribution[0].uri; + attributionLabel.target = "_blank;"; + return attributionLabel; + } +} + +init(); diff --git a/dist/samples/place-photos/playground/index.html b/dist/samples/place-photos/playground/index.html new file mode 100644 index 0000000000..7d80d5f97a --- /dev/null +++ b/dist/samples/place-photos/playground/index.html @@ -0,0 +1,32 @@ + + + Place Photos + + + + + + + + + +
            +
            +
            +
            +
            +
            + +
            +
            +
            + + + + + diff --git a/dist/samples/place-photos/playground/index.ts b/dist/samples/place-photos/playground/index.ts new file mode 100644 index 0000000000..f6cd7ad516 --- /dev/null +++ b/dist/samples/place-photos/playground/index.ts @@ -0,0 +1,66 @@ +async function init() { + const { Place } = (await google.maps.importLibrary( + "places", + )) as google.maps.PlacesLibrary; + + // Use a place ID to create a new Place instance. + const place = new Place({ + id: "ChIJydSuSkkUkFQRsqhB-cEtYnw", // Woodland Park Zoo, Seattle WA + }); + + // Call fetchFields, passing the desired data fields. + await place.fetchFields({ + fields: ["displayName", "photos", "editorialSummary"], + }); + + // Get the various HTML elements. + let heading = document.getElementById("heading") as HTMLElement; + let summary = document.getElementById("summary") as HTMLElement; + let gallery = document.getElementById("gallery") as HTMLElement; + let expandedImageDiv = document.getElementById( + "expanded-image", + ) as HTMLElement; + let attributionLabel; + + // Show the display name and summary for the place. + heading.textContent = place.displayName as string; + summary.textContent = place.editorialSummary as string; + + // Add photos to the gallery. + if (place.photos) { + place.photos?.forEach((photo) => { + const img = document.createElement("img"); + const expandedImage = document.createElement("img"); + img.src = photo.getURI({ maxHeight: 380 }); + img.addEventListener("click", (event) => { + event.preventDefault(); + expandedImage.src = img.src; + expandedImageDiv.innerHTML = ""; + expandedImageDiv.appendChild(expandedImage); + attributionLabel = createAttribution(photo.authorAttributions); + expandedImageDiv.appendChild(attributionLabel); + }); + + gallery.appendChild(img); + }); + } + + // Display the first photo. + const img = document.createElement("img"); + img.src = place.photos![0].getURI(); + expandedImageDiv.appendChild(img); + attributionLabel = createAttribution(place.photos![0].authorAttributions); + expandedImageDiv.appendChild(attributionLabel); + + // Helper function to create attribution DIV. + function createAttribution(attribution) { + attributionLabel = document.createElement("a"); + attributionLabel.classList.add("attribution-label"); + attributionLabel.textContent = attribution[0].displayName; + attributionLabel.href = attribution[0].uri; + attributionLabel.target = "_blank;"; + return attributionLabel; + } +} + +init(); diff --git a/dist/samples/place-photos/playground/package.json b/dist/samples/place-photos/playground/package.json new file mode 100644 index 0000000000..33703d5822 --- /dev/null +++ b/dist/samples/place-photos/playground/package.json @@ -0,0 +1,3 @@ +{ + "dependencies": {} +} \ No newline at end of file diff --git a/dist/samples/place-photos/playground/playground.ts.json b/dist/samples/place-photos/playground/playground.ts.json new file mode 100644 index 0000000000..dfc32121fc --- /dev/null +++ b/dist/samples/place-photos/playground/playground.ts.json @@ -0,0 +1,17 @@ +{ + "files": { + "index.ts": { + "label": "TypeScript" + }, + "style.css": { + "label": "CSS" + }, + "index.html": { + "label": "HTML" + }, + "../../../types/google-maps/index.d.ts": { + "label": "@types/google.maps", + "hidden": true + } + } +} \ No newline at end of file diff --git a/dist/samples/place-photos/playground/style.css b/dist/samples/place-photos/playground/style.css new file mode 100644 index 0000000000..062ea7af8d --- /dev/null +++ b/dist/samples/place-photos/playground/style.css @@ -0,0 +1,87 @@ +/* + * Always set the map height explicitly to define the size of the div element + * that contains the map. + */ +#map { + height: 100%; +} + +/* + * Optional: Makes the sample page fill the window. + */ +html, +body { + height: 100%; + margin: 0; + padding: 0; +} + +#container { + display: flex; + padding: 10px; + width: 100%; + height: 100%; + box-sizing: border-box; +} + +.place-overview { + width: 400px; + height: 380px; + overflow-x: auto; + position: relative; + margin-right: 20px; +} + +#info { + font-family: sans-serif; + position: sticky; + position: -webkit-sticky; + left: 0; + padding-bottom: 10px; +} + +#heading { + width: 500px; + font-size: x-large; + margin-bottom: 20px; +} + +#summary { + width: 500px; +} + +#gallery { + display: flex; +} + +#gallery img { + width: 200px; + height: 200px; + margin-right: 10px; + margin-top: 40px; + border-radius: 10px; + cursor: pointer; +} + +#expanded-image { + display: flex; + height: 380px; + overflow: hidden; + background-color: #000; +} + +#expanded-image img { + width: 100%; + height: auto; + object-fit: contain; +} + +.attribution-label { + background-color: #fff; + opacity: 0.7; + font-size: 10px; + font-family: sans-serif; + margin: 2px; + position: absolute; +} + diff --git a/dist/samples/place-reviews/app/.env b/dist/samples/place-reviews/app/.env new file mode 100644 index 0000000000..d7474dcb8b --- /dev/null +++ b/dist/samples/place-reviews/app/.env @@ -0,0 +1 @@ +VITE_GOOGLE_MAPS_API_KEY=AIzaSyB41DRUbKWJHPxaFjMAwdrzWzbVKartNGg \ No newline at end of file diff --git a/dist/samples/place-reviews/app/.eslintrc.json b/dist/samples/place-reviews/app/.eslintrc.json new file mode 100644 index 0000000000..841a372aa2 --- /dev/null +++ b/dist/samples/place-reviews/app/.eslintrc.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 + } +} \ No newline at end of file diff --git a/dist/samples/place-reviews/app/.gitignore b/dist/samples/place-reviews/app/.gitignore new file mode 100644 index 0000000000..10ec766622 --- /dev/null +++ b/dist/samples/place-reviews/app/.gitignore @@ -0,0 +1,4 @@ + +node_modules +dist +package-lock.json diff --git a/dist/samples/place-reviews/app/README.md b/dist/samples/place-reviews/app/README.md new file mode 100644 index 0000000000..012fc1859f --- /dev/null +++ b/dist/samples/place-reviews/app/README.md @@ -0,0 +1,17 @@ +# Google Maps JavaScript Sample + +This sample is generated from @googlemaps/js-samples located at +https://github.com/googlemaps/js-samples. + +## Setup + +```sh +npm i +npm start # development +npm run build # production +``` + +## Feedback + +For feedback related to this sample, please open a new issue on +[GitHub](https://github.com/googlemaps/js-samples/issues). diff --git a/dist/samples/place-reviews/app/env.d.ts b/dist/samples/place-reviews/app/env.d.ts new file mode 100644 index 0000000000..2d29a7a6be --- /dev/null +++ b/dist/samples/place-reviews/app/env.d.ts @@ -0,0 +1,12 @@ +/// + +/** + * @external https://vitejs.dev/guide/env-and-mode.html + */ +interface ImportMetaEnv { + readonly VITE_GOOGLE_MAPS_API_KEY: string; +} + +interface ImportMeta { + readonly env: ImportMetaEnv; +} diff --git a/dist/samples/place-reviews/app/index.html b/dist/samples/place-reviews/app/index.html new file mode 100644 index 0000000000..071cf0a26d --- /dev/null +++ b/dist/samples/place-reviews/app/index.html @@ -0,0 +1,21 @@ + + + + + Place Reviews + + + + + +
            + + + + + diff --git a/dist/samples/place-reviews/app/index.ts b/dist/samples/place-reviews/app/index.ts new file mode 100644 index 0000000000..cbcdd3eeae --- /dev/null +++ b/dist/samples/place-reviews/app/index.ts @@ -0,0 +1,75 @@ +/** + * @license + * Copyright 2022 Google LLC. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 + */ + +let map: google.maps.Map; +let centerCoordinates = { lat: 42.349134, lng: -71.083184 }; // Boston, MA +let infoWindow; +let contentString; + +async function initMap() { + const { Map, InfoWindow } = await google.maps.importLibrary('maps') as google.maps.MapsLibrary; + const { AdvancedMarkerElement } = await google.maps.importLibrary('marker') as google.maps.MarkerLibrary; + const { Place, Review } = await google.maps.importLibrary('places') as google.maps.PlacesLibrary; + + map = new Map(document.getElementById('map') as HTMLElement, { + center: centerCoordinates, + zoom: 14, + // [START_EXCLUDE] + mapId: '4504f8b37365c3d0', + // [END_EXCLUDE] + }); + + // Use a place ID to create a new Place instance. + const place = new Place({ + id: 'ChIJpyiwa4Zw44kRBQSGWKv4wgA', // Faneuil Hall Marketplace, Boston, MA + }); + + // Call fetchFields, passing 'reviews' and other needed fields. + await place.fetchFields({ + fields: ['displayName', 'formattedAddress', 'location', 'reviews'], + }); + + // If there are any reviews display the first one. + if (place.reviews && place.reviews.length > 0) { + // Get info for the first review. + let reviewRating = place.reviews[0].rating; + let reviewText = place.reviews[0].text; + let authorName = place.reviews[0].authorAttribution!.displayName; + let authorUri = place.reviews[0].authorAttribution!.uri; + + // Format the review using HTML. + contentString =` +
            ${place.displayName}
            +
            ${place.formattedAddress}
            + Author: ${authorName} +
            Rating: ${reviewRating} stars
            +

            Review: ${reviewText}

            `; + } else { + contentString = 'No reviews were found for ' + place.displayName + '.'; + } + + // Create an infowindow to display the review. + infoWindow = new InfoWindow({ + content: contentString, + ariaLabel: place.displayName, + }); + + // Add a marker. + const marker = new AdvancedMarkerElement({ + map, + position: place.location, + title: place.displayName, + }); + + // Show the info window. + infoWindow.open({ + anchor: marker, + map, + }); +} + +initMap(); +export { }; diff --git a/dist/samples/place-reviews/app/package.json b/dist/samples/place-reviews/app/package.json new file mode 100644 index 0000000000..1e77aead0f --- /dev/null +++ b/dist/samples/place-reviews/app/package.json @@ -0,0 +1,35 @@ +{ + "name": "place-reviews", + "description": "Samples for Google Maps JavaScript", + "version": "2.1.4", + "keywords": [ + "google", + "javascript", + "maps", + "samples" + ], + "homepage": "https://github.com/googlemaps/js-samples#readme", + "bugs": { + "url": "https://github.com/googlemaps/js-samples/issues" + }, + "repository": { + "type": "git", + "url": "git+https://github.com/googlemaps/js-samples.git" + }, + "files": [], + "license": "Apache-2.0", + "scripts": { + "dev": "vite", + "start": "vite", + "build": "vite build --outDir dist --base './'", + "test": "tsc --no-emit", + "preview": "vite preview" + }, + "devDependencies": { + "@types/google.maps": "^3.53.5", + "typescript": "^5.5.3", + "vite": "^5.4.6" + }, + "private": true, + "dependencies": {} +} \ No newline at end of file diff --git a/dist/samples/place-reviews/app/style.css b/dist/samples/place-reviews/app/style.css new file mode 100644 index 0000000000..c97e14e569 --- /dev/null +++ b/dist/samples/place-reviews/app/style.css @@ -0,0 +1,23 @@ +/** + * @license + * Copyright 2019 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. + */ +#map { + height: 100%; +} + +/* + * Optional: Makes the sample page fill the window. + */ +html, +body { + height: 100%; + margin: 0; + padding: 0; +} + diff --git a/dist/samples/place-reviews/app/tsconfig.json b/dist/samples/place-reviews/app/tsconfig.json new file mode 100644 index 0000000000..b405998dad --- /dev/null +++ b/dist/samples/place-reviews/app/tsconfig.json @@ -0,0 +1,16 @@ +{ + "compilerOptions": { + "module": "esnext", + "target": "esnext", + "strict": true, + "noImplicitAny": false, + "lib": [ + "esnext", + "es6", + "dom", + "dom.iterable" + ], + "moduleResolution": "Node", + "jsx": "preserve" + } +} \ No newline at end of file diff --git a/dist/samples/place-reviews/app/vite.config.js b/dist/samples/place-reviews/app/vite.config.js new file mode 100644 index 0000000000..d49e45cd7e --- /dev/null +++ b/dist/samples/place-reviews/app/vite.config.js @@ -0,0 +1,11 @@ +import { defineConfig } from "vite"; + +// https://vitejs.dev/config/ +export default defineConfig({ + server: { + hmr: + process.env.CODESANDBOX_SSE || process.env.GITPOD_WORKSPACE_ID + ? 443 + : undefined, + }, +}); diff --git a/dist/samples/place-reviews/docs/index.html b/dist/samples/place-reviews/docs/index.html new file mode 100644 index 0000000000..4807e8634f --- /dev/null +++ b/dist/samples/place-reviews/docs/index.html @@ -0,0 +1,23 @@ + + + + + + Place Reviews + + + + + +
            + + + + + + diff --git a/dist/samples/place-reviews/docs/index.js b/dist/samples/place-reviews/docs/index.js new file mode 100644 index 0000000000..5d82804d85 --- /dev/null +++ b/dist/samples/place-reviews/docs/index.js @@ -0,0 +1,76 @@ +/** + * @license + * Copyright 2022 Google LLC. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 + */ +// [START maps_place_reviews] +let map; +let centerCoordinates = { lat: 42.349134, lng: -71.083184 }; // Boston, MA +let infoWindow; +let contentString; + +async function initMap() { + const { Map, InfoWindow } = await google.maps.importLibrary("maps"); + const { AdvancedMarkerElement } = await google.maps.importLibrary("marker"); + const { Place, Review } = await google.maps.importLibrary("places"); + + map = new Map(document.getElementById("map"), { + center: centerCoordinates, + zoom: 14, + // [START_EXCLUDE] + mapId: "4504f8b37365c3d0", + // [END_EXCLUDE] + }); + + // [START maps_place_reviews_get_first] + // Use a place ID to create a new Place instance. + const place = new Place({ + id: "ChIJpyiwa4Zw44kRBQSGWKv4wgA", // Faneuil Hall Marketplace, Boston, MA + }); + + // Call fetchFields, passing 'reviews' and other needed fields. + await place.fetchFields({ + fields: ["displayName", "formattedAddress", "location", "reviews"], + }); + // If there are any reviews display the first one. + if (place.reviews && place.reviews.length > 0) { + // Get info for the first review. + let reviewRating = place.reviews[0].rating; + let reviewText = place.reviews[0].text; + let authorName = place.reviews[0].authorAttribution.displayName; + let authorUri = place.reviews[0].authorAttribution.uri; + + // Format the review using HTML. + contentString = ` +
            ${place.displayName}
            +
            ${place.formattedAddress}
            + Author: ${authorName} +
            Rating: ${reviewRating} stars
            +

            Review: ${reviewText}

            `; + } else { + contentString = "No reviews were found for " + place.displayName + "."; + } + + // Create an infowindow to display the review. + infoWindow = new InfoWindow({ + content: contentString, + ariaLabel: place.displayName, + }); + + // [END maps_place_reviews_get_first] + // Add a marker. + const marker = new AdvancedMarkerElement({ + map, + position: place.location, + title: place.displayName, + }); + + // Show the info window. + infoWindow.open({ + anchor: marker, + map, + }); +} + +initMap(); +// [END maps_place_reviews] diff --git a/dist/samples/place-reviews/docs/style.css b/dist/samples/place-reviews/docs/style.css new file mode 100644 index 0000000000..50e7924169 --- /dev/null +++ b/dist/samples/place-reviews/docs/style.css @@ -0,0 +1,25 @@ +/** + * @license + * Copyright 2019 Google LLC. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 + */ +/* [START maps_place_reviews] */ +/* + * Always set the map height explicitly to define the size of the div element + * that contains the map. + */ +#map { + height: 100%; +} + +/* + * Optional: Makes the sample page fill the window. + */ +html, +body { + height: 100%; + margin: 0; + padding: 0; +} + +/* [END maps_place_reviews] */ \ No newline at end of file diff --git a/dist/samples/place-reviews/iframe/index.html b/dist/samples/place-reviews/iframe/index.html new file mode 100644 index 0000000000..3d6904588c --- /dev/null +++ b/dist/samples/place-reviews/iframe/index.html @@ -0,0 +1,21 @@ + + + + + Place Reviews + + + + + +
            + + + + + diff --git a/dist/samples/place-reviews/jsfiddle/demo.css b/dist/samples/place-reviews/jsfiddle/demo.css new file mode 100644 index 0000000000..c97e14e569 --- /dev/null +++ b/dist/samples/place-reviews/jsfiddle/demo.css @@ -0,0 +1,23 @@ +/** + * @license + * Copyright 2019 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. + */ +#map { + height: 100%; +} + +/* + * Optional: Makes the sample page fill the window. + */ +html, +body { + height: 100%; + margin: 0; + padding: 0; +} + diff --git a/dist/samples/place-reviews/jsfiddle/demo.details b/dist/samples/place-reviews/jsfiddle/demo.details new file mode 100644 index 0000000000..e2776ecf3d --- /dev/null +++ b/dist/samples/place-reviews/jsfiddle/demo.details @@ -0,0 +1,7 @@ +name: Place Reviews +authors: + - Justin Poehnelt +tags: + - google maps +load_type: h +description: Sample code for Google Maps Platform JavaScript API diff --git a/dist/samples/place-reviews/jsfiddle/demo.html b/dist/samples/place-reviews/jsfiddle/demo.html new file mode 100644 index 0000000000..fafd808407 --- /dev/null +++ b/dist/samples/place-reviews/jsfiddle/demo.html @@ -0,0 +1,20 @@ + + + + + Place Reviews + + + + +
            + + + + + diff --git a/dist/samples/place-reviews/jsfiddle/demo.js b/dist/samples/place-reviews/jsfiddle/demo.js new file mode 100644 index 0000000000..8a7f1f39fb --- /dev/null +++ b/dist/samples/place-reviews/jsfiddle/demo.js @@ -0,0 +1,72 @@ +/** + * @license + * Copyright 2022 Google LLC. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 + */ +let map; +let centerCoordinates = { lat: 42.349134, lng: -71.083184 }; // Boston, MA +let infoWindow; +let contentString; + +async function initMap() { + const { Map, InfoWindow } = await google.maps.importLibrary("maps"); + const { AdvancedMarkerElement } = await google.maps.importLibrary("marker"); + const { Place, Review } = await google.maps.importLibrary("places"); + + map = new Map(document.getElementById("map"), { + center: centerCoordinates, + zoom: 14, + // [START_EXCLUDE] + mapId: "4504f8b37365c3d0", + // [END_EXCLUDE] + }); + + // Use a place ID to create a new Place instance. + const place = new Place({ + id: "ChIJpyiwa4Zw44kRBQSGWKv4wgA", // Faneuil Hall Marketplace, Boston, MA + }); + + // Call fetchFields, passing 'reviews' and other needed fields. + await place.fetchFields({ + fields: ["displayName", "formattedAddress", "location", "reviews"], + }); + // If there are any reviews display the first one. + if (place.reviews && place.reviews.length > 0) { + // Get info for the first review. + let reviewRating = place.reviews[0].rating; + let reviewText = place.reviews[0].text; + let authorName = place.reviews[0].authorAttribution.displayName; + let authorUri = place.reviews[0].authorAttribution.uri; + + // Format the review using HTML. + contentString = ` +
            ${place.displayName}
            +
            ${place.formattedAddress}
            + Author: ${authorName} +
            Rating: ${reviewRating} stars
            +

            Review: ${reviewText}

            `; + } else { + contentString = "No reviews were found for " + place.displayName + "."; + } + + // Create an infowindow to display the review. + infoWindow = new InfoWindow({ + content: contentString, + ariaLabel: place.displayName, + }); + + // Add a marker. + const marker = new AdvancedMarkerElement({ + map, + position: place.location, + title: place.displayName, + }); + + // Show the info window. + infoWindow.open({ + anchor: marker, + map, + }); +} + +initMap(); diff --git a/dist/samples/place-reviews/playground/index.html b/dist/samples/place-reviews/playground/index.html new file mode 100644 index 0000000000..46bd44fdd6 --- /dev/null +++ b/dist/samples/place-reviews/playground/index.html @@ -0,0 +1,23 @@ + + + Place Reviews + + + + + + + + + +
            + + + + + diff --git a/dist/samples/place-reviews/playground/index.ts b/dist/samples/place-reviews/playground/index.ts new file mode 100644 index 0000000000..869a3b9d7a --- /dev/null +++ b/dist/samples/place-reviews/playground/index.ts @@ -0,0 +1,75 @@ +let map: google.maps.Map; +let centerCoordinates = { lat: 42.349134, lng: -71.083184 }; // Boston, MA +let infoWindow; +let contentString; + +async function initMap() { + const { Map, InfoWindow } = (await google.maps.importLibrary( + "maps", + )) as google.maps.MapsLibrary; + const { AdvancedMarkerElement } = (await google.maps.importLibrary( + "marker", + )) as google.maps.MarkerLibrary; + const { Place, Review } = (await google.maps.importLibrary( + "places", + )) as google.maps.PlacesLibrary; + + map = new Map(document.getElementById("map") as HTMLElement, { + center: centerCoordinates, + zoom: 14, + // [START_EXCLUDE] + mapId: "4504f8b37365c3d0", + // [END_EXCLUDE] + }); + + // Use a place ID to create a new Place instance. + const place = new Place({ + id: "ChIJpyiwa4Zw44kRBQSGWKv4wgA", // Faneuil Hall Marketplace, Boston, MA + }); + + // Call fetchFields, passing 'reviews' and other needed fields. + await place.fetchFields({ + fields: ["displayName", "formattedAddress", "location", "reviews"], + }); + + // If there are any reviews display the first one. + if (place.reviews && place.reviews.length > 0) { + // Get info for the first review. + let reviewRating = place.reviews[0].rating; + let reviewText = place.reviews[0].text; + let authorName = place.reviews[0].authorAttribution!.displayName; + let authorUri = place.reviews[0].authorAttribution!.uri; + + // Format the review using HTML. + contentString = ` +
            ${place.displayName}
            +
            ${place.formattedAddress}
            + Author: ${authorName} +
            Rating: ${reviewRating} stars
            +

            Review: ${reviewText}

            `; + } else { + contentString = "No reviews were found for " + place.displayName + "."; + } + + // Create an infowindow to display the review. + infoWindow = new InfoWindow({ + content: contentString, + ariaLabel: place.displayName, + }); + + // Add a marker. + const marker = new AdvancedMarkerElement({ + map, + position: place.location, + title: place.displayName, + }); + + // Show the info window. + infoWindow.open({ + anchor: marker, + map, + }); +} + +initMap(); +export {}; diff --git a/dist/samples/place-reviews/playground/package.json b/dist/samples/place-reviews/playground/package.json new file mode 100644 index 0000000000..33703d5822 --- /dev/null +++ b/dist/samples/place-reviews/playground/package.json @@ -0,0 +1,3 @@ +{ + "dependencies": {} +} \ No newline at end of file diff --git a/dist/samples/place-reviews/playground/playground.ts.json b/dist/samples/place-reviews/playground/playground.ts.json new file mode 100644 index 0000000000..dfc32121fc --- /dev/null +++ b/dist/samples/place-reviews/playground/playground.ts.json @@ -0,0 +1,17 @@ +{ + "files": { + "index.ts": { + "label": "TypeScript" + }, + "style.css": { + "label": "CSS" + }, + "index.html": { + "label": "HTML" + }, + "../../../types/google-maps/index.d.ts": { + "label": "@types/google.maps", + "hidden": true + } + } +} \ No newline at end of file diff --git a/dist/samples/place-reviews/playground/style.css b/dist/samples/place-reviews/playground/style.css new file mode 100644 index 0000000000..a8d59c808e --- /dev/null +++ b/dist/samples/place-reviews/playground/style.css @@ -0,0 +1,18 @@ +/* + * Always set the map height explicitly to define the size of the div element + * that contains the map. + */ +#map { + height: 100%; +} + +/* + * Optional: Makes the sample page fill the window. + */ +html, +body { + height: 100%; + margin: 0; + padding: 0; +} + diff --git a/dist/samples/place-search-pagination/app/index.html b/dist/samples/place-search-pagination/app/index.html index 09d25a0f11..1f6dd68830 100644 --- a/dist/samples/place-search-pagination/app/index.html +++ b/dist/samples/place-search-pagination/app/index.html @@ -7,7 +7,6 @@ Place Search Pagination - @@ -23,10 +22,10 @@

            Results

            @@ -24,10 +23,10 @@

            Results

            - - + +
            @@ -23,10 +22,10 @@

            Results

            + @@ -21,10 +21,10 @@

            Results

            + @@ -16,10 +15,10 @@
            @@ -17,10 +16,10 @@
            - - + +
            +
            + diff --git a/dist/samples/place-text-search/app/package.json b/dist/samples/place-text-search/app/package.json index b86d55cd81..6a36af7779 100644 --- a/dist/samples/place-text-search/app/package.json +++ b/dist/samples/place-text-search/app/package.json @@ -27,8 +27,8 @@ }, "devDependencies": { "@types/google.maps": "^3.53.5", - "typescript": "^5.2.2", - "vite": "^5.0.13" + "typescript": "^5.5.3", + "vite": "^5.4.6" }, "private": true, "dependencies": {} diff --git a/dist/samples/place-text-search/docs/index.html b/dist/samples/place-text-search/docs/index.html index 39ce1598e2..21d500bc95 100644 --- a/dist/samples/place-text-search/docs/index.html +++ b/dist/samples/place-text-search/docs/index.html @@ -8,7 +8,6 @@ Text Search - diff --git a/dist/samples/place-text-search/iframe/index.html b/dist/samples/place-text-search/iframe/index.html index 3aa406fd34..2ccd12c114 100644 --- a/dist/samples/place-text-search/iframe/index.html +++ b/dist/samples/place-text-search/iframe/index.html @@ -7,10 +7,9 @@ Text Search - - - + +
            diff --git a/dist/samples/place-text-search/jsfiddle/demo.html b/dist/samples/place-text-search/jsfiddle/demo.html index b0c6669208..a9eb8b543c 100644 --- a/dist/samples/place-text-search/jsfiddle/demo.html +++ b/dist/samples/place-text-search/jsfiddle/demo.html @@ -7,7 +7,7 @@ Text Search - + diff --git a/dist/samples/place-text-search/playground/index.html b/dist/samples/place-text-search/playground/index.html index a706f7fc27..c1771ed4e7 100644 --- a/dist/samples/place-text-search/playground/index.html +++ b/dist/samples/place-text-search/playground/index.html @@ -1,7 +1,7 @@ Text Search - + + + + - - + + + + @@ -48,10 +47,10 @@
            @@ -49,10 +48,10 @@
            - - + +
            @@ -48,10 +47,10 @@
            + @@ -46,10 +46,10 @@
            + @@ -76,10 +75,10 @@
            @@ -77,10 +76,10 @@ - - + + + @@ -74,10 +74,10 @@ + @@ -43,10 +42,10 @@ @@ -44,10 +43,10 @@ - - + +
            @@ -43,10 +42,10 @@
            + @@ -41,10 +41,10 @@ + + + + - - + +
            @@ -145,10 +145,10 @@
            + + @@ -60,10 +59,10 @@ @@ -61,10 +60,10 @@ - - + +
            @@ -60,10 +59,10 @@
            + @@ -58,10 +58,10 @@ + @@ -29,10 +28,10 @@ @@ -30,10 +29,10 @@ - - + +
            @@ -29,10 +28,10 @@
            + @@ -27,10 +27,10 @@ + @@ -29,10 +28,10 @@ @@ -30,10 +29,10 @@ - - + +
            @@ -29,10 +28,10 @@
            + @@ -27,10 +27,10 @@ + @@ -23,10 +22,10 @@ /> @@ -24,10 +23,10 @@ /> - +

            Query suggestions for 'pizza near Syd':

            @@ -22,10 +21,10 @@ /> + @@ -21,10 +21,10 @@ /> + @@ -22,10 +21,10 @@
            @@ -23,10 +22,10 @@
            - - + + + @@ -20,10 +20,10 @@
            + diff --git a/dist/samples/poly-containsLocation/app/index.html b/dist/samples/poly-containsLocation/app/index.html index d0e9ba99dc..9be91f98c3 100644 --- a/dist/samples/poly-containsLocation/app/index.html +++ b/dist/samples/poly-containsLocation/app/index.html @@ -7,7 +7,6 @@ Polygon Contains Location - @@ -16,10 +15,10 @@
            @@ -17,10 +16,10 @@
            - - + +
            +
            + @@ -16,10 +15,10 @@
            @@ -17,10 +16,10 @@
            - - + +
            +
            + @@ -16,10 +15,10 @@
            @@ -17,10 +16,10 @@
            - - + +
            +
            + @@ -16,10 +15,10 @@
            @@ -17,10 +16,10 @@
            - - + +
            +
            + @@ -16,10 +15,10 @@
            @@ -17,10 +16,10 @@
            - - + +
            +
            + @@ -16,10 +15,10 @@
            @@ -17,10 +16,10 @@
            - - + +
            +
            + @@ -16,10 +15,10 @@
            @@ -17,10 +16,10 @@
            - - + +
            +
            + @@ -20,10 +19,10 @@
            @@ -21,10 +20,10 @@
            - - + +
            @@ -20,10 +19,10 @@
            + @@ -18,10 +18,10 @@
            + @@ -16,10 +15,10 @@
            @@ -17,10 +16,10 @@
            - - + +
            +
            + + Programmatically Load Google Maps JS - + Programmatically Load Google Maps JS - + - - + +
            diff --git a/dist/samples/programmatic-load-button/jsfiddle/demo.html b/dist/samples/programmatic-load-button/jsfiddle/demo.html index ab4c737aca..a7ec208fa8 100644 --- a/dist/samples/programmatic-load-button/jsfiddle/demo.html +++ b/dist/samples/programmatic-load-button/jsfiddle/demo.html @@ -7,7 +7,7 @@ Programmatically Load Google Maps JS - + Programmatically Load Google Maps JS - + Programmatically Load Google Maps JS - diff --git a/dist/samples/programmatic-load/app/package.json b/dist/samples/programmatic-load/app/package.json index 8235055e7b..642da7126c 100644 --- a/dist/samples/programmatic-load/app/package.json +++ b/dist/samples/programmatic-load/app/package.json @@ -27,8 +27,8 @@ }, "devDependencies": { "@types/google.maps": "^3.53.5", - "typescript": "^5.2.2", - "vite": "^5.0.13" + "typescript": "^5.5.3", + "vite": "^5.4.6" }, "private": true, "dependencies": {} diff --git a/dist/samples/programmatic-load/docs/index.html b/dist/samples/programmatic-load/docs/index.html index b1fbc46f34..5c11a8a63f 100644 --- a/dist/samples/programmatic-load/docs/index.html +++ b/dist/samples/programmatic-load/docs/index.html @@ -8,7 +8,6 @@ Programmatically Load Google Maps JS - diff --git a/dist/samples/programmatic-load/iframe/index.html b/dist/samples/programmatic-load/iframe/index.html index 4f1b4a22cc..2f1c5f8027 100644 --- a/dist/samples/programmatic-load/iframe/index.html +++ b/dist/samples/programmatic-load/iframe/index.html @@ -7,10 +7,9 @@ Programmatically Load Google Maps JS - - - + +
            diff --git a/dist/samples/programmatic-load/jsfiddle/demo.html b/dist/samples/programmatic-load/jsfiddle/demo.html index 7dde2d2bcb..95a591bfc3 100644 --- a/dist/samples/programmatic-load/jsfiddle/demo.html +++ b/dist/samples/programmatic-load/jsfiddle/demo.html @@ -7,7 +7,7 @@ Programmatically Load Google Maps JS - + diff --git a/dist/samples/programmatic-load/playground/index.html b/dist/samples/programmatic-load/playground/index.html index 36047fc1af..939437e648 100644 --- a/dist/samples/programmatic-load/playground/index.html +++ b/dist/samples/programmatic-load/playground/index.html @@ -1,7 +1,7 @@ Programmatically Load Google Maps JS - + diff --git a/dist/samples/react-map/app/package.json b/dist/samples/react-map/app/package.json index 03ac0c41f0..76c27ab011 100644 --- a/dist/samples/react-map/app/package.json +++ b/dist/samples/react-map/app/package.json @@ -27,13 +27,13 @@ }, "devDependencies": { "@types/google.maps": "^3.53.5", - "typescript": "^5.2.2", - "vite": "^5.0.13" + "typescript": "^5.5.3", + "vite": "^5.4.6" }, "private": true, "dependencies": { "react": "^18.2.0", - "react-dom": "^18.2.0", + "react-dom": "^18.3.1", "@googlemaps/react-wrapper": "^1.1.35", "@googlemaps/typescript-guards": "^2.0.3" } diff --git a/dist/samples/react-map/docs/index.html b/dist/samples/react-map/docs/index.html index 7027bc1355..233fd7b022 100644 --- a/dist/samples/react-map/docs/index.html +++ b/dist/samples/react-map/docs/index.html @@ -8,7 +8,6 @@ React Map - diff --git a/dist/samples/react-map/iframe/index.html b/dist/samples/react-map/iframe/index.html index 67f99f4861..309d3c79dd 100644 --- a/dist/samples/react-map/iframe/index.html +++ b/dist/samples/react-map/iframe/index.html @@ -7,10 +7,9 @@ React Map - - - + +
            diff --git a/dist/samples/react-map/jsfiddle/demo.html b/dist/samples/react-map/jsfiddle/demo.html index 2a9e36305b..cca3302c24 100644 --- a/dist/samples/react-map/jsfiddle/demo.html +++ b/dist/samples/react-map/jsfiddle/demo.html @@ -7,7 +7,7 @@ React Map - + diff --git a/dist/samples/react-map/jsfiddle/demo.jsx b/dist/samples/react-map/jsfiddle/demo.jsx index 5c0b76d593..5180159e20 100644 --- a/dist/samples/react-map/jsfiddle/demo.jsx +++ b/dist/samples/react-map/jsfiddle/demo.jsx @@ -14,7 +14,7 @@ * limitations under the License. */ import * as React from "https://cdn.skypack.dev/react@^18.2.0"; -import { createRoot } from "https://cdn.skypack.dev/react-dom@^18.2.0/client"; +import { createRoot } from "https://cdn.skypack.dev/react-dom@^18.3.1/client"; import { Wrapper } from "https://cdn.skypack.dev/@googlemaps/react-wrapper@^1.1.35"; import { createCustomEqual } from "https://cdn.skypack.dev/fast-equals@^3.0.3"; import { isLatLngLiteral } from "https://cdn.skypack.dev/@googlemaps/typescript-guards@^2.0.3"; diff --git a/dist/samples/react-map/playground/index.html b/dist/samples/react-map/playground/index.html index 08cc9aa80a..2b294d87ae 100644 --- a/dist/samples/react-map/playground/index.html +++ b/dist/samples/react-map/playground/index.html @@ -1,7 +1,7 @@ React Map - + @@ -16,10 +15,10 @@
            @@ -17,10 +16,10 @@
            - - + +
            +
            + @@ -16,10 +15,10 @@
            @@ -17,10 +16,10 @@
            - - + +
            +
            + @@ -16,10 +15,10 @@
            @@ -17,10 +16,10 @@
            - - + +
            +
            + + + diff --git a/dist/samples/rgm-autocomplete/app/index.tsx b/dist/samples/rgm-autocomplete/app/index.tsx new file mode 100644 index 0000000000..6d3945f835 --- /dev/null +++ b/dist/samples/rgm-autocomplete/app/index.tsx @@ -0,0 +1,119 @@ +/* + * Copyright 2024 Google LLC. All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +import React, { useState, useEffect, useRef } from 'react'; +import { createRoot } from 'react-dom/client'; +import { + APIProvider, + ControlPosition, + MapControl, + AdvancedMarker, + Map, + useMap, + useMapsLibrary, + useAdvancedMarkerRef, + AdvancedMarkerRef +} from '@vis.gl/react-google-maps'; + +const API_KEY = + globalThis.GOOGLE_MAPS_API_KEY ?? (import.meta.env.VITE_GOOGLE_MAPS_API_KEY!); + +const App = () => { + const [selectedPlace, setSelectedPlace] = + useState(null); + const [markerRef, marker] = useAdvancedMarkerRef(); + + return ( + + + + + +
            + +
            +
            + +
            + ); +}; + +interface MapHandlerProps { + place: google.maps.places.PlaceResult | null; + marker: google.maps.marker.AdvancedMarkerElement | null; +} + +const MapHandler = ({ place, marker }: MapHandlerProps) => { + const map = useMap(); + + useEffect(() => { + if (!map || !place || !marker) return; + + if (place.geometry?.viewport) { + map.fitBounds(place.geometry?.viewport); + } + marker.position = place.geometry?.location; + }, [map, place, marker]); + + return null; +}; + +interface PlaceAutocompleteProps { + onPlaceSelect: (place: google.maps.places.PlaceResult | null) => void; +} + +const PlaceAutocomplete = ({ onPlaceSelect }: PlaceAutocompleteProps) => { + const [placeAutocomplete, setPlaceAutocomplete] = + useState(null); + const inputRef = useRef(null); + const places = useMapsLibrary('places'); + + useEffect(() => { + if (!places || !inputRef.current) return; + + const options = { + fields: ['geometry', 'name', 'formatted_address'] + }; + + setPlaceAutocomplete(new places.Autocomplete(inputRef.current, options)); + }, [places]); + + useEffect(() => { + if (!placeAutocomplete) return; + + placeAutocomplete.addListener('place_changed', () => { + onPlaceSelect(placeAutocomplete.getPlace()); + }); + }, [onPlaceSelect, placeAutocomplete]); + + return ( +
            + +
            + ); +}; + +const root = createRoot(document.getElementById('app')!); +root.render(); + +export default App; diff --git a/dist/samples/rgm-autocomplete/app/package.json b/dist/samples/rgm-autocomplete/app/package.json new file mode 100644 index 0000000000..2922710072 --- /dev/null +++ b/dist/samples/rgm-autocomplete/app/package.json @@ -0,0 +1,40 @@ +{ + "name": "rgm-autocomplete", + "description": "Samples for Google Maps JavaScript", + "version": "2.1.4", + "keywords": [ + "google", + "javascript", + "maps", + "samples" + ], + "homepage": "https://github.com/googlemaps/js-samples#readme", + "bugs": { + "url": "https://github.com/googlemaps/js-samples/issues" + }, + "repository": { + "type": "git", + "url": "git+https://github.com/googlemaps/js-samples.git" + }, + "files": [], + "license": "Apache-2.0", + "scripts": { + "dev": "vite", + "start": "vite", + "build": "vite build --outDir dist --base './'", + "test": "tsc --no-emit", + "preview": "vite preview" + }, + "devDependencies": { + "@types/google.maps": "^3.53.5", + "typescript": "^5.5.3", + "vite": "^5.4.6" + }, + "private": true, + "dependencies": { + "@vis.gl/react-google-maps": "^1.0.0", + "react": "^18.2.0", + "react-dom": "^18.3.1", + "vite": "^5.4.6" + } +} \ No newline at end of file diff --git a/dist/samples/rgm-autocomplete/app/style.css b/dist/samples/rgm-autocomplete/app/style.css new file mode 100644 index 0000000000..b72082ca6f --- /dev/null +++ b/dist/samples/rgm-autocomplete/app/style.css @@ -0,0 +1,52 @@ +/** + * @license + * Copyright 2024 Google LLC. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 + */ +body { + margin: 0; + font-family: sans-serif; +} + +#app { + width: 100vw; + height: 100vh; +} + +.autocomplete-container input, +.autocomplete-control { + box-sizing: border-box; +} + +.autocomplete-control { + margin: 24px; + background: #fff; +} + +.autocomplete-container { + width: 300px; +} + +.autocomplete-container input { + width: 100%; + height: 40px; + padding: 0 12px; + font-size: 18px; +} + +.autocomplete-container .custom-list { + width: 100%; + list-style: none; + padding: 0; + margin: 0; +} + +.autocomplete-container .custom-list-item { + padding: 8px; +} + +.autocomplete-container .custom-list-item:hover { + background: lightgrey; + cursor: pointer; +} + diff --git a/dist/samples/rgm-autocomplete/app/tsconfig.json b/dist/samples/rgm-autocomplete/app/tsconfig.json new file mode 100644 index 0000000000..b405998dad --- /dev/null +++ b/dist/samples/rgm-autocomplete/app/tsconfig.json @@ -0,0 +1,16 @@ +{ + "compilerOptions": { + "module": "esnext", + "target": "esnext", + "strict": true, + "noImplicitAny": false, + "lib": [ + "esnext", + "es6", + "dom", + "dom.iterable" + ], + "moduleResolution": "Node", + "jsx": "preserve" + } +} \ No newline at end of file diff --git a/dist/samples/rgm-autocomplete/app/vite.config.js b/dist/samples/rgm-autocomplete/app/vite.config.js new file mode 100644 index 0000000000..d49e45cd7e --- /dev/null +++ b/dist/samples/rgm-autocomplete/app/vite.config.js @@ -0,0 +1,11 @@ +import { defineConfig } from "vite"; + +// https://vitejs.dev/config/ +export default defineConfig({ + server: { + hmr: + process.env.CODESANDBOX_SSE || process.env.GITPOD_WORKSPACE_ID + ? 443 + : undefined, + }, +}); diff --git a/dist/samples/rgm-autocomplete/docs/index.html b/dist/samples/rgm-autocomplete/docs/index.html new file mode 100644 index 0000000000..7b2cce1eeb --- /dev/null +++ b/dist/samples/rgm-autocomplete/docs/index.html @@ -0,0 +1,19 @@ + + + + + + React Google Maps - Autocomplete + + + + +
            + + + + diff --git a/dist/samples/rgm-autocomplete/docs/index.jsx b/dist/samples/rgm-autocomplete/docs/index.jsx new file mode 100644 index 0000000000..11724578c8 --- /dev/null +++ b/dist/samples/rgm-autocomplete/docs/index.jsx @@ -0,0 +1,105 @@ +/* + * Copyright 2024 Google LLC. All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +// [START maps_rgm_autocomplete] +import React, { useState, useEffect, useRef } from "react"; +import { createRoot } from "react-dom/client"; +import { + APIProvider, + ControlPosition, + MapControl, + AdvancedMarker, + Map, + useMap, + useMapsLibrary, + useAdvancedMarkerRef, +} from "@vis.gl/react-google-maps"; +const API_KEY = globalThis.GOOGLE_MAPS_API_KEY ?? "YOUR_API_KEY"; + +const App = () => { + const [selectedPlace, setSelectedPlace] = useState(null); + const [markerRef, marker] = useAdvancedMarkerRef(); + return ( + + + + + +
            + +
            +
            + +
            + ); +}; + +const MapHandler = ({ place, marker }) => { + const map = useMap(); + + useEffect(() => { + if (!map || !place || !marker) return; + + if (place.geometry?.viewport) { + map.fitBounds(place.geometry?.viewport); + } + + marker.position = place.geometry?.location; + }, [map, place, marker]); + return null; +}; + +const PlaceAutocomplete = ({ onPlaceSelect }) => { + const [placeAutocomplete, setPlaceAutocomplete] = useState(null); + const inputRef = useRef(null); + const places = useMapsLibrary("places"); + + useEffect(() => { + if (!places || !inputRef.current) return; + + const options = { + fields: ["geometry", "name", "formatted_address"], + }; + + setPlaceAutocomplete(new places.Autocomplete(inputRef.current, options)); + }, [places]); + useEffect(() => { + if (!placeAutocomplete) return; + + placeAutocomplete.addListener("place_changed", () => { + onPlaceSelect(placeAutocomplete.getPlace()); + }); + }, [onPlaceSelect, placeAutocomplete]); + return ( +
            + +
            + ); +}; + +const root = createRoot(document.getElementById("app")); + +root.render(); +export default App; +// [END maps_rgm_autocomplete] diff --git a/dist/samples/rgm-autocomplete/docs/style.css b/dist/samples/rgm-autocomplete/docs/style.css new file mode 100644 index 0000000000..62c35098ff --- /dev/null +++ b/dist/samples/rgm-autocomplete/docs/style.css @@ -0,0 +1,54 @@ +/** + * @license + * Copyright 2024 Google LLC. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 + */ +/* [START maps_rgm_autocomplete] */ +body { + margin: 0; + font-family: sans-serif; +} + +#app { + width: 100vw; + height: 100vh; +} + +.autocomplete-container input, +.autocomplete-control { + box-sizing: border-box; +} + +.autocomplete-control { + margin: 24px; + background: #fff; +} + +.autocomplete-container { + width: 300px; +} + +.autocomplete-container input { + width: 100%; + height: 40px; + padding: 0 12px; + font-size: 18px; +} + +.autocomplete-container .custom-list { + width: 100%; + list-style: none; + padding: 0; + margin: 0; +} + +.autocomplete-container .custom-list-item { + padding: 8px; +} + +.autocomplete-container .custom-list-item:hover { + background: lightgrey; + cursor: pointer; +} + +/* [END maps_rgm_autocomplete] */ \ No newline at end of file diff --git a/dist/samples/rgm-autocomplete/iframe/index.html b/dist/samples/rgm-autocomplete/iframe/index.html new file mode 100644 index 0000000000..a302da8849 --- /dev/null +++ b/dist/samples/rgm-autocomplete/iframe/index.html @@ -0,0 +1,17 @@ + + + + + React Google Maps - Autocomplete + + + + + +
            + + diff --git a/dist/samples/rgm-autocomplete/jsfiddle/demo.css b/dist/samples/rgm-autocomplete/jsfiddle/demo.css new file mode 100644 index 0000000000..b72082ca6f --- /dev/null +++ b/dist/samples/rgm-autocomplete/jsfiddle/demo.css @@ -0,0 +1,52 @@ +/** + * @license + * Copyright 2024 Google LLC. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 + */ +body { + margin: 0; + font-family: sans-serif; +} + +#app { + width: 100vw; + height: 100vh; +} + +.autocomplete-container input, +.autocomplete-control { + box-sizing: border-box; +} + +.autocomplete-control { + margin: 24px; + background: #fff; +} + +.autocomplete-container { + width: 300px; +} + +.autocomplete-container input { + width: 100%; + height: 40px; + padding: 0 12px; + font-size: 18px; +} + +.autocomplete-container .custom-list { + width: 100%; + list-style: none; + padding: 0; + margin: 0; +} + +.autocomplete-container .custom-list-item { + padding: 8px; +} + +.autocomplete-container .custom-list-item:hover { + background: lightgrey; + cursor: pointer; +} + diff --git a/dist/samples/rgm-autocomplete/jsfiddle/demo.details b/dist/samples/rgm-autocomplete/jsfiddle/demo.details new file mode 100644 index 0000000000..f1b08c27e8 --- /dev/null +++ b/dist/samples/rgm-autocomplete/jsfiddle/demo.details @@ -0,0 +1,7 @@ +name: React Google Maps - Autocomplete +authors: + - Justin Poehnelt +tags: + - google maps +load_type: h +description: Sample code for Google Maps Platform JavaScript API diff --git a/dist/samples/rgm-autocomplete/jsfiddle/demo.html b/dist/samples/rgm-autocomplete/jsfiddle/demo.html new file mode 100644 index 0000000000..c85c2f8d4a --- /dev/null +++ b/dist/samples/rgm-autocomplete/jsfiddle/demo.html @@ -0,0 +1,17 @@ + + + + + React Google Maps - Autocomplete + + + + +
            + + + diff --git a/dist/samples/rgm-autocomplete/jsfiddle/demo.jsx b/dist/samples/rgm-autocomplete/jsfiddle/demo.jsx new file mode 100644 index 0000000000..2c6dd56fb0 --- /dev/null +++ b/dist/samples/rgm-autocomplete/jsfiddle/demo.jsx @@ -0,0 +1,103 @@ +/* + * Copyright 2024 Google LLC. All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +import React, { useState, useEffect, useRef } from "https://cdn.skypack.dev/react@^18.2.0"; +import { createRoot } from "https://cdn.skypack.dev/react-dom@^18.3.1/client"; +import { + APIProvider, + ControlPosition, + MapControl, + AdvancedMarker, + Map, + useMap, + useMapsLibrary, + useAdvancedMarkerRef, +} from "https://cdn.skypack.dev/@vis.gl/react-google-maps@^1.0.0"; +const API_KEY = globalThis.GOOGLE_MAPS_API_KEY ?? "YOUR_API_KEY"; + +const App = () => { + const [selectedPlace, setSelectedPlace] = useState(null); + const [markerRef, marker] = useAdvancedMarkerRef(); + return ( + + + + + +
            + +
            +
            + +
            + ); +}; + +const MapHandler = ({ place, marker }) => { + const map = useMap(); + + useEffect(() => { + if (!map || !place || !marker) return; + + if (place.geometry?.viewport) { + map.fitBounds(place.geometry?.viewport); + } + + marker.position = place.geometry?.location; + }, [map, place, marker]); + return null; +}; + +const PlaceAutocomplete = ({ onPlaceSelect }) => { + const [placeAutocomplete, setPlaceAutocomplete] = useState(null); + const inputRef = useRef(null); + const places = useMapsLibrary("places"); + + useEffect(() => { + if (!places || !inputRef.current) return; + + const options = { + fields: ["geometry", "name", "formatted_address"], + }; + + setPlaceAutocomplete(new places.Autocomplete(inputRef.current, options)); + }, [places]); + useEffect(() => { + if (!placeAutocomplete) return; + + placeAutocomplete.addListener("place_changed", () => { + onPlaceSelect(placeAutocomplete.getPlace()); + }); + }, [onPlaceSelect, placeAutocomplete]); + return ( +
            + +
            + ); +}; + +const root = createRoot(document.getElementById("app")); + +root.render(); +export default App; diff --git a/dist/samples/rgm-autocomplete/playground/index.html b/dist/samples/rgm-autocomplete/playground/index.html new file mode 100644 index 0000000000..09deb3c2d1 --- /dev/null +++ b/dist/samples/rgm-autocomplete/playground/index.html @@ -0,0 +1,19 @@ + + + React Google Maps - Autocomplete + + + + + + + + +
            + + + diff --git a/dist/samples/rgm-autocomplete/playground/index.tsx b/dist/samples/rgm-autocomplete/playground/index.tsx new file mode 100644 index 0000000000..b4875560b8 --- /dev/null +++ b/dist/samples/rgm-autocomplete/playground/index.tsx @@ -0,0 +1,119 @@ +/* + * Copyright 2024 Google LLC. All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +import React, { useState, useEffect, useRef } from 'react'; +import { createRoot } from 'react-dom/client'; +import { + APIProvider, + ControlPosition, + MapControl, + AdvancedMarker, + Map, + useMap, + useMapsLibrary, + useAdvancedMarkerRef, + AdvancedMarkerRef +} from '@vis.gl/react-google-maps'; + +const API_KEY = + globalThis.GOOGLE_MAPS_API_KEY ?? ("YOUR_API_KEY"); + +const App = () => { + const [selectedPlace, setSelectedPlace] = + useState(null); + const [markerRef, marker] = useAdvancedMarkerRef(); + + return ( + + + + + +
            + +
            +
            + +
            + ); +}; + +interface MapHandlerProps { + place: google.maps.places.PlaceResult | null; + marker: google.maps.marker.AdvancedMarkerElement | null; +} + +const MapHandler = ({ place, marker }: MapHandlerProps) => { + const map = useMap(); + + useEffect(() => { + if (!map || !place || !marker) return; + + if (place.geometry?.viewport) { + map.fitBounds(place.geometry?.viewport); + } + marker.position = place.geometry?.location; + }, [map, place, marker]); + + return null; +}; + +interface PlaceAutocompleteProps { + onPlaceSelect: (place: google.maps.places.PlaceResult | null) => void; +} + +const PlaceAutocomplete = ({ onPlaceSelect }: PlaceAutocompleteProps) => { + const [placeAutocomplete, setPlaceAutocomplete] = + useState(null); + const inputRef = useRef(null); + const places = useMapsLibrary('places'); + + useEffect(() => { + if (!places || !inputRef.current) return; + + const options = { + fields: ['geometry', 'name', 'formatted_address'] + }; + + setPlaceAutocomplete(new places.Autocomplete(inputRef.current, options)); + }, [places]); + + useEffect(() => { + if (!placeAutocomplete) return; + + placeAutocomplete.addListener('place_changed', () => { + onPlaceSelect(placeAutocomplete.getPlace()); + }); + }, [onPlaceSelect, placeAutocomplete]); + + return ( +
            + +
            + ); +}; + +const root = createRoot(document.getElementById('app')!); +root.render(); + +export default App; diff --git a/dist/samples/rgm-autocomplete/playground/package.json b/dist/samples/rgm-autocomplete/playground/package.json new file mode 100644 index 0000000000..91bbeeda86 --- /dev/null +++ b/dist/samples/rgm-autocomplete/playground/package.json @@ -0,0 +1,8 @@ +{ + "dependencies": { + "@vis.gl/react-google-maps": "^1.0.0", + "react": "^18.2.0", + "react-dom": "^18.3.1", + "vite": "^5.4.6" + } +} \ No newline at end of file diff --git a/dist/samples/rgm-autocomplete/playground/playground.ts.json b/dist/samples/rgm-autocomplete/playground/playground.ts.json new file mode 100644 index 0000000000..4926d7f154 --- /dev/null +++ b/dist/samples/rgm-autocomplete/playground/playground.ts.json @@ -0,0 +1,20 @@ +{ + "files": { + "index.ts": { + "label": "TypeScript" + }, + "style.css": { + "label": "CSS" + }, + "index.html": { + "label": "HTML" + }, + "../../../types/google-maps/index.d.ts": { + "label": "@types/google.maps", + "hidden": true + }, + "package.json": { + "label": "Dependencies" + } + } +} \ No newline at end of file diff --git a/dist/samples/rgm-autocomplete/playground/style.css b/dist/samples/rgm-autocomplete/playground/style.css new file mode 100644 index 0000000000..789018e732 --- /dev/null +++ b/dist/samples/rgm-autocomplete/playground/style.css @@ -0,0 +1,47 @@ +body { + margin: 0; + font-family: sans-serif; +} + +#app { + width: 100vw; + height: 100vh; +} + +.autocomplete-container input, +.autocomplete-control { + box-sizing: border-box; +} + +.autocomplete-control { + margin: 24px; + background: #fff; +} + +.autocomplete-container { + width: 300px; +} + +.autocomplete-container input { + width: 100%; + height: 40px; + padding: 0 12px; + font-size: 18px; +} + +.autocomplete-container .custom-list { + width: 100%; + list-style: none; + padding: 0; + margin: 0; +} + +.autocomplete-container .custom-list-item { + padding: 8px; +} + +.autocomplete-container .custom-list-item:hover { + background: lightgrey; + cursor: pointer; +} + diff --git a/dist/samples/rgm-basic-map/app/index.tsx b/dist/samples/rgm-basic-map/app/index.tsx index a238ed3d5b..62a280507d 100644 --- a/dist/samples/rgm-basic-map/app/index.tsx +++ b/dist/samples/rgm-basic-map/app/index.tsx @@ -14,15 +14,16 @@ * limitations under the License. */ import React from 'react'; -import {createRoot} from 'react-dom/client'; - -import {APIProvider, Map} from '@vis.gl/react-google-maps'; +import { createRoot } from 'react-dom/client'; +import { APIProvider, Map } from '@vis.gl/react-google-maps'; const API_KEY = globalThis.GOOGLE_MAPS_API_KEY ?? (import.meta.env.VITE_GOOGLE_MAPS_API_KEY!); const App = () => ( - + ( - + React Google Maps - Basic Map - - + +
            diff --git a/dist/samples/rgm-basic-map/jsfiddle/demo.jsx b/dist/samples/rgm-basic-map/jsfiddle/demo.jsx index 21cf35badd..6aaec79f03 100644 --- a/dist/samples/rgm-basic-map/jsfiddle/demo.jsx +++ b/dist/samples/rgm-basic-map/jsfiddle/demo.jsx @@ -14,11 +14,14 @@ * limitations under the License. */ import React from "https://cdn.skypack.dev/react@^18.2.0"; -import { createRoot } from "https://cdn.skypack.dev/react-dom@^18.2.0/client"; -import { APIProvider, Map } from "https://cdn.skypack.dev/@vis.gl/react-google-maps@latest"; +import { createRoot } from "https://cdn.skypack.dev/react-dom@^18.3.1/client"; +import { APIProvider, Map } from "https://cdn.skypack.dev/@vis.gl/react-google-maps@^1.0.0"; const API_KEY = globalThis.GOOGLE_MAPS_API_KEY ?? "YOUR_API_KEY"; const App = () => ( - + ( - + + +/** + * @external https://vitejs.dev/guide/env-and-mode.html + */ +interface ImportMetaEnv { + readonly VITE_GOOGLE_MAPS_API_KEY: string; +} + +interface ImportMeta { + readonly env: ImportMetaEnv; +} diff --git a/dist/samples/rgm-college-picker/app/index.html b/dist/samples/rgm-college-picker/app/index.html new file mode 100644 index 0000000000..d7f1568ba1 --- /dev/null +++ b/dist/samples/rgm-college-picker/app/index.html @@ -0,0 +1,17 @@ + + + + + React Google Maps - College Picker App + + + + +
            + + + diff --git a/dist/samples/rgm-college-picker/app/index.tsx b/dist/samples/rgm-college-picker/app/index.tsx new file mode 100644 index 0000000000..2be33cb59c --- /dev/null +++ b/dist/samples/rgm-college-picker/app/index.tsx @@ -0,0 +1,135 @@ +/** + * @license + * Copyright 2024 Google LLC + * SPDX-License-Identifier: Apache-2.0 + */ + +import React, { useState, useRef } from 'react'; +import ReactDOM from 'react-dom/client'; +import { AdvancedMarker, Map, Pin, APIProvider } from '@vis.gl/react-google-maps'; +import { + PlaceReviews, + PlaceDataProvider, + PlaceDirectionsButton, + IconButton, + PlaceOverview, + SplitLayout, + OverlayLayout, + PlacePicker +} from '@googlemaps/extended-component-library/react'; +/** + * The below imports are necessary because we are creating refs of + * the OverlayLayout and PlacePicker components. You need to pass + * the ref property a web component type object. Imports from + * @googlemaps/extended-component-library/react are wrappers around + * the web components, not the components themselves. For the ref + * property we import the actual components and alias them for clarity. + */ +import { OverlayLayout as TOverlayLayout } from '@googlemaps/extended-component-library/overlay_layout.js'; +import { PlacePicker as TPlacePicker } from '@googlemaps/extended-component-library/place_picker.js'; + +const API_KEY = + globalThis.GOOGLE_MAPS_API_KEY ?? (import.meta.env.VITE_GOOGLE_MAPS_API_KEY!); +const DEFAULT_CENTER = { lat: 38, lng: -98 }; +const DEFAULT_ZOOM = 4; +const DEFAULT_ZOOM_WITH_LOCATION = 16; +/** + * Sample app that helps users locate a college on the map, with place info such + * as ratings, photos, and reviews displayed on the side. + */ +const App = () => { + const overlayLayoutRef = useRef(null); + const pickerRef = useRef(null); + const [college, setCollege] = useState(undefined); + /** + * See https://lit.dev/docs/frameworks/react/#using-slots for why + * we need to wrap our custom elements in a div with a slot attribute. + */ + return ( +
            + + +
            + +
            + { + if (!pickerRef.current?.value) { + setCollege(undefined); + } else { + setCollege(pickerRef.current?.value); + } + }} + /> + +
            + overlayLayoutRef.current?.showOverlay()} + > + See Reviews + +
            +
            + + Directions + +
            +
            +
            +
            + overlayLayoutRef.current?.hideOverlay()} + > + Close + + + + +
            +
            +
            +
            + + {college?.location && ( + + + + )} + +
            +
            +
            +
            + ); +}; + +const root = ReactDOM.createRoot(document.getElementById('root')!); +root.render( + + + +); diff --git a/dist/samples/rgm-college-picker/app/package.json b/dist/samples/rgm-college-picker/app/package.json new file mode 100644 index 0000000000..04dc5f9030 --- /dev/null +++ b/dist/samples/rgm-college-picker/app/package.json @@ -0,0 +1,40 @@ +{ + "name": "rgm-college-picker", + "description": "Samples for Google Maps JavaScript", + "version": "2.1.4", + "keywords": [ + "google", + "javascript", + "maps", + "samples" + ], + "homepage": "https://github.com/googlemaps/js-samples#readme", + "bugs": { + "url": "https://github.com/googlemaps/js-samples/issues" + }, + "repository": { + "type": "git", + "url": "git+https://github.com/googlemaps/js-samples.git" + }, + "files": [], + "license": "Apache-2.0", + "scripts": { + "dev": "vite", + "start": "vite", + "build": "vite build --outDir dist --base './'", + "test": "tsc --no-emit", + "preview": "vite preview" + }, + "devDependencies": { + "@types/google.maps": "^3.53.5", + "typescript": "^5.5.3", + "vite": "^5.4.6" + }, + "private": true, + "dependencies": { + "@vis.gl/react-google-maps": "^1.0.0", + "react": "^18.2.0", + "react-dom": "^18.3.1", + "vite": "^5.4.6" + } +} \ No newline at end of file diff --git a/dist/samples/rgm-college-picker/app/style.css b/dist/samples/rgm-college-picker/app/style.css new file mode 100644 index 0000000000..84511b2d6a --- /dev/null +++ b/dist/samples/rgm-college-picker/app/style.css @@ -0,0 +1,66 @@ +/** + * Copyright 2024 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * @license + * Copyright 2024 Google LLC + * SPDX-License-Identifier: Apache-2.0 + */ +body { + margin: 0; + font-family: sans-serif; +} + +#root { + width: 100vw; + height: 100vh; +} + +.App { + --gmpx-color-surface: #f6f5ff; + --gmpx-color-on-primary: #f8e8ff; + --gmpx-color-on-surface: #000; + --gmpx-color-on-surface-variant: #636268; + --gmpx-color-primary: #8a5cf4; + --gmpx-fixed-panel-height-column-layout: 420px; + --gmpx-fixed-panel-width-row-layout: 340px; + background: var(--gmpx-color-surface); + inset: 0; + position: fixed; +} + +.MainContainer { + display: flex; + flex-direction: column; +} + +.SplitLayoutContainer { + height: 100%; +} + +.CollegePicker { + --gmpx-color-surface: #fff; + flex-grow: 1; + margin: 1rem; +} + +.CloseButton { + display: block; + margin: 1rem; +} + +.SlotDiv { + display: contents; +} + diff --git a/dist/samples/rgm-college-picker/app/tsconfig.json b/dist/samples/rgm-college-picker/app/tsconfig.json new file mode 100644 index 0000000000..b405998dad --- /dev/null +++ b/dist/samples/rgm-college-picker/app/tsconfig.json @@ -0,0 +1,16 @@ +{ + "compilerOptions": { + "module": "esnext", + "target": "esnext", + "strict": true, + "noImplicitAny": false, + "lib": [ + "esnext", + "es6", + "dom", + "dom.iterable" + ], + "moduleResolution": "Node", + "jsx": "preserve" + } +} \ No newline at end of file diff --git a/dist/samples/rgm-college-picker/app/vite.config.js b/dist/samples/rgm-college-picker/app/vite.config.js new file mode 100644 index 0000000000..d49e45cd7e --- /dev/null +++ b/dist/samples/rgm-college-picker/app/vite.config.js @@ -0,0 +1,11 @@ +import { defineConfig } from "vite"; + +// https://vitejs.dev/config/ +export default defineConfig({ + server: { + hmr: + process.env.CODESANDBOX_SSE || process.env.GITPOD_WORKSPACE_ID + ? 443 + : undefined, + }, +}); diff --git a/dist/samples/rgm-college-picker/docs/index.html b/dist/samples/rgm-college-picker/docs/index.html new file mode 100644 index 0000000000..194bee350f --- /dev/null +++ b/dist/samples/rgm-college-picker/docs/index.html @@ -0,0 +1,19 @@ + + + + + + React Google Maps - College Picker App + + + + +
            + + + + diff --git a/dist/samples/rgm-college-picker/docs/index.jsx b/dist/samples/rgm-college-picker/docs/index.jsx new file mode 100644 index 0000000000..d5c0697b30 --- /dev/null +++ b/dist/samples/rgm-college-picker/docs/index.jsx @@ -0,0 +1,138 @@ +/** + * @license + * Copyright 2024 Google LLC + * SPDX-License-Identifier: Apache-2.0 + */ +// [START maps_rgm_college_picker] +import React, { useState, useRef } from "react"; +import ReactDOM from "react-dom/client"; +import { + AdvancedMarker, + Map, + Pin, + APIProvider, +} from "@vis.gl/react-google-maps"; +import { + PlaceReviews, + PlaceDataProvider, + PlaceDirectionsButton, + IconButton, + PlaceOverview, + SplitLayout, + OverlayLayout, + PlacePicker, +} from "@googlemaps/extended-component-library/react"; +const API_KEY = globalThis.GOOGLE_MAPS_API_KEY ?? "YOUR_API_KEY"; +const DEFAULT_CENTER = { lat: 38, lng: -98 }; +const DEFAULT_ZOOM = 4; +const DEFAULT_ZOOM_WITH_LOCATION = 16; + +/** + * Sample app that helps users locate a college on the map, with place info such + * as ratings, photos, and reviews displayed on the side. + */ +const App = () => { + const overlayLayoutRef = useRef(null); + const pickerRef = useRef(null); + const [college, setCollege] = useState(undefined); + /** + * See https://lit.dev/docs/frameworks/react/#using-slots for why + * we need to wrap our custom elements in a div with a slot attribute. + */ + return ( +
            + + +
            + +
            + { + if (!pickerRef.current?.value) { + setCollege(undefined); + } else { + setCollege(pickerRef.current?.value); + } + }} + /> + +
            + overlayLayoutRef.current?.showOverlay()} + > + See Reviews + +
            +
            + + Directions + +
            +
            +
            +
            + overlayLayoutRef.current?.hideOverlay()} + > + Close + + + + +
            +
            +
            +
            + + {college?.location && ( + + + + )} + +
            +
            +
            +
            + ); +}; + +const root = ReactDOM.createRoot(document.getElementById("root")); + +root.render( + + + , +); +// [END maps_rgm_college_picker] diff --git a/dist/samples/rgm-college-picker/docs/style.css b/dist/samples/rgm-college-picker/docs/style.css new file mode 100644 index 0000000000..63b86d5e81 --- /dev/null +++ b/dist/samples/rgm-college-picker/docs/style.css @@ -0,0 +1,68 @@ +/** + * Copyright 2024 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * @license + * Copyright 2024 Google LLC + * SPDX-License-Identifier: Apache-2.0 + */ +/* [START maps_rgm_college_picker] */ +body { + margin: 0; + font-family: sans-serif; +} + +#root { + width: 100vw; + height: 100vh; +} + +.App { + --gmpx-color-surface: #f6f5ff; + --gmpx-color-on-primary: #f8e8ff; + --gmpx-color-on-surface: #000; + --gmpx-color-on-surface-variant: #636268; + --gmpx-color-primary: #8a5cf4; + --gmpx-fixed-panel-height-column-layout: 420px; + --gmpx-fixed-panel-width-row-layout: 340px; + background: var(--gmpx-color-surface); + inset: 0; + position: fixed; +} + +.MainContainer { + display: flex; + flex-direction: column; +} + +.SplitLayoutContainer { + height: 100%; +} + +.CollegePicker { + --gmpx-color-surface: #fff; + flex-grow: 1; + margin: 1rem; +} + +.CloseButton { + display: block; + margin: 1rem; +} + +.SlotDiv { + display: contents; +} + +/* [END maps_rgm_college_picker] */ \ No newline at end of file diff --git a/dist/samples/rgm-college-picker/iframe/index.html b/dist/samples/rgm-college-picker/iframe/index.html new file mode 100644 index 0000000000..97c4e99275 --- /dev/null +++ b/dist/samples/rgm-college-picker/iframe/index.html @@ -0,0 +1,17 @@ + + + + + React Google Maps - College Picker App + + + + + +
            + + diff --git a/dist/samples/rgm-college-picker/jsfiddle/demo.css b/dist/samples/rgm-college-picker/jsfiddle/demo.css new file mode 100644 index 0000000000..84511b2d6a --- /dev/null +++ b/dist/samples/rgm-college-picker/jsfiddle/demo.css @@ -0,0 +1,66 @@ +/** + * Copyright 2024 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * @license + * Copyright 2024 Google LLC + * SPDX-License-Identifier: Apache-2.0 + */ +body { + margin: 0; + font-family: sans-serif; +} + +#root { + width: 100vw; + height: 100vh; +} + +.App { + --gmpx-color-surface: #f6f5ff; + --gmpx-color-on-primary: #f8e8ff; + --gmpx-color-on-surface: #000; + --gmpx-color-on-surface-variant: #636268; + --gmpx-color-primary: #8a5cf4; + --gmpx-fixed-panel-height-column-layout: 420px; + --gmpx-fixed-panel-width-row-layout: 340px; + background: var(--gmpx-color-surface); + inset: 0; + position: fixed; +} + +.MainContainer { + display: flex; + flex-direction: column; +} + +.SplitLayoutContainer { + height: 100%; +} + +.CollegePicker { + --gmpx-color-surface: #fff; + flex-grow: 1; + margin: 1rem; +} + +.CloseButton { + display: block; + margin: 1rem; +} + +.SlotDiv { + display: contents; +} + diff --git a/dist/samples/rgm-college-picker/jsfiddle/demo.details b/dist/samples/rgm-college-picker/jsfiddle/demo.details new file mode 100644 index 0000000000..5844686e0c --- /dev/null +++ b/dist/samples/rgm-college-picker/jsfiddle/demo.details @@ -0,0 +1,7 @@ +name: React Google Maps - College Picker App +authors: + - Justin Poehnelt +tags: + - google maps +load_type: h +description: Sample code for Google Maps Platform JavaScript API diff --git a/dist/samples/rgm-college-picker/jsfiddle/demo.html b/dist/samples/rgm-college-picker/jsfiddle/demo.html new file mode 100644 index 0000000000..d7f1568ba1 --- /dev/null +++ b/dist/samples/rgm-college-picker/jsfiddle/demo.html @@ -0,0 +1,17 @@ + + + + + React Google Maps - College Picker App + + + + +
            + + + diff --git a/dist/samples/rgm-college-picker/jsfiddle/demo.jsx b/dist/samples/rgm-college-picker/jsfiddle/demo.jsx new file mode 100644 index 0000000000..ae36d49461 --- /dev/null +++ b/dist/samples/rgm-college-picker/jsfiddle/demo.jsx @@ -0,0 +1,136 @@ +/** + * @license + * Copyright 2024 Google LLC + * SPDX-License-Identifier: Apache-2.0 + */ +import React, { useState, useRef } from "https://cdn.skypack.dev/react@^18.2.0"; +import ReactDOM from "https://cdn.skypack.dev/react-dom@^18.3.1/client"; +import { + AdvancedMarker, + Map, + Pin, + APIProvider, +} from "https://cdn.skypack.dev/@vis.gl/react-google-maps@^1.0.0"; +import { + PlaceReviews, + PlaceDataProvider, + PlaceDirectionsButton, + IconButton, + PlaceOverview, + SplitLayout, + OverlayLayout, + PlacePicker, +} from "https://cdn.skypack.dev/@googlemaps/extended-component-library@^0.6.11/react"; +const API_KEY = globalThis.GOOGLE_MAPS_API_KEY ?? "YOUR_API_KEY"; +const DEFAULT_CENTER = { lat: 38, lng: -98 }; +const DEFAULT_ZOOM = 4; +const DEFAULT_ZOOM_WITH_LOCATION = 16; + +/** + * Sample app that helps users locate a college on the map, with place info such + * as ratings, photos, and reviews displayed on the side. + */ +const App = () => { + const overlayLayoutRef = useRef(null); + const pickerRef = useRef(null); + const [college, setCollege] = useState(undefined); + /** + * See https://lit.dev/docs/frameworks/react/#using-slots for why + * we need to wrap our custom elements in a div with a slot attribute. + */ + return ( +
            + + +
            + +
            + { + if (!pickerRef.current?.value) { + setCollege(undefined); + } else { + setCollege(pickerRef.current?.value); + } + }} + /> + +
            + overlayLayoutRef.current?.showOverlay()} + > + See Reviews + +
            +
            + + Directions + +
            +
            +
            +
            + overlayLayoutRef.current?.hideOverlay()} + > + Close + + + + +
            +
            +
            +
            + + {college?.location && ( + + + + )} + +
            +
            +
            +
            + ); +}; + +const root = ReactDOM.createRoot(document.getElementById("root")); + +root.render( + + + , +); diff --git a/dist/samples/rgm-college-picker/playground/index.html b/dist/samples/rgm-college-picker/playground/index.html new file mode 100644 index 0000000000..9f1d19b1b2 --- /dev/null +++ b/dist/samples/rgm-college-picker/playground/index.html @@ -0,0 +1,19 @@ + + + React Google Maps - College Picker App + + + + + + + + +
            + + + diff --git a/dist/samples/rgm-college-picker/playground/index.tsx b/dist/samples/rgm-college-picker/playground/index.tsx new file mode 100644 index 0000000000..bc10ee80cd --- /dev/null +++ b/dist/samples/rgm-college-picker/playground/index.tsx @@ -0,0 +1,135 @@ +/** + * @license + * Copyright 2024 Google LLC + * SPDX-License-Identifier: Apache-2.0 + */ + +import React, { useState, useRef } from 'react'; +import ReactDOM from 'react-dom/client'; +import { AdvancedMarker, Map, Pin, APIProvider } from '@vis.gl/react-google-maps'; +import { + PlaceReviews, + PlaceDataProvider, + PlaceDirectionsButton, + IconButton, + PlaceOverview, + SplitLayout, + OverlayLayout, + PlacePicker +} from '@googlemaps/extended-component-library/react'; +/** + * The below imports are necessary because we are creating refs of + * the OverlayLayout and PlacePicker components. You need to pass + * the ref property a web component type object. Imports from + * @googlemaps/extended-component-library/react are wrappers around + * the web components, not the components themselves. For the ref + * property we import the actual components and alias them for clarity. + */ +import { OverlayLayout as TOverlayLayout } from '@googlemaps/extended-component-library/overlay_layout.js'; +import { PlacePicker as TPlacePicker } from '@googlemaps/extended-component-library/place_picker.js'; + +const API_KEY = + globalThis.GOOGLE_MAPS_API_KEY ?? ("YOUR_API_KEY"); +const DEFAULT_CENTER = { lat: 38, lng: -98 }; +const DEFAULT_ZOOM = 4; +const DEFAULT_ZOOM_WITH_LOCATION = 16; +/** + * Sample app that helps users locate a college on the map, with place info such + * as ratings, photos, and reviews displayed on the side. + */ +const App = () => { + const overlayLayoutRef = useRef(null); + const pickerRef = useRef(null); + const [college, setCollege] = useState(undefined); + /** + * See https://lit.dev/docs/frameworks/react/#using-slots for why + * we need to wrap our custom elements in a div with a slot attribute. + */ + return ( +
            + + +
            + +
            + { + if (!pickerRef.current?.value) { + setCollege(undefined); + } else { + setCollege(pickerRef.current?.value); + } + }} + /> + +
            + overlayLayoutRef.current?.showOverlay()} + > + See Reviews + +
            +
            + + Directions + +
            +
            +
            +
            + overlayLayoutRef.current?.hideOverlay()} + > + Close + + + + +
            +
            +
            +
            + + {college?.location && ( + + + + )} + +
            +
            +
            +
            + ); +}; + +const root = ReactDOM.createRoot(document.getElementById('root')!); +root.render( + + + +); diff --git a/dist/samples/rgm-college-picker/playground/package.json b/dist/samples/rgm-college-picker/playground/package.json new file mode 100644 index 0000000000..91bbeeda86 --- /dev/null +++ b/dist/samples/rgm-college-picker/playground/package.json @@ -0,0 +1,8 @@ +{ + "dependencies": { + "@vis.gl/react-google-maps": "^1.0.0", + "react": "^18.2.0", + "react-dom": "^18.3.1", + "vite": "^5.4.6" + } +} \ No newline at end of file diff --git a/dist/samples/rgm-college-picker/playground/playground.ts.json b/dist/samples/rgm-college-picker/playground/playground.ts.json new file mode 100644 index 0000000000..4926d7f154 --- /dev/null +++ b/dist/samples/rgm-college-picker/playground/playground.ts.json @@ -0,0 +1,20 @@ +{ + "files": { + "index.ts": { + "label": "TypeScript" + }, + "style.css": { + "label": "CSS" + }, + "index.html": { + "label": "HTML" + }, + "../../../types/google-maps/index.d.ts": { + "label": "@types/google.maps", + "hidden": true + }, + "package.json": { + "label": "Dependencies" + } + } +} \ No newline at end of file diff --git a/dist/samples/rgm-college-picker/playground/style.css b/dist/samples/rgm-college-picker/playground/style.css new file mode 100644 index 0000000000..84511b2d6a --- /dev/null +++ b/dist/samples/rgm-college-picker/playground/style.css @@ -0,0 +1,66 @@ +/** + * Copyright 2024 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * @license + * Copyright 2024 Google LLC + * SPDX-License-Identifier: Apache-2.0 + */ +body { + margin: 0; + font-family: sans-serif; +} + +#root { + width: 100vw; + height: 100vh; +} + +.App { + --gmpx-color-surface: #f6f5ff; + --gmpx-color-on-primary: #f8e8ff; + --gmpx-color-on-surface: #000; + --gmpx-color-on-surface-variant: #636268; + --gmpx-color-primary: #8a5cf4; + --gmpx-fixed-panel-height-column-layout: 420px; + --gmpx-fixed-panel-width-row-layout: 340px; + background: var(--gmpx-color-surface); + inset: 0; + position: fixed; +} + +.MainContainer { + display: flex; + flex-direction: column; +} + +.SplitLayoutContainer { + height: 100%; +} + +.CollegePicker { + --gmpx-color-surface: #fff; + flex-grow: 1; + margin: 1rem; +} + +.CloseButton { + display: block; + margin: 1rem; +} + +.SlotDiv { + display: contents; +} + diff --git a/dist/samples/split-map-panes/app/index.html b/dist/samples/split-map-panes/app/index.html index 41a66e54b0..07911fc03f 100644 --- a/dist/samples/split-map-panes/app/index.html +++ b/dist/samples/split-map-panes/app/index.html @@ -7,7 +7,7 @@ Split Map Panes - + @@ -24,10 +24,10 @@
            + @@ -25,10 +25,10 @@
            + - - + +
            @@ -24,10 +24,10 @@
            + @@ -23,10 +23,10 @@ + @@ -26,10 +26,10 @@ + + + - - + +
            @@ -107,10 +107,10 @@
            + + @@ -16,10 +15,10 @@
            @@ -17,10 +16,10 @@
            - - + +
            +
            + @@ -16,10 +15,10 @@
            @@ -17,10 +16,10 @@
            - - + +
            +
            + @@ -16,10 +15,10 @@
            @@ -17,10 +16,10 @@
            - - + +
            +
            + @@ -16,10 +15,10 @@
            @@ -17,10 +16,10 @@
            - - + +
            +
            + @@ -37,10 +36,10 @@ @@ -38,10 +37,10 @@ - - + +
            @@ -37,10 +36,10 @@ + @@ -35,10 +35,10 @@ + @@ -19,14 +18,14 @@
            diff --git a/dist/samples/streetview-overlays/app/index.ts b/dist/samples/streetview-overlays/app/index.ts index 9779bd2621..ae20140b37 100644 --- a/dist/samples/streetview-overlays/app/index.ts +++ b/dist/samples/streetview-overlays/app/index.ts @@ -22,27 +22,37 @@ function initMap(): void { document .getElementById("toggle")! .addEventListener("click", toggleStreetView); + + const cafeIcon = document.createElement("img"); + cafeIcon.src = "https://developers.google.com/maps/documentation/javascript/examples/full/images/cafe_icon.svg"; + + const dollarIcon = document.createElement("img"); + dollarIcon.src = "https://developers.google.com/maps/documentation/javascript/examples/full/images/bank_icon.svg"; + + const busIcon = document.createElement("img"); + busIcon.src = "https://developers.google.com/maps/documentation/javascript/examples/full/images/bus_icon.svg"; + // Set up the markers on the map const cafeMarker = new google.maps.Marker({ position: { lat: 40.730031, lng: -73.991428 }, map, - icon: "https://chart.apis.google.com/chart?chst=d_map_pin_icon&chld=cafe|FFFF00", title: "Cafe", + icon: cafeIcon.src, }); const bankMarker = new google.maps.Marker({ position: { lat: 40.729681, lng: -73.991138 }, map, - icon: "https://chart.apis.google.com/chart?chst=d_map_pin_icon&chld=dollar|FFFF00", title: "Bank", + icon: dollarIcon.src, }); const busMarker = new google.maps.Marker({ position: { lat: 40.729559, lng: -73.990741 }, map, - icon: "https://chart.apis.google.com/chart?chst=d_map_pin_icon&chld=bus|FFFF00", title: "Bus Stop", + icon: busIcon.src, }); // We get the map's default panorama and set up some defaults. diff --git a/dist/samples/streetview-overlays/app/package.json b/dist/samples/streetview-overlays/app/package.json index c6d388e79a..1e2bde0750 100644 --- a/dist/samples/streetview-overlays/app/package.json +++ b/dist/samples/streetview-overlays/app/package.json @@ -27,8 +27,8 @@ }, "devDependencies": { "@types/google.maps": "^3.53.5", - "typescript": "^5.2.2", - "vite": "^5.0.13" + "typescript": "^5.5.3", + "vite": "^5.4.6" }, "private": true, "dependencies": {} diff --git a/dist/samples/streetview-overlays/docs/index.html b/dist/samples/streetview-overlays/docs/index.html index c8bf87b887..1acbe0e3d2 100644 --- a/dist/samples/streetview-overlays/docs/index.html +++ b/dist/samples/streetview-overlays/docs/index.html @@ -8,7 +8,6 @@ Overlays Within Street View - @@ -20,14 +19,14 @@
            diff --git a/dist/samples/streetview-overlays/docs/index.js b/dist/samples/streetview-overlays/docs/index.js index 6d214b2785..1c65d49adc 100644 --- a/dist/samples/streetview-overlays/docs/index.js +++ b/dist/samples/streetview-overlays/docs/index.js @@ -17,24 +17,39 @@ function initMap() { document.getElementById("toggle").addEventListener("click", toggleStreetView); + const cafeIcon = document.createElement("img"); + + cafeIcon.src = + "https://developers.google.com/maps/documentation/javascript/examples/full/images/cafe_icon.svg"; + + const dollarIcon = document.createElement("img"); + + dollarIcon.src = + "https://developers.google.com/maps/documentation/javascript/examples/full/images/bank_icon.svg"; + + const busIcon = document.createElement("img"); + + busIcon.src = + "https://developers.google.com/maps/documentation/javascript/examples/full/images/bus_icon.svg"; + // Set up the markers on the map const cafeMarker = new google.maps.Marker({ position: { lat: 40.730031, lng: -73.991428 }, map, - icon: "https://chart.apis.google.com/chart?chst=d_map_pin_icon&chld=cafe|FFFF00", title: "Cafe", + icon: cafeIcon.src, }); const bankMarker = new google.maps.Marker({ position: { lat: 40.729681, lng: -73.991138 }, map, - icon: "https://chart.apis.google.com/chart?chst=d_map_pin_icon&chld=dollar|FFFF00", title: "Bank", + icon: dollarIcon.src, }); const busMarker = new google.maps.Marker({ position: { lat: 40.729559, lng: -73.990741 }, map, - icon: "https://chart.apis.google.com/chart?chst=d_map_pin_icon&chld=bus|FFFF00", title: "Bus Stop", + icon: busIcon.src, }); // We get the map's default panorama and set up some defaults. diff --git a/dist/samples/streetview-overlays/iframe/index.html b/dist/samples/streetview-overlays/iframe/index.html index a4e18874a5..6be20ed0be 100644 --- a/dist/samples/streetview-overlays/iframe/index.html +++ b/dist/samples/streetview-overlays/iframe/index.html @@ -7,10 +7,9 @@ Overlays Within Street View - - - + +
            @@ -19,14 +18,14 @@
            diff --git a/dist/samples/streetview-overlays/jsfiddle/demo.html b/dist/samples/streetview-overlays/jsfiddle/demo.html index 9555c5dd62..2a794bfca1 100644 --- a/dist/samples/streetview-overlays/jsfiddle/demo.html +++ b/dist/samples/streetview-overlays/jsfiddle/demo.html @@ -7,7 +7,7 @@ Overlays Within Street View - + @@ -17,14 +17,14 @@
            diff --git a/dist/samples/streetview-overlays/jsfiddle/demo.js b/dist/samples/streetview-overlays/jsfiddle/demo.js index 49972440b2..b066f1293e 100644 --- a/dist/samples/streetview-overlays/jsfiddle/demo.js +++ b/dist/samples/streetview-overlays/jsfiddle/demo.js @@ -16,24 +16,39 @@ function initMap() { document.getElementById("toggle").addEventListener("click", toggleStreetView); + const cafeIcon = document.createElement("img"); + + cafeIcon.src = + "https://developers.google.com/maps/documentation/javascript/examples/full/images/cafe_icon.svg"; + + const dollarIcon = document.createElement("img"); + + dollarIcon.src = + "https://developers.google.com/maps/documentation/javascript/examples/full/images/bank_icon.svg"; + + const busIcon = document.createElement("img"); + + busIcon.src = + "https://developers.google.com/maps/documentation/javascript/examples/full/images/bus_icon.svg"; + // Set up the markers on the map const cafeMarker = new google.maps.Marker({ position: { lat: 40.730031, lng: -73.991428 }, map, - icon: "https://chart.apis.google.com/chart?chst=d_map_pin_icon&chld=cafe|FFFF00", title: "Cafe", + icon: cafeIcon.src, }); const bankMarker = new google.maps.Marker({ position: { lat: 40.729681, lng: -73.991138 }, map, - icon: "https://chart.apis.google.com/chart?chst=d_map_pin_icon&chld=dollar|FFFF00", title: "Bank", + icon: dollarIcon.src, }); const busMarker = new google.maps.Marker({ position: { lat: 40.729559, lng: -73.990741 }, map, - icon: "https://chart.apis.google.com/chart?chst=d_map_pin_icon&chld=bus|FFFF00", title: "Bus Stop", + icon: busIcon.src, }); // We get the map's default panorama and set up some defaults. diff --git a/dist/samples/streetview-overlays/playground/index.html b/dist/samples/streetview-overlays/playground/index.html index fa88a404fa..2616d3b5cd 100644 --- a/dist/samples/streetview-overlays/playground/index.html +++ b/dist/samples/streetview-overlays/playground/index.html @@ -1,7 +1,7 @@ Overlays Within Street View - + diff --git a/dist/samples/streetview-overlays/playground/index.ts b/dist/samples/streetview-overlays/playground/index.ts index 4ef69d1bf3..8696c197da 100644 --- a/dist/samples/streetview-overlays/playground/index.ts +++ b/dist/samples/streetview-overlays/playground/index.ts @@ -17,26 +17,38 @@ function initMap(): void { .getElementById("toggle")! .addEventListener("click", toggleStreetView); + const cafeIcon = document.createElement("img"); + cafeIcon.src = + "https://developers.google.com/maps/documentation/javascript/examples/full/images/cafe_icon.svg"; + + const dollarIcon = document.createElement("img"); + dollarIcon.src = + "https://developers.google.com/maps/documentation/javascript/examples/full/images/bank_icon.svg"; + + const busIcon = document.createElement("img"); + busIcon.src = + "https://developers.google.com/maps/documentation/javascript/examples/full/images/bus_icon.svg"; + // Set up the markers on the map const cafeMarker = new google.maps.Marker({ position: { lat: 40.730031, lng: -73.991428 }, map, - icon: "https://chart.apis.google.com/chart?chst=d_map_pin_icon&chld=cafe|FFFF00", title: "Cafe", + icon: cafeIcon.src, }); const bankMarker = new google.maps.Marker({ position: { lat: 40.729681, lng: -73.991138 }, map, - icon: "https://chart.apis.google.com/chart?chst=d_map_pin_icon&chld=dollar|FFFF00", title: "Bank", + icon: dollarIcon.src, }); const busMarker = new google.maps.Marker({ position: { lat: 40.729559, lng: -73.990741 }, map, - icon: "https://chart.apis.google.com/chart?chst=d_map_pin_icon&chld=bus|FFFF00", title: "Bus Stop", + icon: busIcon.src, }); // We get the map's default panorama and set up some defaults. diff --git a/dist/samples/streetview-service/app/index.html b/dist/samples/streetview-service/app/index.html index c70caa2f66..ff078cccb2 100644 --- a/dist/samples/streetview-service/app/index.html +++ b/dist/samples/streetview-service/app/index.html @@ -7,7 +7,6 @@ Directly Accessing Street View Data - @@ -17,10 +16,10 @@
            @@ -18,10 +17,10 @@
            - - + +
            + @@ -15,10 +15,10 @@
            + @@ -17,10 +16,10 @@
            @@ -18,10 +17,10 @@
            - - + +
            + @@ -15,10 +15,10 @@
            + @@ -16,10 +15,10 @@
            @@ -17,10 +16,10 @@
            - - + +
            +
            + @@ -25,10 +24,10 @@
            @@ -26,10 +25,10 @@
            - - + +
            @@ -25,10 +24,10 @@
            + @@ -23,10 +23,10 @@
            + @@ -16,10 +15,10 @@
            @@ -17,10 +16,10 @@
            - - + +
            @@ -15,10 +14,10 @@
            @@ -16,10 +15,10 @@
            @@ -17,10 +16,10 @@
            - - + +
            +
            + @@ -16,10 +15,10 @@
            @@ -17,10 +16,10 @@
            - - + +
            +
            + + + + + + + + + + + + + + + + + diff --git a/dist/samples/web-components-accessibility/app/index.ts b/dist/samples/web-components-accessibility/app/index.ts new file mode 100644 index 0000000000..7fc40f03bd --- /dev/null +++ b/dist/samples/web-components-accessibility/app/index.ts @@ -0,0 +1,35 @@ +/** + * @license + * Copyright 2019 Google LLC. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 + */ + +async function initMap(): Promise { + const { InfoWindow } = await google.maps.importLibrary("maps") as google.maps.MapsLibrary; + const { PinElement } = await google.maps.importLibrary("marker") as google.maps.MarkerLibrary; + console.log('Maps JavaScript API loaded.'); + + // Return an array of markers. + const advancedMarkers = [...document.querySelectorAll('gmp-advanced-marker')]; + + // Create a shared info window. + let infoWindow = new InfoWindow(); + + for (let i = 0; i < advancedMarkers.length; i++) { + const marker = advancedMarkers[i] as google.maps.marker.AdvancedMarkerElement; + const pin = new PinElement({ + glyph: `${i + 1}`, + scale: 1.5, + }); + + marker.appendChild(pin.element); + marker.addEventListener('gmp-click', () => { + infoWindow.close(); + infoWindow.setContent(marker.title); + infoWindow.open(marker.map, marker); + }); + } +} + +initMap(); +export { }; \ No newline at end of file diff --git a/dist/samples/web-components-accessibility/app/package.json b/dist/samples/web-components-accessibility/app/package.json new file mode 100644 index 0000000000..102ad5ef83 --- /dev/null +++ b/dist/samples/web-components-accessibility/app/package.json @@ -0,0 +1,35 @@ +{ + "name": "web-components-accessibility", + "description": "Samples for Google Maps JavaScript", + "version": "2.1.4", + "keywords": [ + "google", + "javascript", + "maps", + "samples" + ], + "homepage": "https://github.com/googlemaps/js-samples#readme", + "bugs": { + "url": "https://github.com/googlemaps/js-samples/issues" + }, + "repository": { + "type": "git", + "url": "git+https://github.com/googlemaps/js-samples.git" + }, + "files": [], + "license": "Apache-2.0", + "scripts": { + "dev": "vite", + "start": "vite", + "build": "vite build --outDir dist --base './'", + "test": "tsc --no-emit", + "preview": "vite preview" + }, + "devDependencies": { + "@types/google.maps": "^3.53.5", + "typescript": "^5.5.3", + "vite": "^5.4.6" + }, + "private": true, + "dependencies": {} +} \ No newline at end of file diff --git a/dist/samples/web-components-accessibility/app/style.css b/dist/samples/web-components-accessibility/app/style.css new file mode 100644 index 0000000000..582e19d3dd --- /dev/null +++ b/dist/samples/web-components-accessibility/app/style.css @@ -0,0 +1,27 @@ +/** + * @license + * Copyright 2019 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. + */ +#map { + height: 100%; +} + +/* + * Optional: Makes the sample page fill the window. + */ +html, +body { + height: 100%; + margin: 0; + padding: 0; +} + +gmp-map { + height: 400px; +} + diff --git a/dist/samples/web-components-accessibility/app/tsconfig.json b/dist/samples/web-components-accessibility/app/tsconfig.json new file mode 100644 index 0000000000..b405998dad --- /dev/null +++ b/dist/samples/web-components-accessibility/app/tsconfig.json @@ -0,0 +1,16 @@ +{ + "compilerOptions": { + "module": "esnext", + "target": "esnext", + "strict": true, + "noImplicitAny": false, + "lib": [ + "esnext", + "es6", + "dom", + "dom.iterable" + ], + "moduleResolution": "Node", + "jsx": "preserve" + } +} \ No newline at end of file diff --git a/dist/samples/web-components-accessibility/app/vite.config.js b/dist/samples/web-components-accessibility/app/vite.config.js new file mode 100644 index 0000000000..d49e45cd7e --- /dev/null +++ b/dist/samples/web-components-accessibility/app/vite.config.js @@ -0,0 +1,11 @@ +import { defineConfig } from "vite"; + +// https://vitejs.dev/config/ +export default defineConfig({ + server: { + hmr: + process.env.CODESANDBOX_SSE || process.env.GITPOD_WORKSPACE_ID + ? 443 + : undefined, + }, +}); diff --git a/dist/samples/web-components-accessibility/docs/index.html b/dist/samples/web-components-accessibility/docs/index.html new file mode 100644 index 0000000000..f6bc759b39 --- /dev/null +++ b/dist/samples/web-components-accessibility/docs/index.html @@ -0,0 +1,51 @@ + + + + + + Advanced Marker Accessibility with web components + + + + + + + + + + + + + + + + + + + + diff --git a/dist/samples/web-components-accessibility/docs/index.js b/dist/samples/web-components-accessibility/docs/index.js new file mode 100644 index 0000000000..f91d67061f --- /dev/null +++ b/dist/samples/web-components-accessibility/docs/index.js @@ -0,0 +1,39 @@ +/** + * @license + * Copyright 2019 Google LLC. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 + */ +// [START maps_web_components_accessibility] +async function initMap() { + const { InfoWindow } = await google.maps.importLibrary("maps"); + const { PinElement } = await google.maps.importLibrary("marker"); + + console.log("Maps JavaScript API loaded."); + + // [START maps_web_components_accessibility_query] + // Return an array of markers. + const advancedMarkers = [...document.querySelectorAll("gmp-advanced-marker")]; + // [END maps_web_components_accessibility_query] + // [START maps_web_components_accessibility_iterate] + // Create a shared info window. + let infoWindow = new InfoWindow(); + + for (let i = 0; i < advancedMarkers.length; i++) { + const marker = advancedMarkers[i]; + const pin = new PinElement({ + glyph: `${i + 1}`, + scale: 1.5, + }); + + marker.appendChild(pin.element); + marker.addEventListener("gmp-click", () => { + infoWindow.close(); + infoWindow.setContent(marker.title); + infoWindow.open(marker.map, marker); + }); + } + // [END maps_web_components_accessibility_iterate] +} + +initMap(); +// [END maps_web_components_accessibility] diff --git a/dist/samples/web-components-accessibility/docs/style.css b/dist/samples/web-components-accessibility/docs/style.css new file mode 100644 index 0000000000..8f435fec69 --- /dev/null +++ b/dist/samples/web-components-accessibility/docs/style.css @@ -0,0 +1,29 @@ +/** + * @license + * Copyright 2019 Google LLC. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 + */ +/* [START maps_web_components_accessibility] */ +/* + * Always set the map height explicitly to define the size of the div element + * that contains the map. + */ +#map { + height: 100%; +} + +/* + * Optional: Makes the sample page fill the window. + */ +html, +body { + height: 100%; + margin: 0; + padding: 0; +} + +gmp-map { + height: 400px; +} + +/* [END maps_web_components_accessibility] */ \ No newline at end of file diff --git a/dist/samples/web-components-accessibility/iframe/index.html b/dist/samples/web-components-accessibility/iframe/index.html new file mode 100644 index 0000000000..97561518fa --- /dev/null +++ b/dist/samples/web-components-accessibility/iframe/index.html @@ -0,0 +1,49 @@ + + + + + Advanced Marker Accessibility with web components + + + + + + + + + + + + + + + + + + + diff --git a/dist/samples/web-components-accessibility/jsfiddle/demo.css b/dist/samples/web-components-accessibility/jsfiddle/demo.css new file mode 100644 index 0000000000..582e19d3dd --- /dev/null +++ b/dist/samples/web-components-accessibility/jsfiddle/demo.css @@ -0,0 +1,27 @@ +/** + * @license + * Copyright 2019 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. + */ +#map { + height: 100%; +} + +/* + * Optional: Makes the sample page fill the window. + */ +html, +body { + height: 100%; + margin: 0; + padding: 0; +} + +gmp-map { + height: 400px; +} + diff --git a/dist/samples/web-components-accessibility/jsfiddle/demo.details b/dist/samples/web-components-accessibility/jsfiddle/demo.details new file mode 100644 index 0000000000..99cf731fce --- /dev/null +++ b/dist/samples/web-components-accessibility/jsfiddle/demo.details @@ -0,0 +1,7 @@ +name: Advanced Marker Accessibility with web components +authors: + - Justin Poehnelt +tags: + - google maps +load_type: h +description: Sample code for Google Maps Platform JavaScript API diff --git a/dist/samples/web-components-accessibility/jsfiddle/demo.html b/dist/samples/web-components-accessibility/jsfiddle/demo.html new file mode 100644 index 0000000000..b1ccefa8a8 --- /dev/null +++ b/dist/samples/web-components-accessibility/jsfiddle/demo.html @@ -0,0 +1,48 @@ + + + + + Advanced Marker Accessibility with web components + + + + + + + + + + + + + + + + + + diff --git a/dist/samples/web-components-accessibility/jsfiddle/demo.js b/dist/samples/web-components-accessibility/jsfiddle/demo.js new file mode 100644 index 0000000000..ca0c20f410 --- /dev/null +++ b/dist/samples/web-components-accessibility/jsfiddle/demo.js @@ -0,0 +1,33 @@ +/** + * @license + * Copyright 2019 Google LLC. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 + */ +async function initMap() { + const { InfoWindow } = await google.maps.importLibrary("maps"); + const { PinElement } = await google.maps.importLibrary("marker"); + + console.log("Maps JavaScript API loaded."); + + // Return an array of markers. + const advancedMarkers = [...document.querySelectorAll("gmp-advanced-marker")]; + // Create a shared info window. + let infoWindow = new InfoWindow(); + + for (let i = 0; i < advancedMarkers.length; i++) { + const marker = advancedMarkers[i]; + const pin = new PinElement({ + glyph: `${i + 1}`, + scale: 1.5, + }); + + marker.appendChild(pin.element); + marker.addEventListener("gmp-click", () => { + infoWindow.close(); + infoWindow.setContent(marker.title); + infoWindow.open(marker.map, marker); + }); + } +} + +initMap(); diff --git a/dist/samples/web-components-accessibility/playground/index.html b/dist/samples/web-components-accessibility/playground/index.html new file mode 100644 index 0000000000..c060e3ffde --- /dev/null +++ b/dist/samples/web-components-accessibility/playground/index.html @@ -0,0 +1,51 @@ + + + Advanced Marker Accessibility with web components + + + + + + + + + + + + + + + + + + + + + + + diff --git a/dist/samples/web-components-accessibility/playground/index.ts b/dist/samples/web-components-accessibility/playground/index.ts new file mode 100644 index 0000000000..924437a552 --- /dev/null +++ b/dist/samples/web-components-accessibility/playground/index.ts @@ -0,0 +1,35 @@ +async function initMap(): Promise { + const { InfoWindow } = (await google.maps.importLibrary( + "maps", + )) as google.maps.MapsLibrary; + const { PinElement } = (await google.maps.importLibrary( + "marker", + )) as google.maps.MarkerLibrary; + console.log("Maps JavaScript API loaded."); + + // Return an array of markers. + const advancedMarkers = [...document.querySelectorAll("gmp-advanced-marker")]; + + // Create a shared info window. + let infoWindow = new InfoWindow(); + + for (let i = 0; i < advancedMarkers.length; i++) { + const marker = advancedMarkers[ + i + ] as google.maps.marker.AdvancedMarkerElement; + const pin = new PinElement({ + glyph: `${i + 1}`, + scale: 1.5, + }); + + marker.appendChild(pin.element); + marker.addEventListener("gmp-click", () => { + infoWindow.close(); + infoWindow.setContent(marker.title); + infoWindow.open(marker.map, marker); + }); + } +} + +initMap(); +export {}; diff --git a/dist/samples/web-components-accessibility/playground/package.json b/dist/samples/web-components-accessibility/playground/package.json new file mode 100644 index 0000000000..33703d5822 --- /dev/null +++ b/dist/samples/web-components-accessibility/playground/package.json @@ -0,0 +1,3 @@ +{ + "dependencies": {} +} \ No newline at end of file diff --git a/dist/samples/web-components-accessibility/playground/playground.ts.json b/dist/samples/web-components-accessibility/playground/playground.ts.json new file mode 100644 index 0000000000..dfc32121fc --- /dev/null +++ b/dist/samples/web-components-accessibility/playground/playground.ts.json @@ -0,0 +1,17 @@ +{ + "files": { + "index.ts": { + "label": "TypeScript" + }, + "style.css": { + "label": "CSS" + }, + "index.html": { + "label": "HTML" + }, + "../../../types/google-maps/index.d.ts": { + "label": "@types/google.maps", + "hidden": true + } + } +} \ No newline at end of file diff --git a/dist/samples/web-components-accessibility/playground/style.css b/dist/samples/web-components-accessibility/playground/style.css new file mode 100644 index 0000000000..5f1dfff74c --- /dev/null +++ b/dist/samples/web-components-accessibility/playground/style.css @@ -0,0 +1,22 @@ +/* + * Always set the map height explicitly to define the size of the div element + * that contains the map. + */ +#map { + height: 100%; +} + +/* + * Optional: Makes the sample page fill the window. + */ +html, +body { + height: 100%; + margin: 0; + padding: 0; +} + +gmp-map { + height: 400px; +} + diff --git a/dist/samples/web-components-events/app/index.html b/dist/samples/web-components-events/app/index.html index 6cd902dfd9..2aaf5489f5 100644 --- a/dist/samples/web-components-events/app/index.html +++ b/dist/samples/web-components-events/app/index.html @@ -7,7 +7,6 @@ Add a Map Web Component with Events - diff --git a/dist/samples/web-components-events/app/package.json b/dist/samples/web-components-events/app/package.json index 7bb5336324..1c946f0825 100644 --- a/dist/samples/web-components-events/app/package.json +++ b/dist/samples/web-components-events/app/package.json @@ -27,8 +27,8 @@ }, "devDependencies": { "@types/google.maps": "^3.53.5", - "typescript": "^5.2.2", - "vite": "^5.0.13" + "typescript": "^5.5.3", + "vite": "^5.4.6" }, "private": true, "dependencies": {} diff --git a/dist/samples/web-components-events/docs/index.html b/dist/samples/web-components-events/docs/index.html index 3a601aff9e..20740b1c2f 100644 --- a/dist/samples/web-components-events/docs/index.html +++ b/dist/samples/web-components-events/docs/index.html @@ -8,7 +8,6 @@ Add a Map Web Component with Events - diff --git a/dist/samples/web-components-events/iframe/index.html b/dist/samples/web-components-events/iframe/index.html index 79f369aa06..961b0cf988 100644 --- a/dist/samples/web-components-events/iframe/index.html +++ b/dist/samples/web-components-events/iframe/index.html @@ -7,10 +7,9 @@ Add a Map Web Component with Events - - - + + Add a Map Web Component with Events - + diff --git a/dist/samples/web-components-events/playground/index.html b/dist/samples/web-components-events/playground/index.html index 87300d8cd0..5789e8c9e1 100644 --- a/dist/samples/web-components-events/playground/index.html +++ b/dist/samples/web-components-events/playground/index.html @@ -1,7 +1,7 @@ Add a Map Web Component with Events - + @@ -17,17 +16,18 @@ center="37.4220656,-122.0840897" zoom="10" map-id="DEMO_MAP_ID" + style="height: 400px" > diff --git a/dist/samples/web-components-map/app/package.json b/dist/samples/web-components-map/app/package.json index d7f9637726..9661987f90 100644 --- a/dist/samples/web-components-map/app/package.json +++ b/dist/samples/web-components-map/app/package.json @@ -27,8 +27,8 @@ }, "devDependencies": { "@types/google.maps": "^3.53.5", - "typescript": "^5.2.2", - "vite": "^5.0.13" + "typescript": "^5.5.3", + "vite": "^5.4.6" }, "private": true, "dependencies": {} diff --git a/dist/samples/web-components-map/app/style.css b/dist/samples/web-components-map/app/style.css index 582e19d3dd..ab00e384fe 100644 --- a/dist/samples/web-components-map/app/style.css +++ b/dist/samples/web-components-map/app/style.css @@ -3,25 +3,3 @@ * Copyright 2019 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. - */ -#map { - height: 100%; -} - -/* - * Optional: Makes the sample page fill the window. - */ -html, -body { - height: 100%; - margin: 0; - padding: 0; -} - -gmp-map { - height: 400px; -} - diff --git a/dist/samples/web-components-map/docs/index.html b/dist/samples/web-components-map/docs/index.html index 6be724c12c..fd8cd48700 100644 --- a/dist/samples/web-components-map/docs/index.html +++ b/dist/samples/web-components-map/docs/index.html @@ -8,7 +8,6 @@ Add a Map using HTML - @@ -19,18 +18,19 @@ center="37.4220656,-122.0840897" zoom="10" map-id="DEMO_MAP_ID" + style="height: 400px" > diff --git a/dist/samples/web-components-map/docs/style.css b/dist/samples/web-components-map/docs/style.css index b56f4370f1..c37e7f3f22 100644 --- a/dist/samples/web-components-map/docs/style.css +++ b/dist/samples/web-components-map/docs/style.css @@ -4,28 +4,4 @@ * SPDX-License-Identifier: Apache-2.0 */ /* [START maps_web_components_map] */ -/* - * Always set the map height explicitly to define the size of the div element - * that contains the map. - */ -#map { - height: 100%; -} - -/* - * Optional: Makes the sample page fill the window. - */ -html, -body { - height: 100%; - margin: 0; - padding: 0; -} - -/* [START maps_web_components_map_style] */ -gmp-map { - height: 400px; -} - -/* [END maps_web_components_map_style] */ /* [END maps_web_components_map] */ \ No newline at end of file diff --git a/dist/samples/web-components-map/iframe/index.html b/dist/samples/web-components-map/iframe/index.html index eeef700878..8da6e4ba35 100644 --- a/dist/samples/web-components-map/iframe/index.html +++ b/dist/samples/web-components-map/iframe/index.html @@ -7,27 +7,26 @@ Add a Map using HTML - - - + diff --git a/dist/samples/web-components-map/jsfiddle/demo.css b/dist/samples/web-components-map/jsfiddle/demo.css index 582e19d3dd..ab00e384fe 100644 --- a/dist/samples/web-components-map/jsfiddle/demo.css +++ b/dist/samples/web-components-map/jsfiddle/demo.css @@ -3,25 +3,3 @@ * Copyright 2019 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. - */ -#map { - height: 100%; -} - -/* - * Optional: Makes the sample page fill the window. - */ -html, -body { - height: 100%; - margin: 0; - padding: 0; -} - -gmp-map { - height: 400px; -} - diff --git a/dist/samples/web-components-map/jsfiddle/demo.html b/dist/samples/web-components-map/jsfiddle/demo.html index b585c145d3..084c360f4c 100644 --- a/dist/samples/web-components-map/jsfiddle/demo.html +++ b/dist/samples/web-components-map/jsfiddle/demo.html @@ -7,7 +7,7 @@ Add a Map using HTML - + @@ -15,17 +15,18 @@ center="37.4220656,-122.0840897" zoom="10" map-id="DEMO_MAP_ID" + style="height: 400px" > diff --git a/dist/samples/web-components-map/playground/index.html b/dist/samples/web-components-map/playground/index.html index ea6ea584dd..536758f146 100644 --- a/dist/samples/web-components-map/playground/index.html +++ b/dist/samples/web-components-map/playground/index.html @@ -1,7 +1,7 @@ Add a Map using HTML - + diff --git a/dist/samples/web-components-map/playground/style.css b/dist/samples/web-components-map/playground/style.css index 5f1dfff74c..e69de29bb2 100644 --- a/dist/samples/web-components-map/playground/style.css +++ b/dist/samples/web-components-map/playground/style.css @@ -1,22 +0,0 @@ -/* - * Always set the map height explicitly to define the size of the div element - * that contains the map. - */ -#map { - height: 100%; -} - -/* - * Optional: Makes the sample page fill the window. - */ -html, -body { - height: 100%; - margin: 0; - padding: 0; -} - -gmp-map { - height: 400px; -} - diff --git a/dist/samples/web-components-markers/app/index.html b/dist/samples/web-components-markers/app/index.html index c84d99a4bb..3be1416cac 100644 --- a/dist/samples/web-components-markers/app/index.html +++ b/dist/samples/web-components-markers/app/index.html @@ -7,13 +7,17 @@ Add a Map with Markers using HTML - - + diff --git a/dist/samples/web-components-markers/app/package.json b/dist/samples/web-components-markers/app/package.json index 92a7ac9d10..44d7970ce7 100644 --- a/dist/samples/web-components-markers/app/package.json +++ b/dist/samples/web-components-markers/app/package.json @@ -27,8 +27,8 @@ }, "devDependencies": { "@types/google.maps": "^3.53.5", - "typescript": "^5.2.2", - "vite": "^5.0.13" + "typescript": "^5.5.3", + "vite": "^5.4.6" }, "private": true, "dependencies": {} diff --git a/dist/samples/web-components-markers/docs/index.html b/dist/samples/web-components-markers/docs/index.html index 6b0c6ebe04..21ed461b31 100644 --- a/dist/samples/web-components-markers/docs/index.html +++ b/dist/samples/web-components-markers/docs/index.html @@ -8,14 +8,18 @@ Add a Map with Markers using HTML - - + diff --git a/dist/samples/web-components-markers/iframe/index.html b/dist/samples/web-components-markers/iframe/index.html index 4c5104990d..d4ba8ab51a 100644 --- a/dist/samples/web-components-markers/iframe/index.html +++ b/dist/samples/web-components-markers/iframe/index.html @@ -7,13 +7,17 @@ Add a Map with Markers using HTML - - - + + - + diff --git a/dist/samples/web-components-markers/jsfiddle/demo.html b/dist/samples/web-components-markers/jsfiddle/demo.html index 81e4906121..45c7323d7c 100644 --- a/dist/samples/web-components-markers/jsfiddle/demo.html +++ b/dist/samples/web-components-markers/jsfiddle/demo.html @@ -7,11 +7,16 @@ Add a Map with Markers using HTML - + - + diff --git a/dist/samples/web-components-markers/playground/index.html b/dist/samples/web-components-markers/playground/index.html index d6c0c8770f..9ae11943cf 100644 --- a/dist/samples/web-components-markers/playground/index.html +++ b/dist/samples/web-components-markers/playground/index.html @@ -1,7 +1,7 @@ Add a Map with Markers using HTML - + - + diff --git a/dist/samples/webgl-deckgl/app/index.html b/dist/samples/webgl-deckgl/app/index.html index 6e2e8f057a..85ff2656fc 100644 --- a/dist/samples/webgl-deckgl/app/index.html +++ b/dist/samples/webgl-deckgl/app/index.html @@ -7,7 +7,7 @@ WebGL DeckGL OverlayView - + @@ -18,10 +18,10 @@
            + @@ -19,10 +19,10 @@
            + - - + +
            + @@ -17,10 +17,10 @@
            + @@ -20,10 +20,10 @@
            + @@ -17,10 +17,10 @@
            + @@ -18,10 +18,10 @@
            + - - + +
            + @@ -16,10 +16,10 @@
            + @@ -19,10 +19,10 @@
            @@ -16,10 +15,10 @@
            @@ -17,10 +16,10 @@
            - - + +
            +
            + +{% endblock %} + diff --git a/samples/rgm-autocomplete/index.tsx b/samples/rgm-autocomplete/index.tsx new file mode 100644 index 0000000000..7512d55f8e --- /dev/null +++ b/samples/rgm-autocomplete/index.tsx @@ -0,0 +1,121 @@ +/* + * Copyright 2024 Google LLC. All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +// [START maps_rgm_autocomplete] +import React, { useState, useEffect, useRef } from 'react'; +import { createRoot } from 'react-dom/client'; +import { + APIProvider, + ControlPosition, + MapControl, + AdvancedMarker, + Map, + useMap, + useMapsLibrary, + useAdvancedMarkerRef, + AdvancedMarkerRef +} from '@vis.gl/react-google-maps'; + +const API_KEY = + globalThis.GOOGLE_MAPS_API_KEY ?? ("YOUR_API_KEY"); + +const App = () => { + const [selectedPlace, setSelectedPlace] = + useState(null); + const [markerRef, marker] = useAdvancedMarkerRef(); + + return ( + + + + + +
            + +
            +
            + +
            + ); +}; + +interface MapHandlerProps { + place: google.maps.places.PlaceResult | null; + marker: google.maps.marker.AdvancedMarkerElement | null; +} + +const MapHandler = ({ place, marker }: MapHandlerProps) => { + const map = useMap(); + + useEffect(() => { + if (!map || !place || !marker) return; + + if (place.geometry?.viewport) { + map.fitBounds(place.geometry?.viewport); + } + marker.position = place.geometry?.location; + }, [map, place, marker]); + + return null; +}; + +interface PlaceAutocompleteProps { + onPlaceSelect: (place: google.maps.places.PlaceResult | null) => void; +} + +const PlaceAutocomplete = ({ onPlaceSelect }: PlaceAutocompleteProps) => { + const [placeAutocomplete, setPlaceAutocomplete] = + useState(null); + const inputRef = useRef(null); + const places = useMapsLibrary('places'); + + useEffect(() => { + if (!places || !inputRef.current) return; + + const options = { + fields: ['geometry', 'name', 'formatted_address'] + }; + + setPlaceAutocomplete(new places.Autocomplete(inputRef.current, options)); + }, [places]); + + useEffect(() => { + if (!placeAutocomplete) return; + + placeAutocomplete.addListener('place_changed', () => { + onPlaceSelect(placeAutocomplete.getPlace()); + }); + }, [onPlaceSelect, placeAutocomplete]); + + return ( +
            + +
            + ); +}; + +const root = createRoot(document.getElementById('app')!); +root.render(); + +export default App; +// [END maps_rgm_autocomplete] diff --git a/samples/rgm-autocomplete/rgm-autocomplete.json b/samples/rgm-autocomplete/rgm-autocomplete.json new file mode 100644 index 0000000000..818efcb05e --- /dev/null +++ b/samples/rgm-autocomplete/rgm-autocomplete.json @@ -0,0 +1,15 @@ +{ + "title": "React Google Maps - Autocomplete", + "libraries": [], + "version": "weekly", + "tag": "rgm_autocomplete", + "name": "rgm-autocomplete", + "pagination": { + "data": "mode", + "size": 1, + "alias": "mode" + }, + "tsx": true, + "permalink": "samples/{{ page.fileSlug }}/{{mode}}/{% if mode == 'jsfiddle' %}demo{% else %}index{% endif %}.{{ page.outputFileExtension }}", + "dependencies": ["@vis.gl/react-google-maps", "react", "react-dom", "vite"] + } \ No newline at end of file diff --git a/samples/rgm-autocomplete/style.scss b/samples/rgm-autocomplete/style.scss new file mode 100644 index 0000000000..5fb9deab54 --- /dev/null +++ b/samples/rgm-autocomplete/style.scss @@ -0,0 +1,52 @@ +/** + * @license + * Copyright 2024 Google LLC. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 + */ + +/* [START maps_rgm_autocomplete] */ +body { + margin: 0; + font-family: sans-serif; + } + #app { + width: 100vw; + height: 100vh; + } + +.autocomplete-container input, +.autocomplete-control { + box-sizing: border-box; +} + +.autocomplete-control { + margin: 24px; + background: #fff; +} + +.autocomplete-container { + width: 300px; +} +.autocomplete-container input { + width: 100%; + height: 40px; + padding: 0 12px; + font-size: 18px; +} + +.autocomplete-container .custom-list { + width: 100%; + list-style: none; + padding: 0; + margin: 0; +} + +.autocomplete-container .custom-list-item { + padding: 8px; +} + +.autocomplete-container .custom-list-item:hover { + background: lightgrey; + cursor: pointer; +} +/* [END maps_rgm_autocomplete] */ diff --git a/samples/rgm-basic-map/index.tsx b/samples/rgm-basic-map/index.tsx index 792227f864..c6f403b56a 100644 --- a/samples/rgm-basic-map/index.tsx +++ b/samples/rgm-basic-map/index.tsx @@ -15,15 +15,16 @@ */ // [START maps_rgm_basic_map] import React from 'react'; -import {createRoot} from 'react-dom/client'; - -import {APIProvider, Map} from '@vis.gl/react-google-maps'; +import { createRoot } from 'react-dom/client'; +import { APIProvider, Map } from '@vis.gl/react-google-maps'; const API_KEY = globalThis.GOOGLE_MAPS_API_KEY ?? ("YOUR_API_KEY"); const App = () => ( - + + + +{% extends '../../src/_includes/layout.njk'%} + +{% block polyfill %}{% endblock %} + +{% block resources %} + +{% endblock %} + +{% block api %}{% endblock %} + +{% block html %} +
            + +{% endblock %} diff --git a/samples/rgm-college-picker/index.tsx b/samples/rgm-college-picker/index.tsx new file mode 100644 index 0000000000..0d09d3077b --- /dev/null +++ b/samples/rgm-college-picker/index.tsx @@ -0,0 +1,137 @@ +/** + * @license + * Copyright 2024 Google LLC + * SPDX-License-Identifier: Apache-2.0 + */ + +// [START maps_rgm_college_picker] +import React, { useState, useRef } from 'react'; +import ReactDOM from 'react-dom/client'; +import { AdvancedMarker, Map, Pin, APIProvider } from '@vis.gl/react-google-maps'; +import { + PlaceReviews, + PlaceDataProvider, + PlaceDirectionsButton, + IconButton, + PlaceOverview, + SplitLayout, + OverlayLayout, + PlacePicker +} from '@googlemaps/extended-component-library/react'; +/** + * The below imports are necessary because we are creating refs of + * the OverlayLayout and PlacePicker components. You need to pass + * the ref property a web component type object. Imports from + * @googlemaps/extended-component-library/react are wrappers around + * the web components, not the components themselves. For the ref + * property we import the actual components and alias them for clarity. + */ +import { OverlayLayout as TOverlayLayout } from '@googlemaps/extended-component-library/overlay_layout.js'; +import { PlacePicker as TPlacePicker } from '@googlemaps/extended-component-library/place_picker.js'; + +const API_KEY = + globalThis.GOOGLE_MAPS_API_KEY ?? ("YOUR_API_KEY"); +const DEFAULT_CENTER = { lat: 38, lng: -98 }; +const DEFAULT_ZOOM = 4; +const DEFAULT_ZOOM_WITH_LOCATION = 16; +/** + * Sample app that helps users locate a college on the map, with place info such + * as ratings, photos, and reviews displayed on the side. + */ +const App = () => { + const overlayLayoutRef = useRef(null); + const pickerRef = useRef(null); + const [college, setCollege] = useState(undefined); + /** + * See https://lit.dev/docs/frameworks/react/#using-slots for why + * we need to wrap our custom elements in a div with a slot attribute. + */ + return ( +
            + + +
            + +
            + { + if (!pickerRef.current?.value) { + setCollege(undefined); + } else { + setCollege(pickerRef.current?.value); + } + }} + /> + +
            + overlayLayoutRef.current?.showOverlay()} + > + See Reviews + +
            +
            + + Directions + +
            +
            +
            +
            + overlayLayoutRef.current?.hideOverlay()} + > + Close + + + + +
            +
            +
            +
            + + {college?.location && ( + + + + )} + +
            +
            +
            +
            + ); +}; + +const root = ReactDOM.createRoot(document.getElementById('root')!); +root.render( + + + +); +// [END maps_rgm_college_picker] diff --git a/samples/rgm-college-picker/rgm-college-picker.json b/samples/rgm-college-picker/rgm-college-picker.json new file mode 100644 index 0000000000..dbfaa163b0 --- /dev/null +++ b/samples/rgm-college-picker/rgm-college-picker.json @@ -0,0 +1,15 @@ +{ + "title": "React Google Maps - College Picker App", + "libraries": [], + "version": "weekly", + "tag": "rgm_college_picker", + "name": "rgm-college-picker", + "pagination": { + "data": "mode", + "size": 1, + "alias": "mode" + }, + "tsx": true, + "permalink": "samples/{{ page.fileSlug }}/{{mode}}/{% if mode == 'jsfiddle' %}demo{% else %}index{% endif %}.{{ page.outputFileExtension }}", + "dependencies": ["@vis.gl/react-google-maps", "react", "react-dom", "vite"] + } \ No newline at end of file diff --git a/samples/rgm-college-picker/style.scss b/samples/rgm-college-picker/style.scss new file mode 100644 index 0000000000..797ca7bc0a --- /dev/null +++ b/samples/rgm-college-picker/style.scss @@ -0,0 +1,70 @@ +/** + * Copyright 2024 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * @license + * Copyright 2024 Google LLC + * SPDX-License-Identifier: Apache-2.0 + */ + +/* [START maps_rgm_college_picker] */ +body { + margin: 0; + font-family: sans-serif; +} +#root { + width: 100vw; + height: 100vh; +} + +.App { + --gmpx-color-surface: #f6f5ff; + --gmpx-color-on-primary: #f8e8ff; + --gmpx-color-on-surface: #000; + --gmpx-color-on-surface-variant: #636268; + --gmpx-color-primary: #8a5cf4; + --gmpx-fixed-panel-height-column-layout: 420px; + --gmpx-fixed-panel-width-row-layout: 340px; + background: var(--gmpx-color-surface); + inset: 0; + position: fixed; +} + +.MainContainer { + display: flex; + flex-direction: column; +} + +.SplitLayoutContainer { + height: 100%; +} + +.CollegePicker { + --gmpx-color-surface: #fff; + flex-grow: 1; + margin: 1rem; +} + +.CloseButton { + display: block; + margin: 1rem; +} + +.SlotDiv { + display: contents; +} +/* [END maps_rgm_college_picker] */ + + + diff --git a/samples/streetview-overlays/index.ts b/samples/streetview-overlays/index.ts index 6b127f8e94..5f732e76cd 100644 --- a/samples/streetview-overlays/index.ts +++ b/samples/streetview-overlays/index.ts @@ -23,27 +23,37 @@ function initMap(): void { document .getElementById("toggle")! .addEventListener("click", toggleStreetView); + + const cafeIcon = document.createElement("img"); + cafeIcon.src = "https://developers.google.com/maps/documentation/javascript/examples/full/images/cafe_icon.svg"; + + const dollarIcon = document.createElement("img"); + dollarIcon.src = "https://developers.google.com/maps/documentation/javascript/examples/full/images/bank_icon.svg"; + + const busIcon = document.createElement("img"); + busIcon.src = "https://developers.google.com/maps/documentation/javascript/examples/full/images/bus_icon.svg"; + // Set up the markers on the map const cafeMarker = new google.maps.Marker({ position: { lat: 40.730031, lng: -73.991428 }, map, - icon: "https://chart.apis.google.com/chart?chst=d_map_pin_icon&chld=cafe|FFFF00", title: "Cafe", + icon: cafeIcon.src, }); const bankMarker = new google.maps.Marker({ position: { lat: 40.729681, lng: -73.991138 }, map, - icon: "https://chart.apis.google.com/chart?chst=d_map_pin_icon&chld=dollar|FFFF00", title: "Bank", + icon: dollarIcon.src, }); const busMarker = new google.maps.Marker({ position: { lat: 40.729559, lng: -73.990741 }, map, - icon: "https://chart.apis.google.com/chart?chst=d_map_pin_icon&chld=bus|FFFF00", title: "Bus Stop", + icon: busIcon.src, }); // We get the map's default panorama and set up some defaults. diff --git a/samples/streetview-overlays/streetview-overlays.json b/samples/streetview-overlays/streetview-overlays.json index c0f258d967..4c76bbced3 100644 --- a/samples/streetview-overlays/streetview-overlays.json +++ b/samples/streetview-overlays/streetview-overlays.json @@ -1,7 +1,7 @@ { "title": "Overlays Within Street View", "callback": "initMap", - "libraries": [], + "libraries": ["marker"], "version": "weekly", "tag": "streetview_overlays", "name": "streetview-overlays", diff --git a/samples/web-components-accessibility/index.njk b/samples/web-components-accessibility/index.njk new file mode 100644 index 0000000000..c592136c8e --- /dev/null +++ b/samples/web-components-accessibility/index.njk @@ -0,0 +1,17 @@ + + +{% extends '../../src/_includes/layout.njk'%} {% block html %} + + + + + + + + + +{% endblock %} \ No newline at end of file diff --git a/samples/web-components-accessibility/index.ts b/samples/web-components-accessibility/index.ts new file mode 100644 index 0000000000..f0d8af8a95 --- /dev/null +++ b/samples/web-components-accessibility/index.ts @@ -0,0 +1,41 @@ +/** + * @license + * Copyright 2019 Google LLC. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 + */ + +// [START maps_web_components_accessibility] +async function initMap(): Promise { + const { InfoWindow } = await google.maps.importLibrary("maps") as google.maps.MapsLibrary; + const { PinElement } = await google.maps.importLibrary("marker") as google.maps.MarkerLibrary; + console.log('Maps JavaScript API loaded.'); + + // [START maps_web_components_accessibility_query] + // Return an array of markers. + const advancedMarkers = [...document.querySelectorAll('gmp-advanced-marker')]; + // [END maps_web_components_accessibility_query] + + // [START maps_web_components_accessibility_iterate] + // Create a shared info window. + let infoWindow = new InfoWindow(); + + for (let i = 0; i < advancedMarkers.length; i++) { + const marker = advancedMarkers[i] as google.maps.marker.AdvancedMarkerElement; + const pin = new PinElement({ + glyph: `${i + 1}`, + scale: 1.5, + }); + + marker.appendChild(pin.element); + marker.addEventListener('gmp-click', () => { + infoWindow.close(); + infoWindow.setContent(marker.title); + infoWindow.open(marker.map, marker); + }); + } + // [END maps_web_components_accessibility_iterate] +} + +initMap(); +// [END maps_web_components_accessibility] +export { }; \ No newline at end of file diff --git a/samples/web-components-accessibility/style.scss b/samples/web-components-accessibility/style.scss new file mode 100644 index 0000000000..ee584045b8 --- /dev/null +++ b/samples/web-components-accessibility/style.scss @@ -0,0 +1,17 @@ +/** + * @license + * Copyright 2019 Google LLC. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 + */ + + @use 'sass:meta'; // To enable @use via meta.load-css and keep comments in order + + /* [START maps_web_components_accessibility] */ + @include meta.load-css("../../shared/scss/default.scss"); + + gmp-map { + height: 400px; + } + + /* [END maps_web_components_accessibility] */ + \ No newline at end of file diff --git a/samples/web-components-accessibility/web-components-accessibility.json b/samples/web-components-accessibility/web-components-accessibility.json new file mode 100644 index 0000000000..127b3dd3f3 --- /dev/null +++ b/samples/web-components-accessibility/web-components-accessibility.json @@ -0,0 +1,13 @@ +{ + "title": "Advanced Marker Accessibility with web components", + "dynamic_import": "true", + "version": "beta", + "tag": "web_components_accessibility", + "name": "web-components-accessibility", + "pagination": { + "data": "mode", + "size": 1, + "alias": "mode" + }, + "permalink": "samples/{{ page.fileSlug }}/{{mode}}/{% if mode == 'jsfiddle' %}demo{% else %}index{% endif %}.{{ page.outputFileExtension }}" +} \ No newline at end of file diff --git a/samples/web-components-map/index.njk b/samples/web-components-map/index.njk index e5ced4ab90..dae9b54b4f 100644 --- a/samples/web-components-map/index.njk +++ b/samples/web-components-map/index.njk @@ -6,6 +6,6 @@ --> {% extends '../../src/_includes/layout.njk'%} {% block html %} - + {% endblock %} diff --git a/samples/web-components-map/style.scss b/samples/web-components-map/style.scss index 840a46ca3f..fbd1eced3d 100644 --- a/samples/web-components-map/style.scss +++ b/samples/web-components-map/style.scss @@ -7,10 +7,4 @@ @use 'sass:meta'; // To enable @use via meta.load-css and keep comments in order /* [START maps_web_components_map] */ -@include meta.load-css("../../shared/scss/default.scss"); -/* [START maps_web_components_map_style] */ -gmp-map { - height: 400px; -} -/* [END maps_web_components_map_style] */ /* [END maps_web_components_map] */ diff --git a/samples/web-components-map/web-components-map.json b/samples/web-components-map/web-components-map.json index 4679b7ffdd..9503de9b89 100644 --- a/samples/web-components-map/web-components-map.json +++ b/samples/web-components-map/web-components-map.json @@ -1,7 +1,6 @@ { "title": "Add a Map using HTML", - "callback": "initMap", - "libraries": [], + "libraries": ["maps"], "version": "beta", "tag": "web_components_map", "name": "web-components-map", @@ -11,4 +10,4 @@ "alias": "mode" }, "permalink": "samples/{{ page.fileSlug }}/{{mode}}/{% if mode == 'jsfiddle' %}demo{% else %}index{% endif %}.{{ page.outputFileExtension }}" - } \ No newline at end of file + } diff --git a/samples/web-components-markers/index.njk b/samples/web-components-markers/index.njk index 6be7a4467f..0e03faba04 100644 --- a/samples/web-components-markers/index.njk +++ b/samples/web-components-markers/index.njk @@ -6,7 +6,7 @@ --> {% extends '../../src/_includes/layout.njk'%} {% block html %} - + diff --git a/samples/web-components-markers/web-components-markers.json b/samples/web-components-markers/web-components-markers.json index 90bcace208..299ca14d21 100644 --- a/samples/web-components-markers/web-components-markers.json +++ b/samples/web-components-markers/web-components-markers.json @@ -1,7 +1,6 @@ { "title": "Add a Map with Markers using HTML", - "callback": "initMap", - "libraries": ["marker"], + "libraries": ["maps,marker"], "version": "beta", "tag": "web_components_markers", "name": "web-components-markers", @@ -11,4 +10,4 @@ "alias": "mode" }, "permalink": "samples/{{ page.fileSlug }}/{{mode}}/{% if mode == 'jsfiddle' %}demo{% else %}index{% endif %}.{{ page.outputFileExtension }}" - } \ No newline at end of file + } diff --git a/src/_includes/layout.njk b/src/_includes/layout.njk index 705443c3a7..418b27f774 100644 --- a/src/_includes/layout.njk +++ b/src/_includes/layout.njk @@ -9,7 +9,6 @@ {{ title }} - {% block polyfill -%}{% endblock -%} {% block external -%}{% endblock -%} {% if mode == "playground" %} @@ -40,16 +39,16 @@ ({key: "{{GOOGLE_MAPS_API_KEY}}"{% if libraries|length %}, libraries: {{ libraries }}{% endif %}{% if version|length %}, v: "{{ version }}"{% endif %}{% if language|length %}, language: "{{ language }}"{% endif %}{% if region|length %}, region: "{{ region }}"{% endif %}{% if solutionChannel|length %}, solutionChannel: "{{ solutionChannel }}"{% endif %}{% if authReferrerPolicy|length %}, authReferrerPolicy: "{{ authReferrerPolicy }}"{% endif %}}); {% else %} + src="https://maps.googleapis.com/maps/api/js?key={{GOOGLE_MAPS_API_KEY}}{% if callback %}&callback={{ callback }}{% endif %}{% if libraries|length %}&libraries={{ libraries }}{% endif %}&v={{ version }}{% if language %}&language={{ language }}{% endif %}{% if region %}®ion={{ region }}{% endif %}" defer> {% endif -%} {% endblock %} - \ No newline at end of file + diff --git a/tsconfig.json b/tsconfig.json index c7465eb9be..0c32e636cd 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -5,7 +5,7 @@ "strict": true, "noImplicitAny": false, "lib": ["esnext", "es6", "dom", "dom.iterable"], - "moduleResolution": "Node", + "moduleResolution": "Bundler", "jsx": "preserve", "esModuleInterop": true, "experimentalDecorators": true