diff --git a/src/app/pages/hike-edit/components/hike-edit-pois-gtrack/hike-edit-pois-gtrack.component.ts b/src/app/pages/hike-edit/components/hike-edit-pois-gtrack/hike-edit-pois-gtrack.component.ts index e87e3713..97ef51a4 100644 --- a/src/app/pages/hike-edit/components/hike-edit-pois-gtrack/hike-edit-pois-gtrack.component.ts +++ b/src/app/pages/hike-edit/components/hike-edit-pois-gtrack/hike-edit-pois-gtrack.component.ts @@ -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, @@ -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 ) {} @@ -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) { /* diff --git a/src/app/store/actions/hike-edit-poi.ts b/src/app/store/actions/hike-edit-poi.ts index 10a64cd5..70d2fd4d 100644 --- a/src/app/store/actions/hike-edit-poi.ts +++ b/src/app/store/actions/hike-edit-poi.ts @@ -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'; @@ -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 */ @@ -207,6 +229,8 @@ export type AllHikeEditPoiActions = | GetWikipediaPois | SetWikipediaPois | SetWikipediaPoiInHike + | GetGTrackPois + | SetGTrackPois | ToggleOnrouteMarkers | ToggleOffrouteMarkers | GenerateSubdomainPoiMarkers diff --git a/src/app/store/effects/hike-edit-poi.ts b/src/app/store/effects/hike-edit-poi.ts index e56bc9a3..21e017da 100644 --- a/src/app/store/effects/hike-edit-poi.ts +++ b/src/app/store/effects/hike-edit-poi.ts @@ -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 { @@ -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 { @@ -135,6 +137,23 @@ export class HikeEditPoiEffects { }); }); + /** + * Get gTrack pois from db + */ + @Effect() + getGtrackPois$: Observable = 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 */ diff --git a/src/app/store/reducer/hike-edit-poi.ts b/src/app/store/reducer/hike-edit-poi.ts index edaf5f79..efd6437a 100644 --- a/src/app/store/reducer/hike-edit-poi.ts +++ b/src/app/store/reducer/hike-edit-poi.ts @@ -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'; @@ -144,6 +144,35 @@ const wikipediaPoiReducer: ActionReducer = ( } } +/** + * gTrack + */ + +export const gTrackPoiAdapter: EntityAdapter = createEntityAdapter(); +export const gTrackPoiInitialState = gTrackPoiAdapter.getInitialState(); + +const gTrackPoiReducer: ActionReducer = ( + 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 */ @@ -158,7 +187,8 @@ export const externalPoiInitialContextState: IExternalPoiListContextState = { osmAmenity: initialContextItemState, osmNatural: initialContextItemState, osmRoute: initialContextItemState, - wikipedia: initialContextItemState + wikipedia: initialContextItemState, + gTrack: initialContextItemState }; export function externalPoiListContextReducer( @@ -307,6 +337,7 @@ const reducerMap: ActionReducerMap = { osmAmenityPois: osmAmenityPoiReducer, osmNaturalPois: osmNaturalPoiReducer, osmRoutePois: osmRoutePoiReducer, + gTrackPois: gTrackPoiReducer, contexts: externalPoiListContextReducer };