Skip to content

Commit 1010d04

Browse files
committed
fix(plugin): climbing out of a bad merge hole
1 parent efc6445 commit 1010d04

File tree

5 files changed

+25
-125
lines changed

5 files changed

+25
-125
lines changed

src/configure.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ export class Configure {
1313
apiScript: 'https://maps.googleapis.com/maps/api/js',
1414
apiKey: '',
1515
apiLibraries: '',
16-
region:'',
17-
language:'',
16+
region: '',
17+
language: '',
1818
options: {}
1919
};
2020
}

src/google-maps.ts

Lines changed: 10 additions & 110 deletions
Original file line numberDiff line numberDiff line change
@@ -21,34 +21,17 @@ const logger = getLogger('aurelia-google-maps');
2121

2222
declare let google: any;
2323

24-
export interface BaseMarker {
24+
export interface Marker {
2525
icon?: string;
2626
label?: string;
2727
title?: string;
2828
draggable?: boolean;
2929
custom?: any;
3030
infoWindow?: { pixelOffset?: number, content: string, position?: number, maxWidth?: number }
31-
}
32-
33-
export interface AddressMarker extends BaseMarker {
34-
address: string;
35-
}
36-
37-
export interface LatLongMarker extends BaseMarker {
3831
latitude: number | string;
3932
longitude: number | string;
4033
}
4134

42-
const isAddressMarker = (marker: Marker): marker is AddressMarker => {
43-
return (<AddressMarker>marker).address !== undefined;
44-
}
45-
46-
const isLatLongMarker = (marker: Marker): marker is LatLongMarker => {
47-
return (<LatLongMarker>marker).latitude !== undefined && (<LatLongMarker>marker).longitude !== undefined;
48-
}
49-
50-
export type Marker = AddressMarker | LatLongMarker;
51-
5235
@noView()
5336
@customElement('google-map')
5437
@inject(Element, TaskQueue, Configure, BindingEngine, EventAggregator, GoogleMapsAPI)
@@ -59,7 +42,6 @@ export class GoogleMaps {
5942
private bindingEngine: BindingEngine;
6043
private eventAggregator: EventAggregator;
6144
private googleMapsApi: GoogleMapsAPI;
62-
private validMarkers: LatLongMarker[];
6345
private _geocoder: any;
6446

6547
@bindable longitude: number = 0;
@@ -105,23 +87,23 @@ export class GoogleMaps {
10587
});
10688
});
10789

108-
this.eventAggregator.subscribe('startMarkerHighlight', function(data: any) {
90+
this.eventAggregator.subscribe('startMarkerHighlight', function (data: any) {
10991
let mrkr: any = self._renderedMarkers[data.index];
11092
mrkr.setIcon(mrkr.custom.altIcon);
11193
mrkr.setZIndex((<any>window).google.maps.Marker.MAX_ZINDEX + 1);
11294
});
11395

114-
this.eventAggregator.subscribe('stopMarkerHighLight', function(data: any) {
96+
this.eventAggregator.subscribe('stopMarkerHighLight', function (data: any) {
11597
let mrkr: any = self._renderedMarkers[data.index];
116-
mrkr.setIcon( mrkr.custom.defaultIcon);
98+
mrkr.setIcon(mrkr.custom.defaultIcon);
11799
});
118100

119-
this.eventAggregator.subscribe('panToMarker', function(data: any) {
101+
this.eventAggregator.subscribe('panToMarker', function (data: any) {
120102
self.map.panTo(self._renderedMarkers[data.index].position);
121103
self.map.setZoom(17);
122104
});
123105

124-
this.eventAggregator.subscribe(`clearMarkers`, function() {
106+
this.eventAggregator.subscribe(`clearMarkers`, function () {
125107
this.clearMarkers();
126108
});
127109
}
@@ -131,7 +113,7 @@ export class GoogleMaps {
131113
return;
132114
}
133115

134-
this._renderedMarkers.forEach(function(marker: any) {
116+
this._renderedMarkers.forEach(function (marker: any) {
135117
marker.setMap(null);
136118
});
137119

@@ -158,7 +140,6 @@ export class GoogleMaps {
158140
mapTypeId: mapTypeId
159141
});
160142

161-
162143
this.map = new (<any>window).google.maps.Map(this.element, options);
163144
if (this.mapLoaded) {
164145
this.mapLoaded(this.map);
@@ -224,7 +205,7 @@ export class GoogleMaps {
224205
*
225206
*/
226207
renderMarker(marker: Marker): Promise<void> {
227-
let markerLatLng = new (<any>window).google.maps.LatLng(parseFloat(<string>(<LatLongMarker>marker).latitude), parseFloat(<string>(<LatLongMarker>marker).longitude));
208+
let markerLatLng = new (<any>window).google.maps.LatLng(parseFloat(<string>marker.latitude), parseFloat(<string>marker.longitude));
228209

229210
return this._mapPromise.then(() => {
230211
// Create the marker
@@ -298,69 +279,6 @@ export class GoogleMaps {
298279
});
299280
}
300281

301-
/**
302-
* Geocodes an address, once the Google Map script
303-
* has been properly loaded and promise instantiated.
304-
*
305-
* @param address string
306-
* @param geocoder any
307-
*
308-
*/
309-
geocodeAddress(address: string) {
310-
this.geocode(address).then(firstResult => {
311-
this.setCenter(firstResult.geometry.location);
312-
this.createMarker({
313-
map: this.map,
314-
position: firstResult.geometry.location
315-
}).then((createdMarker: any) => {
316-
this._locationByAddressMarkers.push(createdMarker);
317-
this.eventAggregator.publish(LOCATIONADDED, Object.assign(createdMarker, { placeId: firstResult.place_id }));
318-
});
319-
}).catch(console.info);
320-
}
321-
322-
/**
323-
* Geocodes Address and returns the coordinates once the google map has been properly initialized
324-
*
325-
* @param marker string
326-
*
327-
*/
328-
addressMarkerToMarker(marker: AddressMarker): Promise<void | BaseMarker> {
329-
return this.geocode(marker.address).then(firstResults => {
330-
return {
331-
... marker,
332-
latitude: firstResults.geometry.location.lat(),
333-
longitude: firstResults.geometry.location.lng(),
334-
};
335-
}).catch(console.info);
336-
}
337-
338-
/**
339-
* Geocodes Address and returns the firstresults object after google maps has initialized
340-
*
341-
* @param address string
342-
*
343-
*/
344-
private geocode(address: string): Promise<any> {
345-
return this._mapPromise.then(() => {
346-
return new Promise((resolve, reject) => {
347-
this.geocoder.geocode({ 'address': address }, (results: any, status: string) => {
348-
if (status !== (<any>window).google.maps.GeocoderStatus.OK) {
349-
reject(new Error(`Failed to geocode address '${address}' with status: ${status}`));
350-
}
351-
resolve(results[0]);
352-
});
353-
});
354-
});
355-
}
356-
357-
private get geocoder() {
358-
if (!this._geocoder) {
359-
this._geocoder = new (<any>window).google.maps.Geocoder;
360-
}
361-
return this._geocoder;
362-
}
363-
364282
/**
365283
* Get Current Position
366284
*
@@ -462,26 +380,8 @@ export class GoogleMaps {
462380

463381
// Render all markers again
464382
this._mapPromise.then(() => {
465-
Promise.all<LatLongMarker>(
466-
newValue.map(marker => {
467-
if (isAddressMarker(marker) && !isLatLongMarker(marker)) {
468-
return this.addressMarkerToMarker(marker);
469-
} else {
470-
}
471-
return marker;
472-
})
473-
).then(validMarkers => {
474-
// Addresses that fail to parse return undefined (because the error is caught earlier in the promise chain)
475-
this.validMarkers = validMarkers.filter(marker => typeof marker !== 'undefined');
476-
return Promise.all(this.validMarkers.map(this.renderMarker.bind(this)));
477-
}).then(() => {
478-
/**
479-
* We queue up a task to update the bounds, because in the case of multiple bound properties changing all at once,
480-
* we need to let Aurelia handle updating the other properties before we actually trigger a re-render of the map
481-
*/
482-
this.taskQueue.queueTask(() => {
483-
this.zoomToMarkerBounds();
484-
});
383+
let markerPromises = newValue.map(marker => {
384+
return this.renderMarker(marker);
485385
});
486386

487387
// Wait until all of the renderMarker calls have been resolved

src/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import {FrameworkConfiguration} from 'aurelia-framework';
1+
import { FrameworkConfiguration } from 'aurelia-framework';
22
import { PLATFORM, DOM } from 'aurelia-pal';
33

44
import { Configure } from './configure';
@@ -11,7 +11,7 @@ export function configure(aurelia: FrameworkConfiguration, configCallback?: (con
1111
DOM.injectStyles(`google-map { display: block; height: 350px; }`);
1212

1313
// Do we have a callback function?
14-
if (configCallback !== undefined && typeof(configCallback) === 'function') {
14+
if (configCallback !== undefined && typeof (configCallback) === 'function') {
1515
configCallback(instance);
1616
}
1717

test/unit/configure.spec.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,26 +11,26 @@ describe('configure', () => {
1111
expect(sut._config).toEqual({
1212
apiScript: 'https://maps.googleapis.com/maps/api/js',
1313
apiKey: '',
14-
region:'',
15-
language:'',
14+
region: '',
15+
language: '',
1616
apiLibraries: '',
1717
options: {}
1818
});
1919
});
2020

2121
it('set a new option using options', () => {
2222
expect(sut.get('test-option')).toBeUndefined();
23-
24-
sut.options({'test-option': 'test value123'});
23+
24+
sut.options({ 'test-option': 'test value123' });
2525

2626
expect(sut.get('test-option')).toEqual('test value123');
2727
});
2828

2929

3030
it('override default option using options', () => {
3131
expect(sut.get('apiScript')).toEqual('https://maps.googleapis.com/maps/api/js');
32-
33-
sut.options({'apiScript': 'http://facebook.com/123'});
32+
33+
sut.options({ 'apiScript': 'http://facebook.com/123' });
3434

3535
expect(sut.get('apiScript')).toEqual('http://facebook.com/123');
3636
});

test/unit/index.spec.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
1-
import {configure} from '../../src/index';
1+
import { configure } from '../../src/index';
22
import { Configure } from '../../src/configure';
3-
import {FrameworkConfiguration} from 'aurelia-framework';
3+
import { FrameworkConfiguration } from 'aurelia-framework';
44

55
let mockFrameWorkConfiguration = {
66
container: {
7-
get: function(instance: string) {
7+
get: function (instance: string) {
88
return instance;
99
}
1010
},
11-
globalResources: function(resources: any): FrameworkConfiguration {
11+
globalResources: function (resources: any): FrameworkConfiguration {
1212
return resources;
1313
}
1414
} as FrameworkConfiguration;
@@ -24,7 +24,7 @@ describe('index', () => {
2424
});
2525

2626
it('configure options callback', () => {
27-
let configureCallback = function(instance: any) {
27+
let configureCallback = function (instance: any) {
2828
return instance;
2929
}
3030

0 commit comments

Comments
 (0)