Skip to content

Commit

Permalink
feat(sebmGoogleMapMarker): support basic label
Browse files Browse the repository at this point in the history
When using a <sebm-google-map-marker> inside a <sebm-google-map>, you
can now set a single-character label:

<sebm-google-map-marker [latitude]="lat" [longitude]="lng"
[label]="myLabel"></sebm-google-map-marker>
  • Loading branch information
sebholstein committed Nov 14, 2015
1 parent d05e6d3 commit f2e1257
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 2 deletions.
4 changes: 4 additions & 0 deletions src/components/google_map_marker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export class SebmGoogleMapMarker {
@Input() latitude: number;
@Input() longitude: number;
@Input() title: string;
@Input() label: string;

private _markerAddedToManger: boolean = false;
private _id: string;
Expand All @@ -27,6 +28,9 @@ export class SebmGoogleMapMarker {
if (changes['title']) {
this._markerManager.updateTitle(this);
}
if (changes['label']) {
this._markerManager.updateLabel(this);
}
}

id(): string { return this._id; }
Expand Down
2 changes: 2 additions & 0 deletions src/custom_typings/google_maps.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,14 @@ declare module google.maps {
setPosition(latLng: LatLng | LatLngLiteral): void;
setTitle(title: string): void;
setLabel(label: string | MarkerLabel): void;
getLabel(): MarkerLabel;
}

export interface MarkerOptions {
position: LatLng | LatLngLiteral;
title?: string;
map?: Map;
label?: string | MarkerLabel;
}

export interface MarkerLabel {
Expand Down
12 changes: 10 additions & 2 deletions src/services/marker_manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,17 @@ export class MarkerManager {
return this._markers.get(marker).then((m: google.maps.Marker) => m.setTitle(marker.title));
}

updateLabel(marker: SebmGoogleMapMarker): Promise<void> {
return this._markers.get(marker).then((m: google.maps.Marker) => {
const label = m.getLabel();
label.text = marker.label;
m.setLabel(label);
});
}

addMarker(marker: SebmGoogleMapMarker) {
const markerPromise =
this._mapsWrapper.createMarker({position: {lat: marker.latitude, lng: marker.longitude}});
const markerPromise = this._mapsWrapper.createMarker(
{position: {lat: marker.latitude, lng: marker.longitude}, label: marker.label});
this._markers.set(marker, markerPromise);
}
}

0 comments on commit f2e1257

Please sign in to comment.