File tree Expand file tree Collapse file tree 4 files changed +65
-50
lines changed Expand file tree Collapse file tree 4 files changed +65
-50
lines changed Original file line number Diff line number Diff line change @@ -7,7 +7,6 @@ import MapMarker from "@/components/map/map-marker";
77function MapEventDemo ( ) {
88 const [ position , setPosition ] = useState < [ number , number ] | undefined > ( ) ;
99 const map = useMapEvent ( "click" , ( e ) => {
10- console . log ( e . latlng ) ;
1110 setPosition ( [ e . latlng . lat , e . latlng . lng ] ) ;
1211 } ) ;
1312
Original file line number Diff line number Diff line change 1+ "use client" ;
2+
3+ import { Marker , Popup } from "react-leaflet" ;
4+ import L from "leaflet" ;
5+ import { ReactNode } from "react" ;
6+ import { useClientRenderToString } from "@/hooks/useClientRenderToString" ;
7+ import IconMarkerWall from "../ui/icons/marker-wall" ;
8+ import IconMarkerParking from "../ui/icons/marker-parking" ;
9+ import { IconSize } from "../ui/icons/icon-size" ;
10+
11+ type TLazyMapMarkerProps = {
12+ type : "parking" | "wall" ;
13+ position : [ number , number ] ;
14+ popupContent ?: ReactNode ;
15+ interactive ?: boolean ;
16+ hidden ?: boolean ;
17+ } ;
18+
19+ function LazyMapMarker ( {
20+ type,
21+ position,
22+ popupContent,
23+ interactive = true ,
24+ hidden,
25+ } : TLazyMapMarkerProps ) {
26+ const [ icon ] = useClientRenderToString (
27+ type === "parking" ? (
28+ < IconMarkerParking size = { IconSize . xl } />
29+ ) : (
30+ < IconMarkerWall size = { IconSize . xl } />
31+ )
32+ ) ;
33+
34+ return (
35+ < Marker
36+ icon = { L . divIcon ( {
37+ className : "" ,
38+ html : icon ,
39+ iconSize : [ 52 , 52 ] ,
40+ iconAnchor : [ 26 , 52 ] ,
41+ popupAnchor : [ 0 , - 46 ] ,
42+ } ) }
43+ position = { position }
44+ interactive = { interactive }
45+ opacity = { hidden ? 0 : 1 }
46+ >
47+ { popupContent && < Popup > { popupContent } </ Popup > }
48+ </ Marker >
49+ ) ;
50+ }
51+
52+ export default LazyMapMarker ;
53+ export type { TLazyMapMarkerProps } ;
Original file line number Diff line number Diff line change 1- "use client" ;
1+ import dynamic from "next/dynamic" ;
2+ import { TLazyMapMarkerProps as TMapMarkerProps } from "./lazy-map-marker" ;
23
3- import { Marker , Popup } from "react-leaflet" ;
4- import L from "leaflet" ;
5- import { ReactNode } from "react" ;
6- import { useClientRenderToString } from "@/hooks/useClientRenderToString" ;
7- import IconMarkerWall from "../ui/icons/marker-wall" ;
8- import IconMarkerParking from "../ui/icons/marker-parking" ;
9- import { IconSize } from "../ui/icons/icon-size" ;
4+ const LazyMapMarker = dynamic ( ( ) => import ( "./lazy-map-marker" ) , {
5+ ssr : false ,
6+ } ) ;
107
11- type TMapMarkerProps = {
12- type : "parking" | "wall" ;
13- position : [ number , number ] ;
14- popupContent ?: ReactNode ;
15- interactive ?: boolean ;
16- } ;
17-
18- function MapMarker ( {
19- type,
20- position,
21- popupContent,
22- interactive = true ,
23- } : TMapMarkerProps ) {
24- const [ icon ] = useClientRenderToString (
25- type === "parking" ? (
26- < IconMarkerParking size = { IconSize . xl } />
27- ) : (
28- < IconMarkerWall size = { IconSize . xl } />
29- )
30- ) ;
31-
32- return (
33- < Marker
34- icon = { L . divIcon ( {
35- className : "" ,
36- html : icon ,
37- iconSize : [ 52 , 52 ] ,
38- iconAnchor : [ 26 , 52 ] ,
39- popupAnchor : [ 0 , - 46 ] ,
40- } ) }
41- position = { position }
42- interactive = { interactive }
43- >
44- { popupContent && < Popup > { popupContent } </ Popup > }
45- </ Marker >
46- ) ;
8+ function MapMarker ( props : TMapMarkerProps ) {
9+ return < LazyMapMarker { ...props } /> ;
4710}
4811
4912export default MapMarker ;
Original file line number Diff line number Diff line change @@ -9,9 +9,9 @@ import Button from "./button";
99import Dialog , { DialogSize , DialogTitleSize } from "./dialog" ;
1010import TextField , { TTextFieldProps } from "./text-field" ;
1111import { Dispatch , SetStateAction , useState } from "react" ;
12+ import IconMarker from "./icons/marker" ;
1213import { useMapEvent } from "react-leaflet" ;
1314import MapMarker from "../map/map-marker" ;
14- import IconMarker from "./icons/marker" ;
1515
1616type TCoordinatesInputProps = TTextFieldProps & {
1717 dialogTitle : string ;
@@ -120,10 +120,10 @@ function PlacedMarker({
120120 setPosition ( [ e . latlng . lat , e . latlng . lng ] ) ;
121121 } ) ;
122122
123- return (
124- position && (
125- < MapMarker type = { markerType } position = { position } interactive = { false } />
126- )
123+ return position ? (
124+ < MapMarker type = { markerType } position = { position } interactive = { false } />
125+ ) : (
126+ < MapMarker type = { markerType } position = { [ 0 , 0 ] } interactive = { false } hidden />
127127 ) ;
128128}
129129
You can’t perform that action at this time.
0 commit comments