Skip to content
This repository has been archived by the owner on May 4, 2024. It is now read-only.

Commit

Permalink
conditions-gp | added import files for Road Continditions, comments t…
Browse files Browse the repository at this point in the history
…o be added and dependencies fixed #3
  • Loading branch information
marcosantiagomuro authored and Seb-sti1 committed Sep 12, 2023
1 parent bee86bf commit 1768309
Show file tree
Hide file tree
Showing 23 changed files with 667 additions and 777 deletions.
2 changes: 1 addition & 1 deletion frontend/src/Components/Map/Hooks/useZoom.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { useEffect, useState } from "react"
import { useMapEvents } from "react-leaflet"


//zoom implementation on map events
const useZoom = () => {
const [zoom, setZoom] = useState<number>()

Expand Down
1 change: 1 addition & 0 deletions frontend/src/Components/Map/MapWrapper.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import Zoom from './Zoom';
import '../../css/map.css'
import { MAP_OPTIONS } from './constants';

//container for map and its attributes
const MapWrapper = ( props : any ) => {

const { children } = props;
Expand Down
126 changes: 50 additions & 76 deletions frontend/src/Components/Map/Renderers/DistHotline.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@

import { FC, useEffect, useMemo, useState } from 'react';
import { LeafletEvent, Polyline } from 'leaflet';
import { LeafletEvent, Polyline } from 'leaflet'
import { HotlineOptions, useCustomHotline } from 'react-leaflet-hotline';

import { useGraph } from '../../../context/GraphContext';
Expand All @@ -9,87 +10,60 @@ import { Condition, Node, WayId } from '../../../models/path';
import DistRenderer from '../../../assets/hotline/DistRenderer';
import { DistData } from '../../../assets/hotline/hotline';
import HoverHotPolyline from '../../../assets/hotline/HoverHotPolyline';
import {
HotlineEventFn,
HotlineEventHandlers,
} from 'react-leaflet-hotline/dist/types/types';
import { HotlineEventFn, HotlineEventHandlers } from 'react-leaflet-hotline/lib/types';
import useZoom from '../Hooks/useZoom';
import { useHoverContext } from '../../../context/GraphHoverContext';
import { useHoverContext } from "../../../context/GraphHoverContext";


const getLat = (n: Node) => n.lat;
const getLng = (n: Node) => n.lng;
const getVal = (n: Node) => n.way_dist;
const getWeight = (z: number | undefined) =>
z === undefined ? 0 : Math.max(z > 8 ? z - 6 : z - 5, 2);
const getWeight = (z: number | undefined) => z === undefined ? 0 : Math.max(z > 8 ? z - 6 : z - 5, 2)

interface IDistHotline {
way_ids: WayId[];
geometry: Node[][];
conditions: Condition[][];
options?: HotlineOptions;
eventHandlers?: HotlineEventHandlers;
way_ids: WayId[];
geometry: Node[][];
conditions: Condition[][];
options?: HotlineOptions,
eventHandlers?: HotlineEventHandlers;
}

const handler = (eventHandlers: HotlineEventHandlers | undefined, event: keyof HotlineEventHandlers, opacity: number) => {
return (e: LeafletEvent, i: number, p: Polyline<any, any>) => {
p.setStyle( { opacity } )
if ( eventHandlers && eventHandlers[event] !== undefined )
(eventHandlers[event] as HotlineEventFn)(e, i, p);
}
}

const DistHotline: FC<IDistHotline> = ( { way_ids, geometry, conditions, options, eventHandlers } ) => {

const { dotHover } = useHoverContext()
const zoom = useZoom()

const opts = useMemo( () => ({
...options, weight: getWeight(zoom)
}), [options, zoom] )

const handlers: HotlineEventHandlers = useMemo( () => ({
...eventHandlers,
mouseover: handler(eventHandlers, 'mouseover', 0.5),
mouseout: handler(eventHandlers, 'mouseout', 0),
}), [eventHandlers] )

const { hotline } = useCustomHotline<Node, DistData>(
DistRenderer, HoverHotPolyline,
{ data: geometry, getLat, getLng, getVal, options: opts, eventHandlers: handlers },
way_ids, conditions
);

useEffect( () => {
if ( hotline === undefined ) return;
(hotline as HoverHotPolyline<Node, DistData>).setHover(dotHover)
}, [dotHover])

return null;
}

const handler = (
eventHandlers: HotlineEventHandlers | undefined,
event: keyof HotlineEventHandlers,
opacity: number,
) => {
return (e: LeafletEvent, i: number, p: Polyline<any, any>) => {
p.setStyle({ opacity });
if (eventHandlers && eventHandlers[event] !== undefined)
(eventHandlers[event] as HotlineEventFn)(e, i, p);
};
};

const DistHotline: FC<IDistHotline> = ({
way_ids,
geometry,
conditions,
options,
eventHandlers,
}) => {
const { dotHover } = useHoverContext();
const zoom = useZoom();

const opts = useMemo(
() => ({
...options,
weight: getWeight(zoom),
}),
[options, zoom],
);

const handlers: HotlineEventHandlers = useMemo(
() => ({
...eventHandlers,
mouseover: handler(eventHandlers, 'mouseover', 0.5),
mouseout: handler(eventHandlers, 'mouseout', 0),
}),
[eventHandlers],
);

const { hotline } = useCustomHotline<Node, DistData>(
DistRenderer,
HoverHotPolyline,
{
data: geometry,
getLat,
getLng,
getVal,
options: opts,
eventHandlers: handlers,
},
way_ids,
conditions,
);

useEffect(() => {
if (hotline === undefined) return;
(hotline as HoverHotPolyline<Node, DistData>).setHover(dotHover);
}, [dotHover]);

return null;
};

export default DistHotline;

export default DistHotline;
1 change: 1 addition & 0 deletions frontend/src/Components/Map/Zoom.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import { ZoomControl } from "react-leaflet"
import useZoom from "./Hooks/useZoom"

// implement zoom component on map
const Zoom = () => {

const zoom = useZoom()
Expand Down
67 changes: 27 additions & 40 deletions frontend/src/Components/Palette/PaletteEditor.tsx
Original file line number Diff line number Diff line change
@@ -1,47 +1,34 @@
import { FC, MouseEvent, useState } from 'react';
import { Gradient } from 'react-gradient-hook';
import { CursorOptions } from 'react-gradient-hook/lib/types';
import { useMap } from 'react-leaflet';
import { Palette } from 'react-leaflet-hotline';
import { FC, MouseEvent, useState } from "react";
import { Gradient } from "react-gradient-hook";
import { CursorOptions } from "react-gradient-hook/lib/types";
import { useMap } from "react-leaflet";
import { Palette } from "react-leaflet-hotline";

import '../../css/palette.css';
import '../../css/palette.css'

interface IPaletteEditor {
width: number | undefined;
defaultPalette?: Palette;
cursorOptions?: CursorOptions;
onChange?: (palette: Palette) => void;
width: number | undefined;
defaultPalette?: Palette;
cursorOptions?: CursorOptions;
onChange?: (palette: Palette) => void;
}

const PaletteEditor: FC<IPaletteEditor> = ({
width,
defaultPalette,
cursorOptions,
onChange,
}) => {
const [show, setShow] = useState<boolean>(false);

const toggleAppear = () => setShow((prev) => !prev);

if (width === undefined || width === 0) return null;

return (
<div
className={`palette-wrapper ${show ? 'palette-show' : ''}`}
style={{ width: `${width}px` }}
>
<div className="palette-container">
<Gradient
defaultColors={defaultPalette}
cursorOptions={cursorOptions}
onChange={onChange}
/>
</div>
<div className="palette-hover" onClick={toggleAppear}>
🎨
</div>
</div>
);
};
const PaletteEditor: FC<IPaletteEditor> = ( { width, defaultPalette, cursorOptions, onChange } ) => {

const [show, setShow] = useState<boolean>(false)

const toggleAppear = () => setShow(prev => !prev)

if ( width === undefined || width === 0 ) return null;

return (
<div className={`palette-wrapper ${show ? 'palette-show' : ''}`} style={{width: `${width}px`}} >
<div className="palette-container">
<Gradient defaultColors={defaultPalette} cursorOptions={cursorOptions} onChange={onChange}/>
</div>
<div className='palette-hover' onClick={toggleAppear}>🎨</div>
</div>
)
}

export default PaletteEditor;
Loading

0 comments on commit 1768309

Please sign in to comment.