-
Notifications
You must be signed in to change notification settings - Fork 52
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
Support for React #24
Comments
This plugin is not supported anymore. It's best to just fork it. |
As it might be helpful for @luisjose24 and some others: Thats how I used leaflet-hotline with react-leaflet. import { useMap } from "react-leaflet";
import L from "leaflet";
interface Props {
data: number[][];
}
/**
* Renderes a path on the map for the passed geojson file
* that changes color according to the elevation.
*
* https://github.com/iosphere/Leaflet.hotline/
*/
export const ColoredPath: React.FC<Props> = (props: Props) => {
const map = useMap();
useEffect(() => {
L.hotline(data, {
// my options
}).addTo(map);
return () => {
// To avoid having the path drawn twice on the map in some edge cases:
map.remove();
};
}, []);
return null;
}; leaflet-hotline.d.ts import * as L from "leaflet";
declare module "leaflet" {
export function hotline(data: number[][], options: any): any;
} Then you can just use Even though this repo is not supported for a long time now it works like a charm. I did not find anything more up to date. |
For anyone still looking in 2022, here is a way to pretty easily incorporate the hotline package with react-leaflet. hotline.jsx
Then you can just import it the same as you would a react-leaflet component |
Hi @stapleton524 , did you use this approach with react-leaflet v4? |
Hi @lud-hu, I believe I was using react-leaflet v3 (3.2.2 specifically) when I was working on it. |
Thanks! I didn't get it to work with v4. |
Hi, I managed to get it working with v4.
After that you can use it as usual with react. This also enables you to add a Tooltip and updates to the path.
|
For anyone stumbling across this, I have made a react package: https://github.com/peacefulotter/react-leaflet-hotline |
Is it possible to add this plugin to react-leaflet?
The text was updated successfully, but these errors were encountered: