Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[#8447] react/maps: fix GeoJsonMarker not updating on prop change for Icon #1697

Merged
merged 1 commit into from
Nov 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions adhocracy4/maps_react/static/a4maps_react/GeoJsonMarker.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ const createGeoJsonMarker = ({ feature, ...props }, context) => {

const updateGeoJsonMarker = (instance, { feature, ...props }, prevProps) => {
const coords = [...feature.geometry.coordinates].reverse()
if (props.icon !== prevProps.icon) {
instance.setIcon(props.icon)
}
instance.setLatLng(coords)
}

Expand Down
2 changes: 2 additions & 0 deletions changelog/8447.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
### Changes
- fixed a bug where the GeoJsonMarker would not update if passing new props for `icon`
7 changes: 7 additions & 0 deletions docs/react_maps.md
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,13 @@ marker with a custom icon on the map.
* **...rest**: [Any other option](https://leafletjs.com/reference.html#marker)
that you could pass to L.marker

### Change the icon

If you find yourself in a situation where you want to change the icon, for example
when you want to highlight a marker that's currently active, you can pass `GeoJsonMarker`
a `icon` prop. You can generate that by using the helper function mentioned below
or call `L.icon` yourself to create an icon instance.

### makeIcon

You can find this utility function in `GeoJsonMarker.js`. It creates and returns
Expand Down