Skip to content

Commit 7a48ee0

Browse files
authored
docs: add example using SuperClusterViewportAlgorithm (#709)
1 parent 70818f1 commit 7a48ee0

File tree

5 files changed

+89
-4
lines changed

5 files changed

+89
-4
lines changed

examples/bench-leaflet.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
import points from "./realworld.json";
1818

19-
declare let L: any;
19+
declare let L: any; /* eslint-disable-line @typescript-eslint/no-explicit-any */
2020

2121
const tiles = L.tileLayer("//{s}.tile.openstreetmap.org/{z}/{x}/{y}.png", {
2222
maxZoom: 18,

examples/bench-legacy-viewport.html

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<!DOCTYPE html>
2+
<!--
3+
Copyright 2023 Google LLC
4+
5+
Licensed under the Apache License, Version 2.0 (the "License");
6+
you may not use this file except in compliance with the License.
7+
You may obtain a copy of the License at
8+
9+
http://www.apache.org/licenses/LICENSE-2.0
10+
11+
Unless required by applicable law or agreed to in writing, software
12+
distributed under the License is distributed on an "AS IS" BASIS,
13+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
See the License for the specific language governing permissions and
15+
limitations under the License.
16+
-->
17+
18+
<html>
19+
<head>
20+
<style>
21+
html,
22+
body,
23+
#map {
24+
margin: 0;
25+
height: 100%;
26+
}
27+
</style>
28+
</head>
29+
<body>
30+
<div id="map"></div>
31+
<script src="bench-legacy-viewport.js" type="module"></script>
32+
<script src="vendor.js" type="module"></script>
33+
</body>
34+
</html>

examples/bench-legacy-viewport.ts

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
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 { getLoaderOptions } from "./config";
18+
import { Loader } from "@googlemaps/js-api-loader";
19+
import { MarkerClusterer, SuperClusterViewportAlgorithm } 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+
};
28+
29+
new Loader(getLoaderOptions()).load().then(() => {
30+
const element = document.getElementById("map");
31+
32+
const map = new google.maps.Map(element, mapOptions);
33+
34+
const markers = (points as [number, number, string][]).map(
35+
([lat, lng, label]) =>
36+
new google.maps.Marker({ position: { lat, lng }, label })
37+
);
38+
39+
const markerCluster = new MarkerClusterer({
40+
markers,
41+
algorithm: new SuperClusterViewportAlgorithm({
42+
maxZoom: 30,
43+
viewportPadding: 60,
44+
}),
45+
});
46+
47+
markerCluster.setMap(map);
48+
});

examples/index.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ <h1>Google Maps JavaScript MarkerClusterer</h1>
3535
<li><a href="./defaults/index.html">Defaults</a></li>
3636
<li><a href="./bench-legacy/index.html">Benchmark legacy markers</a></li>
3737
<li><a href="./bench-advanced/index.html">Benchmark advanced markers</a></li>
38+
<li><a href="./bench-legacyviewport/index.html">Benchmark legacy markers with viewport</a></li>
3839
<li><a href="./bench-leaflet/index.html">Benchmark Leaflet markers</a></li>
3940
</ul>
4041
<label>Google Maps API Key<input id="key" style="width: 400px"></input></label>

src/marker-utils.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,16 @@
1515
*/
1616

1717
/**
18-
* util class that creates a common set of convenience functions to wrap
19-
* shared behavior of Advanced Markers and Markers.
18+
* Supports markers of either either "legacy" or "advanced" types.
2019
*/
21-
2220
export type Marker =
2321
| google.maps.Marker
2422
| google.maps.marker.AdvancedMarkerElement;
2523

24+
/**
25+
* util class that creates a common set of convenience functions to wrap
26+
* shared behavior of Advanced Markers and Markers.
27+
*/
2628
export class MarkerUtils {
2729
public static isAdvancedMarkerAvailable(map: google.maps.Map): boolean {
2830
return (

0 commit comments

Comments
 (0)