Skip to content

Commit

Permalink
Merge branch 'main' into ALS-1902_political-view
Browse files Browse the repository at this point in the history
  • Loading branch information
its-aazizi committed Nov 27, 2024
2 parents 9665e5c + 0a3c6d6 commit 5af0be9
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 7 deletions.
8 changes: 7 additions & 1 deletion src/atomicui/pages/DemoPage/DemoPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ const DemoPage: FC = () => {
const mapRef = useRef<MapRef | null>(null);
const geolocateControlRef = useRef<GeolocateControlRef | null>(null);
const { userProvidedValues } = useAuth();
const { currentLocationData, viewpoint, mapColorScheme } = useMap();
const { currentLocationData, viewpoint, mapColorScheme, setBiasPosition } = useMap();
const { zoom, setZoom } = usePlace();
const { routeData, directions } = useRoute();
const { isEditingRoute } = useTracker();
Expand Down Expand Up @@ -389,6 +389,12 @@ const DemoPage: FC = () => {
onClick={handleMapClick}
onLoad={onLoad}
onZoom={({ viewState }) => setZoom(viewState.zoom)}
onZoomEnd={({ viewState }) => {
setBiasPosition([viewState.longitude, viewState.latitude]);
}}
onDragEnd={({ viewState }) => {
setBiasPosition([viewState.longitude, viewState.latitude]);
}}
onError={error => errorHandler(error.error)}
onIdle={() => gridLoader && setGridLoader(false)}
attributionControl={false}
Expand Down
3 changes: 3 additions & 0 deletions src/hooks/useMap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@ const useMap = () => {
setMapPoliticalView: (mapPoliticalView: { alpha2: string; alpha3: string; desc: string }) => {
setState({ mapPoliticalView });
},
setBiasPosition: (biasPosition: number[]) => {
setState({ biasPosition });
},
resetStore() {
setState({
currentLocationData: undefined
Expand Down
9 changes: 4 additions & 5 deletions src/services/usePlaceService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ const {

const usePlaceService = () => {
const { placesClient } = useClient();
const { viewpoint, mapPoliticalView } = useMap();
const { mapPoliticalView, biasPosition: BiasPosition } = useMap();
const { i18n } = useTranslation();
const Language = i18n.language;

Expand All @@ -32,7 +32,7 @@ const usePlaceService = () => {
getPlaceSuggestions: async (QueryText: string) => {
const input: SuggestCommandInput = {
QueryText,
BiasPosition: [viewpoint?.longitude as number, viewpoint?.latitude as number],
BiasPosition,
Language,
AdditionalFeatures: ["Core"],
PoliticalView: mapPoliticalView.alpha3 || undefined
Expand All @@ -54,7 +54,7 @@ const usePlaceService = () => {
const input: SearchTextCommandInput = {
QueryText: isQueryId ? undefined : QueryTextOrId,
QueryId: isQueryId ? QueryTextOrId : undefined,
BiasPosition: isQueryId ? undefined : [viewpoint?.longitude as number, viewpoint?.latitude as number],
BiasPosition: isQueryId ? undefined : BiasPosition,
Language: isQueryId ? undefined : Language,
PoliticalView: mapPoliticalView.alpha3 || undefined
};
Expand All @@ -71,7 +71,6 @@ const usePlaceService = () => {
return await placesClient?.send(command);
},
getNLPlacesByText: async (Text: string) => {
const BiasPosition = [viewpoint?.longitude as number, viewpoint?.latitude as number];
const response = await fetch(
`${NL_BASE_URL}/places/ask?` +
new URLSearchParams([
Expand All @@ -94,7 +93,7 @@ const usePlaceService = () => {
return responseBody;
}
}),
[viewpoint, Language, mapPoliticalView, placesClient]
[BiasPosition, Language, mapPoliticalView.alpha3, placesClient]
);
};

Expand Down
4 changes: 3 additions & 1 deletion src/stores/useMapStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ interface MapStoreProps {
mapStyle: MapStyleEnum;
mapColorScheme: MapColorSchemeEnum;
mapPoliticalView: { alpha2: string; alpha3: string; desc: string };
biasPosition: number[];
}

const initialState: IStateProps<MapStoreProps> = {
Expand All @@ -47,7 +48,8 @@ const initialState: IStateProps<MapStoreProps> = {
alpha2: "",
alpha3: "",
desc: "no_political_view.text"
}
},
biasPosition: [US.longitude, US.latitude]
};

export default createStore<MapStoreProps>(initialState, true, localStorageKey);

0 comments on commit 5af0be9

Please sign in to comment.