Skip to content

Commit

Permalink
feat: add pois as stops
Browse files Browse the repository at this point in the history
  • Loading branch information
petrot committed Apr 13, 2018
1 parent a1165c0 commit 0a66bd8
Showing 1 changed file with 43 additions and 41 deletions.
84 changes: 43 additions & 41 deletions src/app/shared/services/hike-data/hike-data.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,21 @@ import { State, hikeEditGeneralInfoActions, commonRouteActions, commonHikeAction
import { HikeEditGeneralInfoSelectors, HikeEditRoutePlannerSelectors } from 'app/store/selectors';
import { IGeneralInfoState } from 'app/store/state';
import { ReverseGeocodingService } from '../hike-data/reverse-geocoding.service';
import { ITextualDescriptionItem } from '../../interfaces';
import { IHikeProgram, ILocalizedItem, ITextualDescription } from 'subrepos/provider-client';
import { ITextualDescriptionItem, IGTrackPoi } from '../../interfaces';
import { IHikeProgram, ILocalizedItem, ITextualDescription, IPoi } from 'subrepos/provider-client';
import { PoiSelectors } from 'subrepos/gtrack-common-ngx';

import * as uuid from 'uuid/v1';
import * as _ from 'lodash';
import * as moment from 'moment';

@Injectable()
export class HikeDataService {
constructor(
private _store: Store<State>,
private _hikeEditGeneralInfoSelectors: HikeEditGeneralInfoSelectors,
private _hikeEditRoutePlannerSelectors: HikeEditRoutePlannerSelectors,
private _poiSelectors: PoiSelectors,
private _reverseGeocodingService: ReverseGeocodingService
) {}

Expand All @@ -32,9 +35,10 @@ export class HikeDataService {
return {
id: generalInfo.hikeId,
routeId: generalInfo.routeId,
difficulty: generalInfo.difficulty.toString(), // TODO it will be number!!
difficulty: generalInfo.difficulty,
isRoundTrip: isRoundTrip,
pois: generalInfo.pois
timestamp: moment().valueOf(),
pois: generalInfo.pois // id list
};
});
}
Expand Down Expand Up @@ -63,48 +67,46 @@ export class HikeDataService {
'uphill',
'downhill',
'time',
'score',
'isRoundTrip',
'difficulty',
'rate',
'routeIcon',
'elevationIcon'
'score'
]);

// TEST DATA FOR STOPS ====>
console.warn('TODO: collectHikeRouteInfo - Temporary stops array from markers');
_routeInfo.stops = [];

for (let i in routeInfo.route.features) {
let _feature = routeInfo.route.features[i];
let _segment: any = {
uphill: 0,
downhill: 0,
distance: 0,
score: 0,
time: 0
};

if (parseInt(i) > 1) {
_segment = _.pick(routeInfo.segments[parseInt(i) - 2], ['uphill', 'downhill', 'distance', 'score', 'time']);
}
return _routeInfo;
});
}

if (_feature.geometry.type === 'Point') {
_routeInfo.stops.push({
distanceFromOrigo: _segment.distance,
isCheckpoint: false,
onRoute: true,
poiId: 'fakeId',
lat: _feature.geometry.coordinates[1],
lon: _feature.geometry.coordinates[0],
segment: _segment
/**
* collectHikeData effect submethod
*/
public collectHikeStops() {
return this._store
.select(this._hikeEditGeneralInfoSelectors.getHikePois<(IPoi)>(this._poiSelectors.getAllPois))
.take(1)
.map(hikePois => {
const stops: any[] = [];

if (hikePois && hikePois.length > 0) {
for (let poi of hikePois) {
stops.push({
distanceFromOrigo: (<IGTrackPoi>poi).distFromRoute,
isCheckpoint: poi.isCheckpoint || false,
onRoute: (<IGTrackPoi>poi).onRoute || false,
poiId: poi.id,
lat: poi.lat,
lon: poi.lon,
segment: {
uphill: 0,
downhill: 0,
distance: 0,
score: 0,
time: 0
}
});
}
}

// <=== TEST DATA FOR STOPS

return _routeInfo;
return {
stops: stops
};
});
}

Expand Down Expand Up @@ -138,8 +140,8 @@ export class HikeDataService {
*/
public splitHikeDataToStore(hikeData: IHikeProgram) {
// Set unsaved states
this._store.dispatch(new commonHikeActions.HikeProgramUnsaved(<string>hikeData.id));
this._store.dispatch(new commonRouteActions.RouteUnsaved(hikeData.routeId));
this._store.dispatch(new commonHikeActions.HikeProgramModified(<string>hikeData.id));
this._store.dispatch(new commonRouteActions.RouteModified(hikeData.routeId));

// Set route id and load route data
this._store.dispatch(
Expand Down

0 comments on commit 0a66bd8

Please sign in to comment.