Skip to content

Commit

Permalink
fix hook order error, nextjs loader issue
Browse files Browse the repository at this point in the history
  • Loading branch information
akursat committed Dec 28, 2022
1 parent 04b6317 commit 26acc0f
Show file tree
Hide file tree
Showing 9 changed files with 9,368 additions and 596 deletions.
8 changes: 4 additions & 4 deletions examples/custom-marker-cluster/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,16 @@
"@testing-library/react": "^11.1.0",
"@testing-library/user-event": "^12.1.10",
"@types/jest": "^26.0.15",
"@types/leaflet": "^1.5.23",
"@types/leaflet": "^1.9.0",
"@types/leaflet.markercluster": "^1.4.3",
"@types/node": "^12.0.0",
"@types/react": "^18.0.0",
"@types/react-dom": "^18.0.0",
"leaflet": "^1.8.0",
"leaflet": "^1.9.0",
"react": "^18.0.0",
"react-dom": "^18.0.0",
"react-leaflet": "^4.0.0",
"react-leaflet-cluster": "^2.0.0",
"react-leaflet": "^4.1.0",
"react-leaflet-cluster": "^2.1.0",
"react-scripts": "4.0.2",
"typescript": "^4.1.2",
"web-vitals": "^1.0.1"
Expand Down
94 changes: 50 additions & 44 deletions examples/custom-marker-cluster/src/App.tsx
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='&copy; <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='&copy; <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
18 changes: 18 additions & 0 deletions examples/custom-marker-cluster/src/index.d.ts
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;
8 changes: 4 additions & 4 deletions examples/ten-thousand-marker/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,16 @@
"@testing-library/react": "^11.1.0",
"@testing-library/user-event": "^12.1.10",
"@types/jest": "^26.0.15",
"@types/leaflet": "^1.5.23",
"@types/leaflet": "^1.9.0",
"@types/leaflet.markercluster": "^1.4.3",
"@types/node": "^12.0.0",
"@types/react": "^18.0.0",
"@types/react-dom": "^18.0.0",
"leaflet": "^1.8.0",
"leaflet": "^1.9.0",
"react": "^18.0.0",
"react-dom": "^18.0.0",
"react-leaflet": "^4.0.0",
"react-leaflet-cluster": "^2.0.0",
"react-leaflet": "^4.1.0",
"react-leaflet-cluster": "^2.1.0",
"react-scripts": "4.0.2",
"typescript": "^4.1.2",
"web-vitals": "^1.0.1"
Expand Down
Loading

0 comments on commit 26acc0f

Please sign in to comment.