Skip to content

Commit a05475e

Browse files
committed
feat(google-maps): deprecate marker cluster component
Deprecates the existing `MapMarkerClusterer`, because it's based on a deprecated library that doesn't support advanced markers. A new clusterer component will be introduced that supports both regular markers and advanced ones, and is based on the current marker library. BREAKING CHANGE: * The new @googlemaps/markerclusterer API should be imported instead of the old one. Read more at: https://github.com/googlemaps/js-markerclusterer * The `MapMarkerClusterer` class has been renamed to `DeprecatedMapMarkerClusterer`. * The `map-marker-clusterer` selector has been changed to `deprecated-map-marker-clusterer`.
1 parent b84ebdc commit a05475e

File tree

12 files changed

+162
-149
lines changed

12 files changed

+162
-149
lines changed

src/dev-app/google-map/google-map-demo.html

+2-2
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
(mapRightclick)="handleRightclick()"
1111
[mapTypeId]="mapTypeId"
1212
[mapId]="mapId">
13-
<map-marker-clusterer [imagePath]="markerClustererImagePath">
13+
<deprecated-map-marker-clusterer [imagePath]="markerClustererImagePath">
1414
<map-marker #firstMarker="mapMarker"
1515
[position]="center"
1616
(mapClick)="infoWindow.open(firstMarker)"></map-marker>
@@ -20,7 +20,7 @@
2020
[options]="markerOptions"
2121
(mapClick)="infoWindow.open(marker)"></map-marker>
2222
}
23-
</map-marker-clusterer>
23+
</deprecated-map-marker-clusterer>
2424
@if (hasAdvancedMarker) {
2525
<map-advanced-marker
2626
#secondMarker="mapAdvancedMarker"

src/dev-app/google-map/google-map-demo.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ import {
2626
MapInfoWindow,
2727
MapKmlLayer,
2828
MapMarker,
29-
MapMarkerClusterer,
29+
DeprecatedMapMarkerClusterer,
3030
MapPolygon,
3131
MapPolyline,
3232
MapRectangle,
@@ -76,7 +76,7 @@ let apiLoadingPromise: Promise<unknown> | null = null;
7676
MapInfoWindow,
7777
MapKmlLayer,
7878
MapMarker,
79-
MapMarkerClusterer,
79+
DeprecatedMapMarkerClusterer,
8080
MapAdvancedMarker,
8181
MapPolygon,
8282
MapPolyline,

src/google-maps/map-marker-clusterer/README.md renamed to src/google-maps/deprecated-map-marker-clusterer/README.md

+9-6
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
1-
#MapMarkerClusterer
1+
# Deprecation warning ⚠️
2+
This component is based on the deprecated `@googlemaps/markerclustererplus` library. Use the `map-marker-clusterer` component instead.
23

3-
The `MapMarkerClusterer` component wraps the [`MarkerClusterer` class](https://googlemaps.github.io/js-markerclustererplus/classes/markerclusterer.html) from the [Google Maps JavaScript MarkerClustererPlus Library](https://github.com/googlemaps/js-markerclustererplus). The `MapMarkerClusterer` component displays a cluster of markers that are children of the `<map-marker-clusterer>` tag. Unlike the other Google Maps components, MapMarkerClusterer does not have an `options` input, so any input (listed in the [documentation](https://googlemaps.github.io/js-markerclustererplus/index.html) for the `MarkerClusterer` class) should be set directly.
4+
## DeprecatedMapMarkerClusterer
5+
6+
The `DeprecatedMapMarkerClusterer` component wraps the [`MarkerClusterer` class](https://googlemaps.github.io/js-markerclustererplus/classes/markerclusterer.html) from the [Google Maps JavaScript MarkerClustererPlus Library](https://github.com/googlemaps/js-markerclustererplus). The `DeprecatedMapMarkerClusterer` component displays a cluster of markers that are children of the `<deprecated-map-marker-clusterer>` tag. Unlike the other Google Maps components, MapMarkerClusterer does not have an `options` input, so any input (listed in the [documentation](https://googlemaps.github.io/js-markerclustererplus/index.html) for the `MarkerClusterer` class) should be set directly.
47

58
## Loading the Library
69

@@ -17,12 +20,12 @@ Additional information can be found by looking at [Marker Clustering](https://de
1720
```typescript
1821
// google-map-demo.component.ts
1922
import {Component} from '@angular/core';
20-
import {GoogleMap, MapMarker, MapMarkerClusterer} from '@angular/google-maps';
23+
import {GoogleMap, MapMarker, DeprecatedMapMarkerClusterer} from '@angular/google-maps';
2124

2225
@Component({
2326
selector: 'google-map-demo',
2427
templateUrl: 'google-map-demo.html',
25-
imports: [GoogleMap, MapMarker, MapMarkerClusterer],
28+
imports: [GoogleMap, MapMarker, DeprecatedMapMarkerClusterer],
2629
})
2730
export class GoogleMapDemo {
2831
center: google.maps.LatLngLiteral = {lat: 24, lng: 12};
@@ -45,10 +48,10 @@ export class GoogleMapDemo {
4548
[center]="center"
4649
[zoom]="zoom"
4750
(mapClick)="addMarker($event)">
48-
<map-marker-clusterer [imagePath]="markerClustererImagePath">
51+
<deprecated-map-marker-clusterer [imagePath]="markerClustererImagePath">
4952
@for (position of markerPositions; track position) {
5053
<map-marker [position]="position" />
5154
}
52-
</map-marker-clusterer>
55+
</deprecated-map-marker-clusterer>
5356
</google-map>
5457
```

src/google-maps/map-marker-clusterer/map-marker-clusterer.spec.ts renamed to src/google-maps/deprecated-map-marker-clusterer/deprecated-map-marker-clusterer.spec.ts

+16-12
Original file line numberDiff line numberDiff line change
@@ -6,21 +6,21 @@ import {MapMarker} from '../map-marker/map-marker';
66
import {
77
createMapConstructorSpy,
88
createMapSpy,
9-
createMarkerClustererConstructorSpy,
10-
createMarkerClustererSpy,
9+
createDeprecatedMarkerClustererConstructorSpy,
10+
createDeprecatedMarkerClustererSpy,
1111
createMarkerConstructorSpy,
1212
createMarkerSpy,
1313
} from '../testing/fake-google-map-utils';
14-
import {MapMarkerClusterer} from './map-marker-clusterer';
14+
import {DeprecatedMapMarkerClusterer} from './deprecated-map-marker-clusterer';
1515
import {
1616
AriaLabelFn,
1717
Calculator,
1818
ClusterIconStyle,
1919
MarkerClusterer,
2020
MarkerClustererOptions,
21-
} from './marker-clusterer-types';
21+
} from './deprecated-marker-clusterer-types';
2222

23-
describe('MapMarkerClusterer', () => {
23+
describe('DeprecatedMapMarkerClusterer', () => {
2424
let mapSpy: jasmine.SpyObj<google.maps.Map>;
2525
let markerClustererSpy: jasmine.SpyObj<MarkerClusterer>;
2626
let markerClustererConstructorSpy: jasmine.Spy;
@@ -39,8 +39,9 @@ describe('MapMarkerClusterer', () => {
3939
return createMarkerSpy({});
4040
});
4141

42-
markerClustererSpy = createMarkerClustererSpy();
43-
markerClustererConstructorSpy = createMarkerClustererConstructorSpy(markerClustererSpy);
42+
markerClustererSpy = createDeprecatedMarkerClustererSpy();
43+
markerClustererConstructorSpy =
44+
createDeprecatedMarkerClustererConstructorSpy(markerClustererSpy);
4445

4546
fixture = TestBed.createComponent(TestApp);
4647
});
@@ -52,7 +53,10 @@ describe('MapMarkerClusterer', () => {
5253

5354
it('throws an error if the clustering library has not been loaded', fakeAsync(() => {
5455
(window as any).MarkerClusterer = undefined;
55-
markerClustererConstructorSpy = createMarkerClustererConstructorSpy(markerClustererSpy, false);
56+
markerClustererConstructorSpy = createDeprecatedMarkerClustererConstructorSpy(
57+
markerClustererSpy,
58+
false,
59+
);
5660

5761
expect(() => {
5862
fixture.detectChanges();
@@ -304,7 +308,7 @@ describe('MapMarkerClusterer', () => {
304308
selector: 'test-app',
305309
template: `
306310
<google-map>
307-
<map-marker-clusterer
311+
<deprecated-map-marker-clusterer
308312
[ariaLabelFn]="ariaLabelFn"
309313
[averageCenter]="averageCenter"
310314
[batchSize]="batchSize"
@@ -335,14 +339,14 @@ describe('MapMarkerClusterer', () => {
335339
@if (state === 'state2') {
336340
<map-marker />
337341
}
338-
</map-marker-clusterer>
342+
</deprecated-map-marker-clusterer>
339343
</google-map>
340344
`,
341345
standalone: true,
342-
imports: [GoogleMap, MapMarker, MapMarkerClusterer],
346+
imports: [GoogleMap, MapMarker, DeprecatedMapMarkerClusterer],
343347
})
344348
class TestApp {
345-
@ViewChild(MapMarkerClusterer) markerClusterer: MapMarkerClusterer;
349+
@ViewChild(DeprecatedMapMarkerClusterer) markerClusterer: DeprecatedMapMarkerClusterer;
346350

347351
ariaLabelFn?: AriaLabelFn;
348352
averageCenter?: boolean;

src/google-maps/map-marker-clusterer/map-marker-clusterer.ts renamed to src/google-maps/deprecated-map-marker-clusterer/deprecated-map-marker-clusterer.ts

+10-4
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ import {
3939
ClusterIconStyle,
4040
MarkerClusterer as MarkerClustererInstance,
4141
MarkerClustererOptions,
42-
} from './marker-clusterer-types';
42+
} from './deprecated-marker-clusterer-types';
4343

4444
/** Default options for a clusterer. */
4545
const DEFAULT_CLUSTERER_OPTIONS: MarkerClustererOptions = {};
@@ -52,17 +52,23 @@ declare const MarkerClusterer: typeof MarkerClustererInstance;
5252

5353
/**
5454
* Angular component for implementing a Google Maps Marker Clusterer.
55-
*
5655
* See https://developers.google.com/maps/documentation/javascript/marker-clustering
56+
*
57+
* @deprecated This component is using a deprecated clustering implementation. Use the
58+
* `map-marker-clusterer` component instead.
59+
* @breaking-change 21.0.0
60+
*
5761
*/
5862
@Component({
59-
selector: 'map-marker-clusterer',
63+
selector: 'deprecated-map-marker-clusterer',
6064
exportAs: 'mapMarkerClusterer',
6165
changeDetection: ChangeDetectionStrategy.OnPush,
6266
template: '<ng-content/>',
6367
encapsulation: ViewEncapsulation.None,
6468
})
65-
export class MapMarkerClusterer implements OnInit, AfterContentInit, OnChanges, OnDestroy {
69+
export class DeprecatedMapMarkerClusterer
70+
implements OnInit, AfterContentInit, OnChanges, OnDestroy
71+
{
6672
private readonly _googleMap = inject(GoogleMap);
6773
private readonly _ngZone = inject(NgZone);
6874
private readonly _currentMarkers = new Set<google.maps.Marker>();

src/google-maps/google-maps-module.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import {MapGroundOverlay} from './map-ground-overlay/map-ground-overlay';
1717
import {MapInfoWindow} from './map-info-window/map-info-window';
1818
import {MapKmlLayer} from './map-kml-layer/map-kml-layer';
1919
import {MapMarker} from './map-marker/map-marker';
20-
import {MapMarkerClusterer} from './map-marker-clusterer/map-marker-clusterer';
20+
import {DeprecatedMapMarkerClusterer} from './deprecated-map-marker-clusterer/deprecated-map-marker-clusterer';
2121
import {MapPolygon} from './map-polygon/map-polygon';
2222
import {MapPolyline} from './map-polyline/map-polyline';
2323
import {MapRectangle} from './map-rectangle/map-rectangle';
@@ -38,7 +38,7 @@ const COMPONENTS = [
3838
MapKmlLayer,
3939
MapMarker,
4040
MapAdvancedMarker,
41-
MapMarkerClusterer,
41+
DeprecatedMapMarkerClusterer,
4242
MapPolygon,
4343
MapPolyline,
4444
MapRectangle,

src/google-maps/public-api.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ export {MapInfoWindow} from './map-info-window/map-info-window';
2222
export {MapKmlLayer} from './map-kml-layer/map-kml-layer';
2323
export {MapMarker} from './map-marker/map-marker';
2424
export {MapAdvancedMarker} from './map-advanced-marker/map-advanced-marker';
25-
export {MapMarkerClusterer} from './map-marker-clusterer/map-marker-clusterer';
25+
export {DeprecatedMapMarkerClusterer} from './deprecated-map-marker-clusterer/deprecated-map-marker-clusterer';
2626
export {MapPolygon} from './map-polygon/map-polygon';
2727
export {MapPolyline} from './map-polyline/map-polyline';
2828
export {MapRectangle} from './map-rectangle/map-rectangle';
@@ -35,5 +35,5 @@ export {
3535
ClusterIconStyle,
3636
AriaLabelFn,
3737
Calculator,
38-
} from './map-marker-clusterer/marker-clusterer-types';
38+
} from './deprecated-map-marker-clusterer/deprecated-marker-clusterer-types';
3939
export {MapEventManager} from './map-event-manager';

src/google-maps/testing/fake-google-map-utils.ts

+12-12
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* found in the LICENSE file at https://angular.dev/license
77
*/
88

9-
import {MarkerClusterer} from '../map-marker-clusterer/marker-clusterer-types';
9+
import {MarkerClusterer as DeprecatedMarkerClusterer} from '../deprecated-map-marker-clusterer/deprecated-marker-clusterer-types';
1010

1111
// The global `window` variable is typed as an intersection of `Window` and `globalThis`.
1212
// We re-declare `window` here and omit `globalThis` as it is typed with the actual Google
@@ -574,8 +574,8 @@ export function createBicyclingLayerConstructorSpy(
574574
}
575575

576576
/** Creates a jasmine.SpyObj for a MarkerClusterer */
577-
export function createMarkerClustererSpy(): jasmine.SpyObj<MarkerClusterer> {
578-
const markerClustererSpy = jasmine.createSpyObj('MarkerClusterer', [
577+
export function createDeprecatedMarkerClustererSpy(): jasmine.SpyObj<DeprecatedMarkerClusterer> {
578+
const deprecatedMarkerClustererSpy = jasmine.createSpyObj('DeprecatedMarkerClusterer', [
579579
'addListener',
580580
'addMarkers',
581581
'fitMapToMarkers',
@@ -619,26 +619,26 @@ export function createMarkerClustererSpy(): jasmine.SpyObj<MarkerClusterer> {
619619
'setZoomOnClick',
620620
'setOptions',
621621
]);
622-
markerClustererSpy.addListener.and.returnValue({remove: () => {}});
623-
return markerClustererSpy;
622+
deprecatedMarkerClustererSpy.addListener.and.returnValue({remove: () => {}});
623+
return deprecatedMarkerClustererSpy;
624624
}
625625

626626
/** Creates a jasmine.Spy to watch for the constructor of a MarkerClusterer */
627-
export function createMarkerClustererConstructorSpy(
628-
markerClustererSpy: jasmine.SpyObj<MarkerClusterer>,
627+
export function createDeprecatedMarkerClustererConstructorSpy(
628+
deprecatedMarkerClustererSpy: jasmine.SpyObj<DeprecatedMarkerClusterer>,
629629
apiLoaded = true,
630630
): jasmine.Spy {
631631
// The spy target function cannot be an arrow-function as this breaks when created through `new`.
632-
const markerClustererConstructorSpy = jasmine
633-
.createSpy('MarkerClusterer constructor', function () {
634-
return markerClustererSpy;
632+
const deprecatedMarkerClustererConstructorSpy = jasmine
633+
.createSpy('DeprecatedMarkerClusterer constructor', function () {
634+
return deprecatedMarkerClustererSpy;
635635
})
636636
.and.callThrough();
637637
if (apiLoaded) {
638638
const testingWindow: TestingWindow = window;
639-
testingWindow['MarkerClusterer'] = markerClustererConstructorSpy;
639+
testingWindow['MarkerClusterer'] = deprecatedMarkerClustererConstructorSpy;
640640
}
641-
return markerClustererConstructorSpy;
641+
return deprecatedMarkerClustererConstructorSpy;
642642
}
643643

644644
/** Creates a jasmine.SpyObj for DirectionsRenderer */

src/universal-app/kitchen-sink/kitchen-sink.html

+2-2
Original file line numberDiff line numberDiff line change
@@ -641,13 +641,13 @@ <h2>Google Map</h2>
641641
]"
642642
></map-heatmap-layer>
643643

644-
<map-marker-clusterer
644+
<deprecated-map-marker-clusterer
645645
imagePath="https://developers.google.com/maps/documentation/javascript/examples/markerclusterer/m"
646646
>
647647
<map-marker [position]="{lat: 24, lng: 12}"></map-marker>
648648
<map-marker [position]="{lat: 12, lng: 24}"></map-marker>
649649
<map-marker [position]="{lat: 12, lng: 12}"></map-marker>
650-
</map-marker-clusterer>
650+
</deprecated-map-marker-clusterer>
651651
</google-map>
652652

653653
<h2>Popover edit</h2>

src/universal-app/kitchen-sink/kitchen-sink.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import {
1616
MapInfoWindow,
1717
MapKmlLayer,
1818
MapMarker,
19-
MapMarkerClusterer,
19+
DeprecatedMapMarkerClusterer,
2020
MapPolygon,
2121
MapPolyline,
2222
MapRectangle,
@@ -196,7 +196,7 @@ export class TestEntryComponent {}
196196
MapKmlLayer,
197197
MapMarker,
198198
MapAdvancedMarker,
199-
MapMarkerClusterer,
199+
DeprecatedMapMarkerClusterer,
200200
MapPolygon,
201201
MapPolyline,
202202
MapRectangle,

0 commit comments

Comments
 (0)