-
Notifications
You must be signed in to change notification settings - Fork 154
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
React-Leaflet v3 #87
Comments
I have the same problem! any solution? |
Hello, are you sure you have installed react-leaflet and leaflet-draw ? |
I was only able to use it by downgrading "react-leaflet" to 2.7.0
|
I took a stab at refactoring this; I only dumped about a half hour into it/copied the most basic pattern from the docs, so it's ugly and doesn't use their cleaner, custom hooks but it works for my use case. Didn't rigorously test all the eventHandlers either. Please reply with improvements if you iterate on it
|
I got this error
|
when i link to another route , i'll get an error like this |
@srghma react-leaflet upgrade to v3, MapControl and withLeaflet is not fond in old version |
@chaosJS I'm not working directly on react-leaflet-draw, but I can accept pr |
I confirm that react-leaflet-draw 0.19.0 is incompatible with react-leaflet 3.0.0 and higher. |
Does this fix the issue? If so, would you please make a PR? |
I can try this, but I don't know how to get started. I am new. So I have forked you repo, clone and everything. How can I run your code after making changes to src/EditControl.js |
@srghma Please check my pr and merge. @abewartech @ehsan-sotoodeh @MarcoGiorgi @bokurev @r2dliu @L4brax @ Guys tried to update the library, waiting for the comments from the collaborator. |
Hello guys, thanks for the PR @DVGY , are you going to release it as a new version? |
@cargaralo I don't have rights to release to non, only @alex3165 have |
@cargaralo Thanks! It Can only released by the owner. For the time being you can define your own cutom file |
Just to give a different possibility, we solved this the way react-leaflet probably intended. Since we had to extract the import { useCallback, useEffect, useRef } from 'react';
import leaflet, { Control } from 'leaflet';
import Draw from 'leaflet-draw';
import {
useLeafletContext,
createElementHook,
createLeafComponent,
} from '@react-leaflet/core';
const createControlComponent = (createInstance) => {
function createElement(props, context) {
const { layerContainer } = context;
const { position } = props;
const options = {
position,
edit: {
featureGroup: layerContainer,
},
};
return { instance: createInstance(options), context };
}
const useElement = createElementHook(createElement);
const useControl = createControlHook(useElement);
return createLeafComponent(useControl);
};
const createControlHook = (useElement) => {
return function useLeafletControl(props) {
const context = useLeafletContext();
const elementRef = useElement(props, context);
const { instance } = elementRef.current;
const positionRef = useRef(props.position);
const { position, onCreated, onEdit, onDeleted } = props;
const onDrawCreate = useCallback(
(e) => {
context.layerContainer.addLayer(e.layer);
onCreated(e);
},
[context.layerContainer, onCreated]
);
useEffect(
function addControl() {
instance.addTo(context.map);
context.map.on(leaflet.Draw.Event.CREATED, onDrawCreate);
if (onDeleted) {
context.map.on(leaflet.Draw.Event.DELETED, onDeleted);
}
if (onEdit) {
context.map.on(leaflet.Draw.Event.EDITRESIZE, onEdit);
context.map.on(leaflet.Draw.Event.EDITMOVE, onEdit);
}
return function removeControl() {
context.map.off(leaflet.Draw.Event.CREATED, onDrawCreate);
if (onDeleted) {
context.map.off(leaflet.Draw.Event.DELETED, onDeleted);
}
if (onEdit) {
context.map.off(leaflet.Draw.Event.EDITRESIZE, onEdit);
context.map.off(leaflet.Draw.Event.EDITMOVE, onEdit);
}
instance.remove();
};
},
[context.map, instance, onDrawCreate, onDeleted, onEdit]
);
useEffect(
function updateControl() {
if (position != null && position !== positionRef.current) {
instance.setPosition(position);
positionRef.current = position;
}
},
[instance, position]
);
return elementRef;
};
}; Then, to add a custom control: export const EditOnlyControl = createControlComponent(
(options) =>
new Control.Draw({
...options,
draw: {
polyline: false,
polygon: false,
rectangle: false,
circle: false,
marker: false,
circlemarker: false,
},
})
); Of course, it still needs to be used inside a |
@davis3tnpolitics, Alex is not working on project anymore, I have rights to github repo, but not for npm, do the new version won't be released, but it is merged, yes, I would suggest to install from github master itself if this is possible |
Thank you!! |
@srghma
Can you fix this? I can work around it with |
WARNING in ./node_modules/react-leaflet-draw/dist/esm/EditControl.js 131:2-12
"export 'MapControl' was not found in 'react-leaflet'
WARNING in ./node_modules/react-leaflet-draw/dist/esm/EditControl.js 184:15-26
"export 'withLeaflet' was not found in 'react-leaflet'
The text was updated successfully, but these errors were encountered: