|
| 1 | +/** |
| 2 | + * Copyright 2023 Google LLC |
| 3 | + * |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | + * you may not use this file except in compliance with the License. |
| 6 | + * You may obtain a copy of the License at |
| 7 | + * |
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | + * |
| 10 | + * Unless required by applicable law or agreed to in writing, software |
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | + * See the License for the specific language governing permissions and |
| 14 | + * limitations under the License. |
| 15 | + */ |
| 16 | + |
| 17 | +import { MAP_ID, getLoaderOptions } from "./config"; |
| 18 | +import { Loader } from "@googlemaps/js-api-loader"; |
| 19 | +import { MarkerClusterer } from "../src"; |
| 20 | +import points from "./realworld.json"; |
| 21 | + |
| 22 | +// Do not set the mapId to force legacy markers |
| 23 | +const mapOptions: google.maps.MapOptions = { |
| 24 | + center: { lat: -37.89, lng: 175.46 }, |
| 25 | + zoom: 8, |
| 26 | + maxZoom: 18, |
| 27 | + mapId: MAP_ID, |
| 28 | +}; |
| 29 | + |
| 30 | +new Loader(getLoaderOptions()).load().then(() => { |
| 31 | + const element = document.getElementById("map"); |
| 32 | + |
| 33 | + const map = new google.maps.Map(element, mapOptions); |
| 34 | + |
| 35 | + const markers = (points as [number, number, string][]).map( |
| 36 | + ([lat, lng, title]) => |
| 37 | + new google.maps.marker.AdvancedMarkerElement({ |
| 38 | + position: { lat, lng }, |
| 39 | + map, |
| 40 | + title, |
| 41 | + }) |
| 42 | + ); |
| 43 | + |
| 44 | + const markerCluster = new MarkerClusterer({ |
| 45 | + markers, |
| 46 | + algorithmOptions: { maxZoom: 30 }, |
| 47 | + }); |
| 48 | + |
| 49 | + markerCluster.setMap(map); |
| 50 | +}); |
0 commit comments