-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: examples updated and cleaned up (#7)
* fix: update html examples HTML examples were still using the prerelease versions for the library, these are now replaced with files loaded from unpkg.com. * fix: add minimal typescript/vite example * fix: cleanup playground, remove prerelease content
- Loading branch information
1 parent
d96e6b0
commit fd3be63
Showing
14 changed files
with
798 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
# Advanced Markers Utils – HTML Examples | ||
|
||
This directory contains examples for the different ways to use | ||
`@googlemaps/adv-markers-utils` in a plain html file without needing a | ||
bundler or similar. | ||
|
||
- **`esm.html`** shows how to load the library from a CDN | ||
([unpkg.com](https://unpkg.com) in this example) as a native ES module. | ||
- **`importmap.html`** is similar, but it uses [importmaps][mdn_importmap] | ||
to load the library. | ||
- **`umd.html`** uses the UMD build of the library for older browsers. | ||
|
||
To run these examples, you only need an HTTP-Server and [a Google Maps API Key][gmp_apikey]. | ||
If you have node.js installed, you can start a server by running the command | ||
|
||
npx http-server | ||
|
||
in this directory and opening the URL shown in your browser (typically http://localhost:8080). | ||
The site will then ask for the Google Maps API Key to use and show the map with the marker. | ||
|
||
[mdn_importmap]: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/script/type/importmap | ||
[gmp_apikey]: https://developers.google.com/maps/documentation/javascript/get-api-key#create-api-keys |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
/node_modules |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
# Advanced Markers Utils – TypeScript / vite Example | ||
|
||
This directory contains a minimal example application built with typescript/vite. | ||
|
||
To run these examples, you need [a Google Maps API Key][gmp_apikey]. change into the `./examples/typescript`-directory and run | ||
|
||
npm install | ||
npm start | ||
|
||
This will start the vite development-server, and print the URL to the console (typically http://localhost:5173/). | ||
When opening the site, it will ask for the Google Maps API Key. | ||
|
||
[gmp_apikey]: https://developers.google.com/maps/documentation/javascript/get-api-key#create-api-keys |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
/* | ||
* Copyright 2023 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. | ||
*/ | ||
|
||
/// <reference types="vite/client" /> | ||
interface ImportMetaEnv { | ||
readonly VITE_GOOGLEMAPS_API_KEY: string; | ||
} | ||
interface ImportMeta { | ||
readonly env: ImportMetaEnv; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
<!doctype html> | ||
<!-- | ||
Copyright 2023 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. | ||
--> | ||
|
||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8" /> | ||
<title>@googlemaps/marker - vite / typescript example</title> | ||
<style> | ||
body { | ||
margin: 0; | ||
} | ||
#map { | ||
width: 100vw; | ||
height: 100vh; | ||
} | ||
</style> | ||
</head> | ||
<body> | ||
<div id="map"></div> | ||
<script type="module" src="./main.ts"></script> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
/* | ||
* Copyright 2023 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. | ||
*/ | ||
|
||
import {Loader} from '@googlemaps/js-api-loader'; | ||
import {Marker} from '@googlemaps/adv-markers-utils'; | ||
|
||
const mapDiv = document.querySelector('#map') as HTMLElement; | ||
|
||
async function main() { | ||
const apiKey = getApiKey(); | ||
console.log('loading maps API with key: ' + apiKey); | ||
|
||
const loader = new Loader({apiKey}); | ||
|
||
const {Map} = await loader.importLibrary('maps'); | ||
await loader.importLibrary('marker'); | ||
|
||
const map = new Map(mapDiv, { | ||
mapId: 'bf51a910020fa25a', | ||
center: {lat: 53.55, lng: 10.01}, | ||
zoom: 12 | ||
}); | ||
|
||
const marker = new Marker(); | ||
|
||
marker.position = {lat: 53.55, lng: 10.01}; | ||
marker.map = map; | ||
} | ||
|
||
// get Google Maps API Key from url or environment | ||
function getApiKey() { | ||
const url = new URL(location.href); | ||
const apiKey = | ||
url.searchParams.get('apiKey') || import.meta.env.VITE_GOOGLEMAPS_API_KEY; | ||
|
||
if (!apiKey) { | ||
const key = prompt( | ||
'Please provide your Google Maps API key in the URL\n' + | ||
'(using the parameter `?apiKey=YOUR_API_KEY_HERE`) or enter it here:' | ||
); | ||
|
||
if (key) { | ||
url.searchParams.set('apiKey', key); | ||
location.replace(url.toString()); | ||
} | ||
} | ||
|
||
return apiKey; | ||
} | ||
|
||
main().catch(err => console.error(err)); |
Oops, something went wrong.