Skip to content

Commit

Permalink
fix(SebmGoogleMap): show map when zoom is not set
Browse files Browse the repository at this point in the history
This fixes the following (allowed) use of SebmGoogleMap.
When the zoom was not set, the map was empty.

```
<sebm-google-map [latitude]="lat" [longitude]="lng">
</sebm-google-map>
```

closes #81
  • Loading branch information
sebholstein committed Jan 15, 2016
1 parent e1f0818 commit b975c76
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions src/directives/google-map.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,8 @@ export class SebmGoogleMap implements OnChanges,
}

private _initMapInstance(el: HTMLElement) {
this._mapsWrapper.createMap(el, {center: {lat: this._latitude, lng: this._longitude}});
this._mapsWrapper.createMap(
el, {center: {lat: this._latitude, lng: this._longitude}, zoom: this._zoom});
this._handleMapCenterChange();
this._handleMapZoomChange();
this._handleMapMouseEvents();
Expand All @@ -118,7 +119,7 @@ export class SebmGoogleMap implements OnChanges,
* Sets the zoom level of the map. The default value is `8`.
*/
set zoom(value: number | string) {
this._zoom = this._convertToDecimal(value);
this._zoom = this._convertToDecimal(value, 8);
if (typeof this._zoom === 'number') {
this._mapsWrapper.setZoom(this._zoom);
}
Expand All @@ -140,13 +141,13 @@ export class SebmGoogleMap implements OnChanges,
this._updateCenter();
}

private _convertToDecimal(value: string | number): number {
private _convertToDecimal(value: string | number, defaultValue: number = null): number {
if (typeof value === 'string') {
return parseFloat(value);
} else if (typeof value === 'number') {
return <number>value;
}
return null;
return defaultValue;
}

private _updateCenter() {
Expand Down

0 comments on commit b975c76

Please sign in to comment.