Skip to content

Commit

Permalink
feat: use circle search for gTrackPoi search
Browse files Browse the repository at this point in the history
  • Loading branch information
petrot committed Feb 26, 2018
1 parent 6683cfa commit e094fb1
Show file tree
Hide file tree
Showing 4 changed files with 91 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { Store } from '@ngrx/store';
import { Observable } from 'rxjs/Observable';
import { Subject } from 'rxjs/Subject';
import { IPoi } from 'subrepos/provider-client';
import { PoiSelectors } from 'subrepos/gtrack-common-ngx';
import { PoiSelectors, CenterRadius, GeometryService } from 'subrepos/gtrack-common-ngx';
import { AdminMap, AdminMapService } from 'app/shared/services/admin-map';
import {
State, hikeEditPoiActions, IExternalPoiListContextState, commonPoiActions, commonGeoSearchActions,
Expand All @@ -28,6 +28,7 @@ export class HikeEditPoisGTrackComponent implements OnInit, OnDestroy {
private _adminMapService: AdminMapService,
private _hikeEditMapSelectors: HikeEditMapSelectors,
private _hikeEditPoiSelectors: HikeEditPoiSelectors,
private _geometryService: GeometryService,
private _poiSelectors: PoiSelectors
) {}

Expand Down Expand Up @@ -72,28 +73,19 @@ export class HikeEditPoisGTrackComponent implements OnInit, OnDestroy {
* Get pois for the current subdomain
*/
public getPois() {
this._store.select(state => state.hikeEditRoutePlanner.segments)
.take(1)
.subscribe(segments => {
for (const segment of segments) {
// Segments contains lat/lng, geoJson uses lng/lat
const _segmentCoords = segment.coordinates.map(coord => [coord[1], coord[0]]);

// ERROR: may causes self-intersect
// _segmentCoords.push(_segmentCoords[0]);

console.log('_segmentCoords', [_segmentCoords]);
this._store.dispatch(new commonGeoSearchActions.SearchInBox({
table: 'hike_programs',
box: {
type: 'Polygon',
coordinates: [_segmentCoords]
}
}, uuid()));
}
});
let _bounds = this._map.routeInfo.getSearchBounds();
let _geo: CenterRadius = this._geometryService.getCenterRadius(_bounds);
let _centerCoord = _geo!.center!.geometry!.coordinates;

if (_centerCoord) {
this._store.dispatch(new hikeEditPoiActions.GetGTrackPois({
centerCoord: _centerCoord,
radius: 1000,
mapId: this._map.id
}));
}

/* let _bounds = this._map.routeInfo.getSearchBounds();
/*
if (_bounds) {
/*
Expand Down
24 changes: 24 additions & 0 deletions src/app/store/actions/hike-edit-poi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ export const SET_OSM_ROUTE_POI_IN_HIKE = '[HikeEditPoi] Set OSM route poi inHike
export const GET_WIKIPEDIA_POIS = '[HikeEditPoi] Get Wikipedia pois';
export const SET_WIKIPEDIA_POIS = '[HikeEditPoi] Set Wikipedia pois';
export const SET_WIKIPEDIA_POI_IN_HIKE = '[HikeEditPoi] Set Wikipedia poi inHike';
export const GET_GTRACK_POIS = '[HikeEditPoi] Get gTrack pois';
export const SET_GTRACK_POIS = '[HikeEditPoi] Set gTrack pois';
export const TOGGLE_ONROUTE_MARKERS = '[HikeEditPoi] Toggle onroute markers';
export const TOGGLE_OFFROUTE_MARKERS = '[HikeEditPoi] Toggle offroute markers';
export const GENERATE_SUBDOMAIN_POI_MARKERS = '[HikeEditPoi] Generate subdomain poi markers';
Expand Down Expand Up @@ -159,6 +161,26 @@ export class SetWikipediaPoiInHike implements Action {
}) { /* EMPTY */ }
}

/**
* gTRack pois
*/

export class GetGTrackPois implements Action {
readonly type = GET_GTRACK_POIS;
constructor(public payload: {
centerCoord: number[],
radius: number
mapId: string
}) { /* EMPTY */ }
}

export class SetGTrackPois implements Action {
readonly type = SET_GTRACK_POIS;
constructor(public payload: {
pois: IPoi[]
}) { /* EMPTY */ }
}

/**
* Toggle markers
*/
Expand Down Expand Up @@ -207,6 +229,8 @@ export type AllHikeEditPoiActions =
| GetWikipediaPois
| SetWikipediaPois
| SetWikipediaPoiInHike
| GetGTrackPois
| SetGTrackPois
| ToggleOnrouteMarkers
| ToggleOffrouteMarkers
| GenerateSubdomainPoiMarkers
Expand Down
21 changes: 20 additions & 1 deletion src/app/store/effects/hike-edit-poi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@ import { Actions, Effect, toPayload } from '@ngrx/effects';
import { Action, Store } from '@ngrx/store';
import { Observable } from 'rxjs/Rx';
import { MapMarkerService, IconService } from 'subrepos/gtrack-common-ngx';
import { IPoi } from 'subrepos/provider-client';
import {
State, hikeEditPoiActions, hikeEditMapActions, IExternalPoiListContextItemState
State, hikeEditPoiActions, hikeEditMapActions, IExternalPoiListContextItemState, commonGeoSearchActions
} from '../index';
import { HikeEditPoiSelectors } from 'app/store/selectors/'
import {
Expand All @@ -20,6 +21,7 @@ import { IExternalPoi, IWikipediaPoi, IOsmPoi, IGooglePoi } from 'app/shared/int
import { ExternalPoi } from 'app/shared/services/poi/external-poi';

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

@Injectable()
export class HikeEditPoiEffects {
Expand Down Expand Up @@ -135,6 +137,23 @@ export class HikeEditPoiEffects {
});
});

/**
* Get gTrack pois from db
*/
@Effect()
getGtrackPois$: Observable<any> = this._actions$
.ofType(hikeEditPoiActions.GET_GTRACK_POIS)
.map(toPayload)
.map(data => {
return new commonGeoSearchActions.SearchInCircle({
table: 'hike_programs',
circle: {
radius: data.radius,
center: [data.centerCoord[0], data.centerCoord[1]]
}
}, uuid());
});

/**
* Refresh poi markers for the given subdomain
*/
Expand Down
35 changes: 33 additions & 2 deletions src/app/store/reducer/hike-edit-poi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Action, ActionReducer, ActionReducerMap, combineReducers } from '@ngrx/
import { createEntityAdapter, EntityAdapter } from '@ngrx/entity';
import {
IHikeEditPoiState, IWikipediaPoiEntityState, IGooglePoiEntityState, IOsmAmenityPoiEntityState,
IOsmNaturalPoiEntityState, IOsmRoutePoiEntityState, IExternalPoiListContextState
IOsmNaturalPoiEntityState, IOsmRoutePoiEntityState, IExternalPoiListContextState, IGTrackPoiEntityState
} from '../state';
import { IWikipediaPoi, IGooglePoi, IOsmPoi } from 'app/shared/interfaces';
import { hikeEditPoiActions } from '../index';
Expand Down Expand Up @@ -144,6 +144,35 @@ const wikipediaPoiReducer: ActionReducer<IWikipediaPoiEntityState> = (
}
}

/**
* gTrack
*/

export const gTrackPoiAdapter: EntityAdapter<IPoi> = createEntityAdapter<IPoi>();
export const gTrackPoiInitialState = gTrackPoiAdapter.getInitialState();

const gTrackPoiReducer: ActionReducer<IGTrackPoiEntityState> = (
state: IGTrackPoiEntityState = gTrackPoiInitialState,
action: hikeEditPoiActions.AllHikeEditPoiActions
): IGTrackPoiEntityState => {
switch (action.type) {
case hikeEditPoiActions.SET_GTRACK_POIS: {
return wikipediaPoiAdapter.addAll(action.payload.pois, state);
}
/*
case hikeEditPoiActions.SET_GTRACK_POI_IN_HIKE:
return wikipediaPoiAdapter.updateOne({
id: action.payload.poiId,
changes: {
inHike: action.payload.isInHike
}
}, state);
*/
default:
return state;
}
}

/**
* Context
*/
Expand All @@ -158,7 +187,8 @@ export const externalPoiInitialContextState: IExternalPoiListContextState = {
osmAmenity: initialContextItemState,
osmNatural: initialContextItemState,
osmRoute: initialContextItemState,
wikipedia: initialContextItemState
wikipedia: initialContextItemState,
gTrack: initialContextItemState
};

export function externalPoiListContextReducer(
Expand Down Expand Up @@ -307,6 +337,7 @@ const reducerMap: ActionReducerMap<IHikeEditPoiState> = {
osmAmenityPois: osmAmenityPoiReducer,
osmNaturalPois: osmNaturalPoiReducer,
osmRoutePois: osmRoutePoiReducer,
gTrackPois: gTrackPoiReducer,
contexts: externalPoiListContextReducer
};

Expand Down

0 comments on commit e094fb1

Please sign in to comment.