Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Call one map instance for details page (instead of two) #939

Merged
merged 3 commits into from
Jul 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 15 additions & 45 deletions frontend/src/components/Map/DetailsMap/DetailsMap.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,13 @@ import { useTileLayer } from 'hooks/useTileLayer';
import { TrekChildGeometry, TrekFamily } from 'modules/details/interface';
import { SensitiveAreaGeometry } from 'modules/sensitiveArea/interface';
import { VisibleSectionContext } from 'components/pages/details/VisibleSectionContext';
import { colorPalette, desktopOnly, MAX_WIDTH_MOBILE } from 'stylesheet';
import { useDetailsAndMapContext } from 'components/pages/details/DetailsAndMapContext';
import { Check } from 'components/Icons/Check';
import { FormattedMessage } from 'react-intl';
import { InformationDesk } from 'modules/informationDesk/interface';
import { SignageDictionary } from 'modules/signage/interface';
import { InfrastructureDictionary } from 'modules/infrastructure/interface';
import { cn } from 'services/utils/cn';
import { BackButton } from '../components/BackButton';

import { TrekMarkersAndCourse } from './TrekMarkersAndCourse';
Expand Down Expand Up @@ -66,7 +66,7 @@ export type PropsType = {
trekGeoJSON?: string;
pointsReference?: Coordinate2D[] | null;
hideMap?: () => void;
type: 'DESKTOP' | 'MOBILE';
hasZoomControl: boolean;
openFilterMenu?: () => void;
hasFilters?: boolean;
arrivalLocation?: Coordinate2D;
Expand Down Expand Up @@ -136,19 +136,20 @@ export const DetailsMap: React.FC<PropsType> = props => {
}, [map, center]);

const { visibleSection } = useContext(VisibleSectionContext);
const mapWrapperProps = {
...(visibleSection === 'report' &&
reportVisibility && {
className: 'with-report',
}),
};

const hasTitle = Boolean(props.title);

return (
<MapWrapper {...mapWrapperProps}>
<StyledMapContainer
className="mapContainer"
<div
className={cn(
'relative w-full h-full',
visibleSection === 'report' &&
reportVisibility &&
"after:content-[''] after:absolute after:inset-0 desktop:after:top-1 after:border-solid after:border-3 after:border-red after:pointer-events-none",
)}
>
<MapContainer
className={cn('mapContainer w-full h-full', hasTitle && 'hasDrawer')}
scrollWheelZoom
maxZoom={
navigator.onLine
Expand All @@ -158,10 +159,9 @@ export const DetailsMap: React.FC<PropsType> = props => {
minZoom={
navigator.onLine ? undefined : Math.min(...(mapConfig?.zoomAvailableOffline ?? []))
}
zoomControl={props.type === 'DESKTOP'}
zoomControl={props.hasZoomControl}
whenCreated={setMapInstance}
bounds={bounds}
hasDrawer={hasTitle}
>
<TileLayerManager />
{reportVisibility && coordinatesReportTouched ? (
Expand Down Expand Up @@ -269,39 +269,9 @@ export const DetailsMap: React.FC<PropsType> = props => {
/>
</div>
)}
</StyledMapContainer>
</MapWrapper>
</MapContainer>
</div>
);
};

const MapWrapper = styled.div`
position: relative;
width: 100%;
height: 100%;
&.with-report::after {
content: '';
position: absolute;
top: 0;
right: 0;
bottom: 0;
left: 0;
border: 3px solid ${colorPalette.red};
pointer-events: none;
@media (min-width: ${MAX_WIDTH_MOBILE}px) {
top: 2px;
}
}
`;

const StyledMapContainer = styled(MapContainer)<{ hasDrawer: boolean }>`
width: 100%;
height: 100%;
.leaflet-bottom {
margin-bottom: ${props => (props.hasDrawer ? '50px' : 0)};
${desktopOnly(css`
margin-bottom: 0;
`)}
}
`;

export default DetailsMap;
8 changes: 4 additions & 4 deletions frontend/src/components/Map/SearchMap/MapContainer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,22 @@ import { Map } from 'leaflet';

interface Props {
whenCreated: (map: Map) => void;
type: string;
hasZoomControl?: boolean;
children: React.ReactNode;
}

const MapContainer: React.FC<Props> = ({ children, whenCreated, type }) => {
const MapContainer: React.FC<Props> = ({ children, whenCreated, hasZoomControl = false }) => {
const mapConfig = getMapConfig();

return (
<LeafMapContainer
className="w-full h-full"
center={mapConfig.searchMapCenter as [number, number]}
zoom={mapConfig.searchMapZoom}
maxZoom={mapConfig.maximumZoomLevel}
whenCreated={whenCreated}
scrollWheelZoom
style={{ height: '100%', width: '100%' }}
zoomControl={type === 'DESKTOP'}
zoomControl={hasZoomControl}
id="search_map"
>
{children}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import { useListAndMapContext } from '../../../modules/map/ListAndMapContext';
export type PropsType = {
segments?: { x: number; y: number }[];
hideMap?: () => void;
type: 'DESKTOP' | 'MOBILE';
openFilterMenu?: () => void;
hasFilters?: boolean;
arrivalLocation?: { x: number; y: number };
Expand Down
4 changes: 2 additions & 2 deletions frontend/src/components/Map/SearchMap/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import TileLayerManager from '../components/TileLayerManager';
export type PropsType = {
segments?: { x: number; y: number }[];
hideMap?: () => void;
type: 'DESKTOP' | 'MOBILE';
hasZoomControl?: boolean;
openFilterMenu?: () => void;
hasFilters?: boolean;
arrivalLocation?: { x: number; y: number };
Expand All @@ -37,7 +37,7 @@ const SearchMap: React.FC<PropsType> = props => {
const { setMapInstance } = useTileLayer();

return (
<MapContainer whenCreated={setMapInstance} type={props.type}>
<MapContainer whenCreated={setMapInstance} hasZoomControl={props.hasZoomControl}>
{props.onMove && <MoveHandler onMove={props.onMove} />}
<TileLayerManager />
<BackButton icon={<ArrowLeft size={24} />} onClick={hideMap} />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ interface TouristicContentGeometryNullable {
export type PropsType = {
touristicContentGeometry: TouristicContentGeometryNullable;
hideMap?: () => void;
type: 'DESKTOP' | 'MOBILE';
hasZoomControl: boolean;
bbox: Bbox;
};

Expand All @@ -63,6 +63,7 @@ export const TouristicContentMap: React.FC<PropsType> = props => {
return (
<>
<MapContainer
className="w-full h-full"
scrollWheelZoom
maxZoom={
navigator.onLine
Expand All @@ -72,9 +73,8 @@ export const TouristicContentMap: React.FC<PropsType> = props => {
minZoom={
navigator.onLine ? undefined : Math.min(...(mapConfig?.zoomAvailableOffline ?? []))
}
style={{ height: '100%', width: '100%' }}
whenCreated={setMapInstance}
zoomControl={props.type === 'DESKTOP'}
zoomControl={props.hasZoomControl}
bounds={center}
attributionControl={false}
>
Expand Down
Loading
Loading