You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Instead of importing `Marker` from `react-leaflet`, instead import `Marker` from `react-leaflet-component-marker`.
36
38
37
39
The `icon` prop is extended to allow for a JSX element of your choosing. All other props are identical to the `react-leaflet`[Marker](https://react-leaflet.js.org/docs/api-components/#marker) API.
38
40
39
41
The `icon` prop can also accept all of the original types of icons that the underlying `react-leaflet` Marker accepts. Though there is no gain in using this library for this case, it may help if you want to just use this library in place of Marker universally.
40
42
41
-
### Basic Example
43
+
####Basic Example
42
44
43
45
```javascript
44
46
importReactfrom'react'
@@ -69,3 +71,19 @@ const App = () => {
69
71
)
70
72
}
71
73
```
74
+
75
+
### Advanced Sizing and Positioning
76
+
77
+
Note, that it is often possible to achieve the desired effect by use of margins/padding on the React icon component itself. However, in some cases, adjustments may be needed to get pixel perfect like popup positioning
78
+
79
+
`iconComponentOpts` can be passed which provides a subset of the [options](https://leafletjs.com/reference.html#icon) that can be passed to an underlying leaflet icon, which is used by this library as an intermediary wrapper. It should be considered an escape hatch.
80
+
81
+
`iconComponentLayout` can be passed to control the alignment and size of the React component. It defaults to `fit-content`, meaning the React Component decides its own size and is not constrained by `iconSize` (which defaults to `[0,0]`). The library automatically handles the alignment of the component such that it is centred horizontally with the marker coordinates, regardless of the component's size (which can even change dynamically). Note the anchor options that can be passed to `iconComponentOpts` remain functional with `fit-content`.
82
+
83
+
If more granular control is needed, `iconComponentLayout` can be set `fit-parent` which defers all sizing and positioning to leaflets configuration options, that can be provided via the aforementioned `iconComponentOpts`. This means you will likely need to pass an `iconSize` to `iconComponentOpts`. In this mode, the React icon component should also have a root element that has a width and height of 100%, and it should prevent overflowing. The downside to this approach is the component size is inherently static. The upside is Leaflet knows about the icon size, and so the default anchor coordinates for other elements like popups, will be likely closer to the default expectations.
84
+
85
+
### Gotchas
86
+
87
+
Currently, if any options in `iconComponentOpts` have a material change (new `iconSize` or changed anchors), the React Component will completely remount and lose any state it had. This will be fixed in a future release.
88
+
89
+
Hot reloading causes markers to disappear. This will be fixed in a future release.
/** A {@link ReactElement} representing the Markers icon, or any type from [react-leaflet Marker](https://react-leaflet.js.org/docs/api-components/#marker) component. */
* The {@link DivIconOptions} (except for the `html` property and properties that are not relevant in the context of a React driven marker) that are to be supplied to the `div` wrapper for the leaflet-managed wrapper of the React icon component.
37
+
*
38
+
* By default, `iconSize` is set to `[0,0]`, which is useful when combined with an "auto" `iconComponentSize` in order to allow for dynamically sized React icon markers.
39
+
*
40
+
* Typically, it is not necessary to override these options, and doing so may lead to unexpected results for some properties.
41
+
*
42
+
* These options are only effective when a React element/component is being used for the `icon` prop.
43
+
**/
44
+
iconComponentOpts?: Omit<
45
+
DivIconOptions,
46
+
'html'|'bgPos'|'shadowAnchor'|'shadowRetinaUrl'
47
+
>
48
+
49
+
/**
50
+
* `"fit-content"` disregards the `iconSize` passed to leaflet (defaults to `[0,0]`) and allows the React icon marker to be determined by the size of the provided component itself (which could be dynamic). Automatic alignment compensation is
51
+
* added to ensure the icon component stays centred on the X axis with the marker.
52
+
*
53
+
* `'fit-parent'` will set the container of the component to be the same size as the `iconSize`. Typically, this is used alongside a static `iconSize` that is passed via `iconComponentOpts`. This setup may allow for more granular control over positioning and anchor configuration. The user supplied Icon component itself should have a root element that has 100% width and height.
54
+
*
55
+
* This option is not effective if `icon` is not a React element/component.
0 commit comments