Skip to content

Commit b21f8d5

Browse files
committed
feat(google-maps): Add methods and event handling to Google Map
Change event names so they will not collide with native angular events.
1 parent 721f6b3 commit b21f8d5

File tree

5 files changed

+32
-36
lines changed

5 files changed

+32
-36
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@
33
width="750px"
44
[center]="center"
55
[zoom]="zoom"
6-
(click)="handleClick($event)"></google-map>
6+
(mapClick)="handleClick($event)"></google-map>

src/google-maps/google-map/BUILD.bazel

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ ng_module(
1414
["**/*.ts"],
1515
exclude = ["**/*.spec.ts"],
1616
),
17-
assets = glob(["**/*.html"]),
1817
module_name = "@angular/google-maps/google-map",
1918
deps = [
2019
"@npm//@angular/core",

src/google-maps/google-map/google-map.html

Lines changed: 0 additions & 9 deletions
This file was deleted.

src/google-maps/google-map/google-map.spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -244,9 +244,9 @@ describe('GoogleMap', () => {
244244
[center]="center"
245245
[zoom]="zoom"
246246
[options]="options"
247-
(click)="handleClick"
247+
(mapClick)="handleClick"
248248
(centerChanged)="handleCenterChanged"
249-
(rightclick)="handleRightclick"></google-map>`,
249+
(mapRightclick)="handleRightclick"></google-map>`,
250250
})
251251
class TestApp {
252252
height?: string;

src/google-maps/google-map/google-map.ts

Lines changed: 29 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ export const DEFAULT_WIDTH = '500px';
4343
@Component({
4444
selector: 'google-map',
4545
changeDetection: ChangeDetectionStrategy.OnPush,
46-
templateUrl: 'google-map.html',
46+
template: '<div class="map-container"></div>',
4747
})
4848
export class GoogleMap implements OnChanges, OnInit, OnDestroy {
4949
@Input() height = DEFAULT_HEIGHT;
@@ -65,19 +65,19 @@ export class GoogleMap implements OnChanges, OnInit, OnDestroy {
6565

6666
@Output() boundsChanged = new EventEmitter<void>();
6767
@Output() centerChanged = new EventEmitter<void>();
68-
@Output() click = new EventEmitter<google.maps.MouseEvent|google.maps.IconMouseEvent>();
69-
@Output() dblclick = new EventEmitter<google.maps.MouseEvent>();
70-
@Output() drag = new EventEmitter<void>();
71-
@Output() dragend = new EventEmitter<void>();
72-
@Output() dragstart = new EventEmitter<void>();
68+
@Output() mapClick = new EventEmitter<google.maps.MouseEvent|google.maps.IconMouseEvent>();
69+
@Output() mapDblclick = new EventEmitter<google.maps.MouseEvent>();
70+
@Output() mapDrag = new EventEmitter<void>();
71+
@Output() mapDragend = new EventEmitter<void>();
72+
@Output() mapDragstart = new EventEmitter<void>();
7373
@Output() headingChanged = new EventEmitter<void>();
7474
@Output() idle = new EventEmitter<void>();
7575
@Output() maptypeidChanged = new EventEmitter<void>();
76-
@Output() mousemove = new EventEmitter<google.maps.MouseEvent>();
77-
@Output() mouseout = new EventEmitter<google.maps.MouseEvent>();
78-
@Output() mouseover = new EventEmitter<google.maps.MouseEvent>();
76+
@Output() mapMousemove = new EventEmitter<google.maps.MouseEvent>();
77+
@Output() mapMouseout = new EventEmitter<google.maps.MouseEvent>();
78+
@Output() mapMouseover = new EventEmitter<google.maps.MouseEvent>();
7979
@Output() projectionChanged = new EventEmitter<void>();
80-
@Output() rightclick = new EventEmitter<google.maps.MouseEvent>();
80+
@Output() mapRightclick = new EventEmitter<google.maps.MouseEvent>();
8181
@Output() tilesloaded = new EventEmitter<void>();
8282
@Output() tiltChanged = new EventEmitter<void>();
8383
@Output() zoomChanged = new EventEmitter<void>();
@@ -244,19 +244,25 @@ export class GoogleMap implements OnChanges, OnInit, OnDestroy {
244244

245245
private _initializeEventHandlers() {
246246
const eventHandlers = new Map<string, EventEmitter<void>>([
247-
['bounds_changed', this.boundsChanged], ['center_changed', this.centerChanged],
248-
['drag', this.drag], ['dragend', this.dragend], ['dragstart', this.dragstart],
249-
['heading_changed', this.headingChanged], ['idle', this.idle],
250-
['maptypeid_changed', this.maptypeidChanged], ['projection_changed', this.projectionChanged],
251-
['tilesloaded', this.tilesloaded], ['tilt_changed', this.tiltChanged],
252-
['zoomChanged', this.zoomChanged]
247+
['bounds_changed', this.boundsChanged],
248+
['center_changed', this.centerChanged],
249+
['drag', this.mapDrag],
250+
['dragend', this.mapDragend],
251+
['dragstart', this.mapDragstart],
252+
['heading_changed', this.headingChanged],
253+
['idle', this.idle],
254+
['maptypeid_changed', this.maptypeidChanged],
255+
['projection_changed', this.projectionChanged],
256+
['tilesloaded', this.tilesloaded],
257+
['tilt_changed', this.tiltChanged],
258+
['zoomChanged', this.zoomChanged],
253259
]);
254260
const mouseEventHandlers = new Map<string, EventEmitter<google.maps.MouseEvent>>([
255-
['dblclick', this.dblclick],
256-
['mousemove', this.mousemove],
257-
['mouseout', this.mouseout],
258-
['mouseover', this.mouseover],
259-
['rightclick', this.rightclick],
261+
['dblclick', this.mapDblclick],
262+
['mousemove', this.mapMousemove],
263+
['mouseout', this.mapMouseout],
264+
['mouseover', this.mapMouseover],
265+
['rightclick', this.mapRightclick],
260266
]);
261267
eventHandlers.forEach((eventHandler: EventEmitter<void>, name: string) => {
262268
if (eventHandler.observers.length > 0) {
@@ -274,10 +280,10 @@ export class GoogleMap implements OnChanges, OnInit, OnDestroy {
274280
}));
275281
}
276282
});
277-
if (this.click.observers.length > 0) {
283+
if (this.mapClick.observers.length > 0) {
278284
this._listeners.push(this._googleMap.addListener(
279285
'click', (event: google.maps.MouseEvent|google.maps.IconMouseEvent) => {
280-
this.click.emit(event);
286+
this.mapClick.emit(event);
281287
}));
282288
}
283289
}

0 commit comments

Comments
 (0)