Skip to content

Commit

Permalink
Use HomeIcon for user loc
Browse files Browse the repository at this point in the history
  • Loading branch information
OlliV committed Oct 29, 2023
1 parent 5c42214 commit 6861a2f
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 15 deletions.
34 changes: 21 additions & 13 deletions components/map/Marker.tsx
Original file line number Diff line number Diff line change
@@ -1,28 +1,36 @@
'use client';
import L from 'leaflet';
import { Marker, Popup } from 'react-leaflet';
import { ReactNode } from 'react';
import { renderToString } from 'react-dom/server';
import MarkerIcon from '../../node_modules/leaflet/dist/images/marker-icon.png';
import MarkerShadow from '../../node_modules/leaflet/dist/images/marker-shadow.png';
import { ReactNode } from 'react';

export function createMarkerIcon() {
return new L.Icon({
iconUrl: MarkerIcon.src,
iconRetinaUrl: MarkerIcon.src,
iconSize: [25, 41],
iconAnchor: [12.5, 41],
popupAnchor: [0, -41],
shadowUrl: MarkerShadow.src,
shadowSize: [41, 41],
});
export function createMarkerIcon(icon?: ReactNode ) {
if (icon) {
return L.divIcon({
html: renderToString(icon),
className: null,
});
} else {
return new L.Icon({
iconUrl: MarkerIcon.src,
iconRetinaUrl: MarkerIcon.src,
iconSize: [25, 41],
iconAnchor: [12.5, 41],
popupAnchor: [0, -41],
shadowUrl: MarkerShadow.src,
shadowSize: [41, 41],
});
}
}

export default function MapMarker({ position, children }: { position: [number, number]; children?: ReactNode }) {
export default function MapMarker({ icon, position, children }: { icon?: ReturnType<typeof createMarkerIcon>; position: [number, number]; children?: ReactNode; }) {
return (
<Marker
position={position}
// @ts-ignore
icon={createMarkerIcon()}
icon={createMarkerIcon(icon)}
>
<Popup>{children}</Popup>
</Marker>
Expand Down
5 changes: 3 additions & 2 deletions pages/ride/map/index.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import dynamic from 'next/dynamic';
import { useEffect, useMemo, useState } from 'react';
import Box from '@mui/material/Box';
import Container from '@mui/material/Container';
import Grid from '@mui/material/Grid';
Expand All @@ -7,7 +8,7 @@ import Button from '@mui/material/Button';
import Switch from '@mui/material/Switch';
import FormGroup from '@mui/material/FormGroup';
import FormControlLabel from '@mui/material/FormControlLabel';
import { useEffect, useMemo, useState } from 'react';
import IconHome from '@mui/icons-material/Home';
import MyHead from '../../../components/MyHead';
import Title from '../../../components/Title';
import OpenStreetMap from '../../../components/map/OpenStreetMap';
Expand Down Expand Up @@ -113,7 +114,7 @@ export default function RideMap() {
</Stack>

<DynamicMap center={coord} setMap={setMap}>
<DynamicMapMarker position={coord}>You are here.</DynamicMapMarker>
<DynamicMapMarker icon={<IconHome/>} position={coord}>You are here.</DynamicMapMarker>
{editMode ? <DynamicMapEditCourse initialCourse={course} setCourse={setCourse} /> : null}
{course && !editMode ? <DynamicCourse course={course} /> : null}
</DynamicMap>
Expand Down

1 comment on commit 6861a2f

@vercel
Copy link

@vercel vercel bot commented on 6861a2f Oct 29, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

bfree – ./

bfree.vercel.app
bfree-git-master-olliv.vercel.app
bfree-olliv.vercel.app

Please sign in to comment.