Skip to content
This repository was archived by the owner on Jun 23, 2025. It is now read-only.

Commit 0048ccf

Browse files
jindersebholstein
authored andcommitted
feat(SebmGoogleMap): Add control options support
1 parent dc7894b commit 0048ccf

File tree

2 files changed

+205
-23
lines changed

2 files changed

+205
-23
lines changed

src/core/directives/map.ts

Lines changed: 74 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1-
import {Component, ElementRef, EventEmitter, OnChanges, OnDestroy, OnInit, SimpleChange} from '@angular/core';
1+
import {Component, ElementRef, EventEmitter, OnChanges, OnDestroy, OnInit, SimpleChanges} from '@angular/core';
22
import {Subscription} from 'rxjs/Subscription';
33

44
import {MouseEvent} from '../map-types';
55
import {GoogleMapsAPIWrapper} from '../services/google-maps-api-wrapper';
6-
import {LatLng, LatLngLiteral} from '../services/google-maps-types';
6+
import {FullscreenControlOptions, LatLng, LatLngLiteral, MapTypeControlOptions, PanControlOptions,
7+
RotateControlOptions, ScaleControlOptions, StreetViewControlOptions, ZoomControlOptions} from '../services/google-maps-types';
78
import {LatLngBounds, LatLngBoundsLiteral, MapTypeStyle} from '../services/google-maps-types';
89
import {CircleManager} from '../services/managers/circle-manager';
910
import {InfoWindowManager} from '../services/managers/info-window-manager';
@@ -153,6 +154,11 @@ export class AgmMap implements OnChanges, OnInit, OnDestroy {
153154
*/
154155
zoomControl: boolean = true;
155156

157+
/**
158+
* Options for the Zoom control.
159+
*/
160+
zoomControlOptions: ZoomControlOptions;
161+
156162
/**
157163
* Styles to apply to each of the default map types. Note that for Satellite/Hybrid and Terrain
158164
* modes, these styles will only apply to labels and geometry.
@@ -173,6 +179,11 @@ export class AgmMap implements OnChanges, OnInit, OnDestroy {
173179
*/
174180
streetViewControl: boolean = true;
175181

182+
/**
183+
* Options for the Street View control.
184+
*/
185+
streetViewControlOptions: StreetViewControlOptions;
186+
176187
/**
177188
* Sets the viewport to contain the given bounds.
178189
*/
@@ -183,18 +194,60 @@ export class AgmMap implements OnChanges, OnInit, OnDestroy {
183194
*/
184195
scaleControl: boolean = false;
185196

197+
/**
198+
* Options for the scale control.
199+
*/
200+
scaleControlOptions: ScaleControlOptions;
201+
186202
/**
187203
* The initial enabled/disabled state of the Map type control.
188204
*/
189205
mapTypeControl: boolean = false;
190206

207+
/**
208+
* Options for the Map type control.
209+
*/
210+
mapTypeControlOptions: MapTypeControlOptions;
211+
212+
/**
213+
* The initial enabled/disabled state of the Pan control.
214+
*/
215+
panControl: boolean = false;
216+
217+
/**
218+
* Options for the Pan control.
219+
*/
220+
panControlOptions: PanControlOptions;
221+
222+
/**
223+
* The initial enabled/disabled state of the Rotate control.
224+
*/
225+
rotateControl: boolean = false;
226+
227+
/**
228+
* Options for the Rotate control.
229+
*/
230+
rotateControlOptions: RotateControlOptions;
231+
232+
/**
233+
* The initial enabled/disabled state of the Fullscreen control.
234+
*/
235+
fullscreenControl: boolean = false;
236+
237+
/**
238+
* Options for the Fullscreen control.
239+
*/
240+
fullscreenControlOptions: FullscreenControlOptions;
241+
191242
/**
192243
* Map option attributes that can change over time
193244
*/
194245
private static _mapOptionsAttributes: string[] = [
195246
'disableDoubleClickZoom', 'scrollwheel', 'draggable', 'draggableCursor', 'draggingCursor',
196-
'keyboardShortcuts', 'zoomControl', 'styles', 'streetViewControl', 'zoom', 'mapTypeControl',
197-
'minZoom', 'maxZoom'
247+
'keyboardShortcuts', 'zoomControl', 'zoomControlOptions', 'styles', 'streetViewControl',
248+
'streetViewControlOptions', 'zoom', 'mapTypeControl', 'mapTypeControlOptions', 'minZoom',
249+
'maxZoom', 'panControl', 'panControlOptions', 'rotateControl', 'rotateControlOptions',
250+
'fullscreenControl', 'fullscreenControlOptions'
198251
];
199252

200253
private _observableSubscriptions: Subscription[] = [];
@@ -253,16 +306,28 @@ export class AgmMap implements OnChanges, OnInit, OnDestroy {
253306
minZoom: this.minZoom,
254307
maxZoom: this.maxZoom,
255308
disableDefaultUI: this.disableDefaultUI,
309+
disableDoubleClickZoom: this.disableDoubleClickZoom,
310+
scrollwheel: this.scrollwheel,
256311
backgroundColor: this.backgroundColor,
257312
draggable: this.draggable,
258313
draggableCursor: this.draggableCursor,
259314
draggingCursor: this.draggingCursor,
260315
keyboardShortcuts: this.keyboardShortcuts,
261-
zoomControl: this.zoomControl,
262316
styles: this.styles,
317+
zoomControl: this.zoomControl,
318+
zoomControlOptions: this.zoomControlOptions,
263319
streetViewControl: this.streetViewControl,
320+
streetViewControlOptions: this.streetViewControlOptions,
264321
scaleControl: this.scaleControl,
265-
mapTypeControl: this.mapTypeControl
322+
scaleControlOptions: this.scaleControlOptions,
323+
mapTypeControl: this.mapTypeControl,
324+
mapTypeControlOptions: this.mapTypeControlOptions,
325+
panControl: this.panControl,
326+
panControlOptions: this.panControlOptions,
327+
rotateControl: this.rotateControl,
328+
rotateControlOptions: this.rotateControlOptions,
329+
fullscreenControl: this.fullscreenControl,
330+
fullscreenControlOptions: this.fullscreenControlOptions,
266331
});
267332

268333
// register event listeners
@@ -280,12 +345,12 @@ export class AgmMap implements OnChanges, OnInit, OnDestroy {
280345
}
281346

282347
/* @internal */
283-
ngOnChanges(changes: {[propName: string]: SimpleChange}) {
348+
ngOnChanges(changes: SimpleChanges) {
284349
this._updateMapOptionsChanges(changes);
285350
this._updatePosition(changes);
286351
}
287352

288-
private _updateMapOptionsChanges(changes: {[propName: string]: SimpleChange}) {
353+
private _updateMapOptionsChanges(changes: SimpleChanges) {
289354
let options: {[propName: string]: any} = {};
290355
let optionKeys =
291356
Object.keys(changes).filter(k => AgmMap._mapOptionsAttributes.indexOf(k) !== -1);
@@ -307,7 +372,7 @@ export class AgmMap implements OnChanges, OnInit, OnDestroy {
307372
});
308373
}
309374

310-
private _updatePosition(changes: {[propName: string]: SimpleChange}) {
375+
private _updatePosition(changes: SimpleChanges) {
311376
if (changes['latitude'] == null && changes['longitude'] == null &&
312377
changes['fitBounds'] == null) {
313378
// no position update needed

src/core/services/google-maps-types.ts

Lines changed: 131 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -125,16 +125,27 @@ export interface MapOptions {
125125
maxZoom?: number;
126126
disableDoubleClickZoom?: boolean;
127127
disableDefaultUI?: boolean;
128+
scrollwheel?: boolean;
128129
backgroundColor?: string;
129130
draggable?: boolean;
130131
draggableCursor?: string;
131132
draggingCursor?: string;
132133
keyboardShortcuts?: boolean;
133-
zoomControl?: boolean;
134134
styles?: MapTypeStyle[];
135+
zoomControl?: boolean;
136+
zoomControlOptions?: ZoomControlOptions;
135137
streetViewControl?: boolean;
138+
streetViewControlOptions?: StreetViewControlOptions;
136139
scaleControl?: boolean;
140+
scaleControlOptions?: ScaleControlOptions;
137141
mapTypeControl?: boolean;
142+
mapTypeControlOptions?: MapTypeControlOptions;
143+
panControl?: boolean;
144+
panControlOptions?: PanControlOptions;
145+
rotateControl?: boolean;
146+
rotateControlOptions?: RotateControlOptions;
147+
fullscreenControl?: boolean;
148+
fullscreenControlOptions?: FullscreenControlOptions;
138149
}
139150

140151
export interface MapTypeStyle {
@@ -404,17 +415,123 @@ export interface Geometry {
404415
type: string;
405416
}
406417

407-
export class ControlPosition{
408-
readonly BOTTOM_CENTER: string = 'BOTTOM_CENTER';
409-
readonly BOTTOM_LEFT: string = 'BOTTOM_LEFT';
410-
readonly BOTTOM_RIGHT: string = 'BOTTOM_RIGHT';
411-
readonly LEFT_BOTTOM: string = 'LEFT_BOTTOM';
412-
readonly LEFT_CENTER: string = 'LEFT_CENTER';
413-
readonly LEFT_TOP: string = 'LEFT_TOP';
414-
readonly RIGHT_BOTTOM: string = 'RIGHT_BOTTOM';
415-
readonly RIGHT_CENTER: string = 'RIGHT_CENTER';
416-
readonly RIGHT_TOP: string = 'RIGHT_TOP';
417-
readonly TOP_CENTER: string = 'TOP_CENTER';
418-
readonly TOP_LEFT: string = 'TOP_LEFT';
419-
readonly TOP_RIGHT: string = 'TOP_RIGHT';
418+
/**
419+
* Identifiers used to specify the placement of controls on the map. Controls are
420+
* positioned relative to other controls in the same layout position. Controls that
421+
* are added first are positioned closer to the edge of the map.
422+
*/
423+
export enum ControlPosition {
424+
BOTTOM_CENTER,
425+
BOTTOM_LEFT,
426+
BOTTOM_RIGHT,
427+
LEFT_BOTTOM,
428+
LEFT_CENTER,
429+
LEFT_TOP,
430+
RIGHT_BOTTOM,
431+
RIGHT_CENTER,
432+
RIGHT_TOP,
433+
TOP_CENTER,
434+
TOP_LEFT,
435+
TOP_RIGHT
436+
}
437+
438+
export enum MapTypeId {
439+
/** This map type displays a transparent layer of major streets on satellite images. */
440+
HYBRID,
441+
/** This map type displays a normal street map. */
442+
ROADMAP,
443+
/** This map type displays satellite images. */
444+
SATELLITE,
445+
/** This map type displays maps with physical features such as terrain and vegetation. */
446+
TERRAIN
447+
}
448+
449+
/***** Controls *****/
450+
/** Options for the rendering of the map type control. */
451+
export interface MapTypeControlOptions {
452+
/** IDs of map types to show in the control. */
453+
mapTypeIds?: (MapTypeId|string)[];
454+
/**
455+
* Position id. Used to specify the position of the control on the map.
456+
* The default position is TOP_RIGHT.
457+
*/
458+
position?: ControlPosition;
459+
/** Style id. Used to select what style of map type control to display. */
460+
style?: MapTypeControlStyle;
461+
}
462+
463+
export enum MapTypeControlStyle {
464+
DEFAULT,
465+
DROPDOWN_MENU,
466+
HORIZONTAL_BAR
467+
}
468+
469+
export interface OverviewMapControlOptions {
470+
opened?: boolean;
471+
}
472+
473+
/** Options for the rendering of the pan control. */
474+
export interface PanControlOptions {
475+
/**
476+
* Position id. Used to specify the position of the control on the map.
477+
* The default position is TOP_LEFT.
478+
*/
479+
position?: ControlPosition;
480+
}
481+
482+
/** Options for the rendering of the rotate control. */
483+
export interface RotateControlOptions {
484+
/**
485+
* Position id. Used to specify the position of the control on the map.
486+
* The default position is TOP_LEFT.
487+
*/
488+
position?: ControlPosition;
489+
}
490+
491+
/** Options for the rendering of the scale control. */
492+
export interface ScaleControlOptions {
493+
/** Style id. Used to select what style of scale control to display. */
494+
style?: ScaleControlStyle;
495+
}
496+
497+
export enum ScaleControlStyle {
498+
DEFAULT
499+
}
500+
501+
/** Options for the rendering of the Street View pegman control on the map. */
502+
export interface StreetViewControlOptions {
503+
/**
504+
* Position id. Used to specify the position of the control on the map. The
505+
* default position is embedded within the navigation (zoom and pan) controls.
506+
* If this position is empty or the same as that specified in the
507+
* zoomControlOptions or panControlOptions, the Street View control will be
508+
* displayed as part of the navigation controls. Otherwise, it will be displayed
509+
* separately.
510+
*/
511+
position?: ControlPosition;
512+
}
513+
514+
/** Options for the rendering of the zoom control. */
515+
export interface ZoomControlOptions {
516+
/**
517+
* Position id. Used to specify the position of the control on the map.
518+
* The default position is TOP_LEFT.
519+
*/
520+
position?: ControlPosition;
521+
style?: ZoomControlStyle;
522+
}
523+
524+
export enum ZoomControlStyle {
525+
DEFAULT,
526+
LARGE,
527+
SMALL
528+
}
529+
530+
/** Options for the rendering of the fullscreen control. */
531+
export interface FullscreenControlOptions {
532+
/**
533+
* Position id. Used to specify the position of the control on the map.
534+
* The default position is RIGHT_TOP.
535+
*/
536+
position?: ControlPosition;
420537
}

0 commit comments

Comments
 (0)