-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix hook order error, nextjs loader issue
- Loading branch information
Showing
9 changed files
with
9,368 additions
and
596 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,64 +1,70 @@ | ||
import React from "react"; | ||
import { MapContainer, Marker, TileLayer } from "react-leaflet"; | ||
import L, { MarkerCluster } from "leaflet"; | ||
import MarkerClusterGroup from "react-leaflet-cluster"; | ||
import "./App.css"; | ||
import "leaflet/dist/leaflet.css"; | ||
import React, { useState } from 'react' | ||
import { MapContainer, Marker, TileLayer } from 'react-leaflet' | ||
import L, { MarkerCluster } from 'leaflet' | ||
import MarkerClusterGroup from 'react-leaflet-cluster' | ||
import './App.css' | ||
import 'leaflet/dist/leaflet.css' | ||
|
||
const customIcon = new L.Icon({ | ||
iconUrl: require('./location.svg').default, | ||
iconSize: new L.Point(40, 47), | ||
}) | ||
|
||
// NOTE: iconCreateFunction is running by leaflet, which is not support ES6 arrow func syntax | ||
// eslint-disable-next-line | ||
const createClusterCustomIcon = function (cluster: MarkerCluster) { | ||
return L.divIcon({ | ||
return new L.DivIcon({ | ||
html: `<span>${cluster.getChildCount()}</span>`, | ||
className: 'custom-marker-cluster', | ||
iconSize: L.point(33, 33, true), | ||
}) | ||
} | ||
|
||
|
||
function App() { | ||
const [dynamicPosition, setPosition] = useState<L.LatLngExpression>([41.051687, 28.987261]) | ||
|
||
return ( | ||
<div> | ||
<h1>Custom Marker Cluster</h1> | ||
<MapContainer | ||
style={{ height: '500px' }} | ||
center={[38.9637, 35.2433]} | ||
zoom={4} | ||
scrollWheelZoom={true} | ||
> | ||
<TileLayer | ||
attribution='© <a href="http://osm.org/copyright">OpenStreetMap</a> contributors' | ||
url="https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png" | ||
/> | ||
<MarkerClusterGroup | ||
onClick={(e) => console.log('onClick', e)} | ||
iconCreateFunction={createClusterCustomIcon} | ||
maxClusterRadius={150} | ||
spiderfyOnMaxZoom={true} | ||
polygonOptions={{ | ||
fillColor: '#ffffff', | ||
color: '#f00800', | ||
weight: 5, | ||
opacity: 1, | ||
fillOpacity: 0.8, | ||
<h1>Custom Marker Cluster</h1> | ||
<button | ||
onClick={() => { | ||
setPosition([40.051687, 28.987261]) | ||
}} | ||
showCoverageOnHover={true} | ||
> | ||
<Marker position={[36.668754, 29.104185]} icon={customIcon} /> | ||
<Marker position={[40.587613, 36.944535]} icon={customIcon} /> | ||
<Marker position={[40.614681, 43.121517]} icon={customIcon} /> | ||
<Marker position={[38.357641, 38.328708]} icon={customIcon} /> | ||
<Marker position={[41.051687, 28.987261]} title="a title" icon={customIcon} /> | ||
<Marker position={[39.931841, 32.876713]} icon={customIcon} /> | ||
</MarkerClusterGroup> | ||
</MapContainer> | ||
</div> | ||
); | ||
Rerender Marker | ||
</button> | ||
<MapContainer | ||
style={{ height: '500px' }} | ||
center={[36.668754, 35.2433]} | ||
zoom={4} | ||
scrollWheelZoom={true} | ||
> | ||
<TileLayer | ||
attribution='© <a href="http://osm.org/copyright">OpenStreetMap</a> contributors' | ||
url="https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png" | ||
/> | ||
<MarkerClusterGroup | ||
onClick={(e: any) => console.log('onClick', e)} | ||
iconCreateFunction={createClusterCustomIcon} | ||
maxClusterRadius={150} | ||
spiderfyOnMaxZoom={true} | ||
polygonOptions={{ | ||
fillColor: '#ffffff', | ||
color: '#f00800', | ||
weight: 5, | ||
opacity: 1, | ||
fillOpacity: 0.8, | ||
}} | ||
showCoverageOnHover={true} | ||
> | ||
<Marker position={[36.668754, 29.104185]} icon={customIcon} /> | ||
<Marker position={[40.587613, 36.944535]} icon={customIcon} /> | ||
<Marker position={[40.614681, 43.121517]} icon={customIcon} /> | ||
<Marker position={[38.357641, 38.328708]} icon={customIcon} /> | ||
<Marker position={dynamicPosition} title={'test'} /> | ||
<Marker position={[39.931841, 32.876713]} icon={customIcon} /> | ||
</MarkerClusterGroup> | ||
</MapContainer> | ||
</div> | ||
) | ||
} | ||
|
||
export default App; | ||
export default App |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import React from 'react'; | ||
import L, { LeafletMouseEventHandlerFn } from 'leaflet'; | ||
import 'leaflet.markercluster'; | ||
import './assets/MarkerCluster.css'; | ||
import './assets/MarkerCluster.Default.css'; | ||
declare type ClusterEvents = { | ||
onClick?: LeafletMouseEventHandlerFn; | ||
onDblClick?: LeafletMouseEventHandlerFn; | ||
onMouseDown?: LeafletMouseEventHandlerFn; | ||
onMouseUp?: LeafletMouseEventHandlerFn; | ||
onMouseOver?: LeafletMouseEventHandlerFn; | ||
onMouseOut?: LeafletMouseEventHandlerFn; | ||
onContextMenu?: LeafletMouseEventHandlerFn; | ||
}; | ||
declare const MarkerClusterGroup: React.ForwardRefExoticComponent<L.MarkerClusterGroupOptions & { | ||
children: React.ReactNode; | ||
} & ClusterEvents & React.RefAttributes<L.MarkerClusterGroup>>; | ||
export default MarkerClusterGroup; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.