Skip to content

Commit

Permalink
fix SebmGoogleMap
Browse files Browse the repository at this point in the history
  • Loading branch information
sebholstein committed Jan 12, 2016
1 parent 61aefc0 commit 53320d6
Showing 1 changed file with 69 additions and 23 deletions.
92 changes: 69 additions & 23 deletions src/directives/google-map.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,40 @@
import {
Component,
Input,
Output,
Renderer,
ElementRef,
EventEmitter,
OnChanges,
OnInit,
SimpleChange
} from 'angular2/core';
import {GoogleMapsAPIWrapper} from '../services/google-maps-api-wrapper';
import {MarkerManager} from '../services/marker-manager';
import {LatLng, LatLngLiteral} from '../services/google-maps-types';

/**
* Todo: add docs
* SebMGoogleMap renders a Google Map.
* **Important note**: To be able see a map in the browser, you have to define a height for the CSS
* class `sebm-google-map-container`.
*
* ### Example
* ```typescript
* import {Component} from 'angular2/core';
* import {SebmGoogleMap} from 'angular2-google-maps/core';
*
* @Component({
* selector: 'my-map-cmp',
* directives: [SebmGoogleMap],
* styles: [`
* .sebm-google-map-container {
* height: 300px;
* }
* `],
* template: `
* <sebm-google-map [latitude]="lat" [longitude]="lng" [zoom]="zoom">
* </sebm-google-map>
* `
* })
* ```
*/
@Component({
selector: 'sebm-google-map',
Expand All @@ -26,29 +47,51 @@ import {LatLng, LatLngLiteral} from '../services/google-maps-types';
}
`
],
inputs: ['longitude', 'latitude', 'zoom', 'disableDoubleClickZoom'],
outputs: ['mapClick', 'mapRightClick', 'mapDblClick'],
template: `
<div class="sebm-google-map-container-inner"></div>
<ng-content></ng-content>
`
})
export class SebmGoogleMap implements OnChanges {
export class SebmGoogleMap implements OnChanges,
OnInit {
private _longitude: number = 0;
private _latitude: number = 0;
private _zoom: number = 8;
@Input() disableDoubleClickZoom: boolean = false;
/**
* Enables/disables zoom and center on double click. Enabled by default.
*/
disableDoubleClickZoom: boolean = false;

private static _mapOptionsAttributes: string[] = ['disableDoubleClickZoom'];

@Output() mapClick: EventEmitter<MapMouseEvent> = new EventEmitter<MapMouseEvent>();
@Output() mapRightClick: EventEmitter<MapMouseEvent> = new EventEmitter<MapMouseEvent>();
@Output() mapDblClick: EventEmitter<MapMouseEvent> = new EventEmitter<MapMouseEvent>();

private _mapsWrapper: GoogleMapsAPIWrapper;

constructor(elem: ElementRef, _mapsWrapper: GoogleMapsAPIWrapper, renderer: Renderer) {
this._mapsWrapper = _mapsWrapper;
renderer.setElementClass(elem, 'sebm-google-map-container', true);
const container = elem.nativeElement.querySelector('.sebm-google-map-container-inner');
/**
* This event emitter gets emitted when the user clicks on the map (but not when they click on a
* marker or infoWindow).
*/
mapClick: EventEmitter<MapMouseEvent> = new EventEmitter<MapMouseEvent>();

/**
* This event emitter gets emitted when the user right-clicks on the map (but not when they click
* on a marker or infoWindow).
*/
mapRightClick: EventEmitter<MapMouseEvent> = new EventEmitter<MapMouseEvent>();

/**
* This event emitter gets emitted when the user double-clicks on the map (but not when they click
* on a marker or infoWindow).
*/
mapDblClick: EventEmitter<MapMouseEvent> = new EventEmitter<MapMouseEvent>();

constructor(
private _elem: ElementRef, private _mapsWrapper: GoogleMapsAPIWrapper,
private _renderer: Renderer) {}

/** @internal */
ngOnInit() {
this._renderer.setElementClass(this._elem.nativeElement, 'sebm-google-map-container', true);
const container = this._elem.nativeElement.querySelector('.sebm-google-map-container-inner');
this._initMapInstance(container);
}

Expand All @@ -64,31 +107,34 @@ export class SebmGoogleMap implements OnChanges {
(key: string) => { return SebmGoogleMap._mapOptionsAttributes.indexOf(key) !== 1; });
}

/** @internal */
ngOnChanges(changes: {[propName: string]: SimpleChange}) {
if (SebmGoogleMap._containsMapOptionsChange(Object.keys(changes))) {
this._setMapOptions();
this._mapsWrapper.setMapOptions({disableDoubleClickZoom: this.disableDoubleClickZoom});
}
}

_setMapOptions() {
this._mapsWrapper.setMapOptions({disableDoubleClickZoom: this.disableDoubleClickZoom});
}

@Input()
/**
* Sets the zoom level of the map. The default value is `8`.
*/
set zoom(value: number | string) {
this._zoom = this._convertToDecimal(value);
if (typeof this._zoom === 'number') {
this._mapsWrapper.setZoom(this._zoom);
}
}

@Input()
/**
* The longitude that sets the center of the map.
*/
set longitude(value: number | string) {
this._longitude = this._convertToDecimal(value);
this._updateCenter();
}

@Input()
/**
* The latitude that sets the center of the map.
*/
set latitude(value: number | string) {
this._latitude = this._convertToDecimal(value);
this._updateCenter();
Expand Down

0 comments on commit 53320d6

Please sign in to comment.