-
-
Notifications
You must be signed in to change notification settings - Fork 101
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #211 from yuzhva/feat_polygon_docs
[release] 4.1.0: region/bulk support
- Loading branch information
Showing
8 changed files
with
791 additions
and
2,583 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
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,6 +1,7 @@ | ||
export { default as BasicExample } from './basic'; | ||
export { default as EventListeners } from './event-listeners'; | ||
export { default as MarkerClusterOptions } from './marker-cluster-options'; | ||
export { default as MarkerOptions } from './marker-options'; | ||
export { default as MarkerPopup } from './marker-popup'; | ||
export { default as MarkerTooltip } from './marker-tooltip'; | ||
export { default as BasicExample } from "./basic"; | ||
export { default as EventListeners } from "./event-listeners"; | ||
export { default as MarkerClusterOptions } from "./marker-cluster-options"; | ||
export { default as MarkerOptions } from "./marker-options"; | ||
export { default as MarkerPopup } from "./marker-popup"; | ||
export { default as MarkerTooltip } from "./marker-tooltip"; | ||
export { default as RegionExample } from "./region.jsx"; |
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,86 @@ | ||
import React from "react"; | ||
import { Polygon } from "leaflet"; | ||
import { createPathComponent } from "@react-leaflet/core"; | ||
import { MapContainer, TileLayer } from "react-leaflet"; | ||
import MarkerClusterGroup from "../../src/react-leaflet-markercluster"; | ||
import { MAP_ZOOM, MAP_MAX_ZOOM, MAP_CENTER_COORDINATES } from "./constants"; | ||
import "./styles.scss"; | ||
|
||
function randomCoords() { | ||
return [160 * Math.random() - 80, 360 * Math.random() - 180]; | ||
} | ||
|
||
const ClusterableRegion = createPathComponent(function createClusterableRegion( | ||
{ coordinates, color = "blue", fillOpacity = 0.3, onClick }, | ||
ctx, | ||
) { | ||
// Define a clusterable region with a getLatLng method for clustering compatibility | ||
// Credits to https://github.com/Leaflet/Leaflet.markercluster/issues/612#issuecomment-242929562 | ||
const ClusterableRegion = Polygon.extend({ | ||
initialize: function (latlngs, options) { | ||
Polygon.prototype.initialize.call(this, latlngs, options); | ||
this._latlng = this.getBounds().getCenter(); | ||
}, | ||
getLatLng: function () { | ||
return this._latlng; | ||
}, | ||
setLatLng: function () {}, // Dummy method to satisfy marker clustering requirements | ||
}); | ||
|
||
// Instantiate the ClusterablePolygon with provided positions and options | ||
const region = new ClusterableRegion(coordinates, { | ||
color, | ||
fillOpacity, | ||
onclick: onClick, | ||
}); | ||
|
||
return { | ||
instance: region, | ||
context: { | ||
...ctx, | ||
overlayContainer: region, | ||
}, | ||
}; | ||
}); | ||
|
||
const RegionExample = () => ( | ||
<MapContainer | ||
className="markercluster-map" | ||
center={MAP_CENTER_COORDINATES} | ||
zoom={MAP_ZOOM} | ||
maxZoom={MAP_MAX_ZOOM} | ||
> | ||
<TileLayer | ||
url="https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png" | ||
attribution='© <a href="http://osm.org/copyright">OpenStreetMap</a> contributors' | ||
/> | ||
|
||
<MarkerClusterGroup animate={true}> | ||
{Array.from({ length: 42069 }, (_, i) => { | ||
const centerCoords = randomCoords(); | ||
return ( | ||
<ClusterableRegion | ||
key={i} | ||
coordinates={[ | ||
centerCoords, | ||
[ | ||
centerCoords[0] - Math.random(), | ||
centerCoords[1] - Math.random(), | ||
], | ||
[ | ||
centerCoords[0] - Math.random(), | ||
centerCoords[1] + Math.random(), | ||
], | ||
[ | ||
centerCoords[0] + Math.random(), | ||
centerCoords[1] + Math.random(), | ||
], | ||
]} | ||
/> | ||
); | ||
})} | ||
</MarkerClusterGroup> | ||
</MapContainer> | ||
); | ||
|
||
export default RegionExample; |
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.