Merge branch 'feature/map_group_items' into 'dev'

map pvz and others

See merge request spatial/postamates_frontend!15
dev
Timofey Malinin 3 years ago
commit b879f87445

@ -38,14 +38,22 @@ export const Layers = () => {
<SelectedRegion /> <SelectedRegion />
<Source <Source
id="rivals" id="pvz"
type="vector" type="vector"
tiles={[`${BASE_URL}/martin/public.service_rivals/{z}/{x}/{y}.pbf`]} tiles={[`${BASE_URL}/martin/public.service_post_and_pvz/{z}/{x}/{y}.pbf`]}
> >
<PVZ /> <PVZ />
</Source>
<Source
id="other"
type="vector"
tiles={[`${BASE_URL}/martin/public.service_otherobjects/{z}/{x}/{y}.pbf`]}
>
<OtherPostamates /> <OtherPostamates />
</Source> </Source>
<Points /> <Points />
</> </>
); );

@ -3,8 +3,6 @@ import { otherPostamatesLayer } from "./layers-config";
import { useLayersVisibility } from "../../stores/useLayersVisibility"; import { useLayersVisibility } from "../../stores/useLayersVisibility";
import { LAYER_IDS } from "./constants"; import { LAYER_IDS } from "./constants";
const typeFilter = ["==", ["get", "type"], "post"];
export const OtherPostamates = () => { export const OtherPostamates = () => {
const { isVisible } = useLayersVisibility(); const { isVisible } = useLayersVisibility();
@ -13,12 +11,11 @@ export const OtherPostamates = () => {
<Layer <Layer
{...otherPostamatesLayer} {...otherPostamatesLayer}
id={LAYER_IDS.other} id={LAYER_IDS.other}
source={"rivals"} source={"other"}
source-layer={"public.service_rivals"} source-layer={"public.service_otherobjects"}
layout={{ layout={{
visibility: isVisible[LAYER_IDS.other] ? "visible" : "none", visibility: isVisible[LAYER_IDS.other] ? "visible" : "none",
}} }}
filter={typeFilter}
/> />
</> </>
); );

@ -3,8 +3,6 @@ import { pvzPointLayer } from "./layers-config";
import { useLayersVisibility } from "../../stores/useLayersVisibility"; import { useLayersVisibility } from "../../stores/useLayersVisibility";
import { LAYER_IDS } from "./constants"; import { LAYER_IDS } from "./constants";
const typeFilter = ["==", ["get", "type"], "pvz"];
export const PVZ = () => { export const PVZ = () => {
const { isVisible } = useLayersVisibility(); const { isVisible } = useLayersVisibility();
@ -13,12 +11,11 @@ export const PVZ = () => {
<Layer <Layer
{...pvzPointLayer} {...pvzPointLayer}
id={LAYER_IDS.pvz} id={LAYER_IDS.pvz}
source={"rivals"} source={"pvz"}
source-layer={"public.service_rivals"} source-layer={"public.service_post_and_pvz"}
layout={{ layout={{
visibility: isVisible[LAYER_IDS.pvz] ? "visible" : "none", visibility: isVisible[LAYER_IDS.pvz] ? "visible" : "none",
}} }}
filter={typeFilter}
/> />
</> </>
); );

@ -4,17 +4,17 @@ import {
APPROVE_COLOR, APPROVE_COLOR,
CANCELLED_COLOR, CANCELLED_COLOR,
OTHER_POSTAMATES_COLOR, OTHER_POSTAMATES_COLOR,
PENDING_COLOR, PENDING_COLOR, PVZ_COLOR,
} from "./Layers/layers-config"; } from "./Layers/layers-config";
import {Logo} from "../icons/Logo.jsx"; import {Logo} from "../icons/Logo.jsx";
import {usePostamatesAndPvzGroups} from "../api.js"; import {useOtherGroups, usePostamatesAndPvzGroups} from "../api.js";
import {Collapse, Image} from "antd"; import {Collapse, Image} from "antd";
import React from "react"; import React from "react";
const LegendPointItem = ({color, imageSrc, name}) => { const LegendPointItem = ({color, imageSrc, name}) => {
return ( return (
<div className="flex gap-2 items-center"> <div className="flex gap-2 items-center">
{imageSrc && <Image src={imageSrc} width={12} height={12} preview={false}/>} {imageSrc && <Image src={imageSrc} width={12} height={12} className='flex items-center' preview={false}/>}
{color && !imageSrc && ( {color && !imageSrc && (
<span <span
className="rounded-xl w-3 h-3 inline-block" className="rounded-xl w-3 h-3 inline-block"
@ -50,7 +50,7 @@ const LegendColorRampItem = ({colors, name}) => {
); );
}; };
const LegendGroupItem = ({item}) => { const LegendGroupItem = ({item, color}) => {
return ( return (
<Collapse <Collapse
bordered={false} bordered={false}
@ -62,16 +62,14 @@ const LegendGroupItem = ({item}) => {
> >
<Collapse.Panel <Collapse.Panel
key={"opened"} key={"opened"}
header={<LegendPointItem name={item.name} imageSrc={item.image} color={OTHER_POSTAMATES_COLOR}/>} header={<LegendPointItem name={item.name} imageSrc={item.image} color={color}/>}
showArrow={false}
> >
<div className="ml-3 my-1"> <div className="ml-3 my-1">
{item.groups && item.groups?.map((groupItem) => { {item.groups && item.groups?.map((groupItem) => {
return ( return (
<div className="my-1"> <div key={groupItem.id} className="my-1">
<LegendPointItem <LegendPointItem
key={groupItem.id} color={color}
color={OTHER_POSTAMATES_COLOR}
imageSrc={groupItem.image} imageSrc={groupItem.image}
name={groupItem.name} name={groupItem.name}
/> />
@ -88,6 +86,7 @@ const LegendGroupItem = ({item}) => {
export function Legend() { export function Legend() {
const {mode} = useMode(); const {mode} = useMode();
const {data: postamatesAndPvzGroups} = usePostamatesAndPvzGroups(); const {data: postamatesAndPvzGroups} = usePostamatesAndPvzGroups();
const {data: otherGroups} = useOtherGroups();
return ( return (
<div <div
@ -130,7 +129,12 @@ export function Legend() {
<div className="space-y-1"> <div className="space-y-1">
{postamatesAndPvzGroups && postamatesAndPvzGroups?.map((item) => { {postamatesAndPvzGroups && postamatesAndPvzGroups?.map((item) => {
return <LegendGroupItem key={item.id} item={item}/> return <LegendGroupItem key={item.id} item={item} color={PVZ_COLOR}/>
})}
</div>
<div className="space-y-1">
{otherGroups && otherGroups?.map((item) => {
return <LegendGroupItem key={item.id} item={item} color={OTHER_POSTAMATES_COLOR}/>
})} })}
</div> </div>
</div> </div>

@ -149,6 +149,23 @@ export const usePostamatesAndPvzGroups = () => {
); );
}; };
export const getOtherGroups = async () => {
const { data } = await api.get(
`/api/other_object_groups/`
);
return data;
};
export const useOtherGroups = () => {
return useQuery(
['other_groups'],
async () => {
return await getOtherGroups();
},
);
};
export const useLastMLRun = () => { export const useLastMLRun = () => {
return useQuery( return useQuery(
['last_time'], ['last_time'],

Loading…
Cancel
Save