-
Notifications
You must be signed in to change notification settings - Fork 935
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
How can I "edit" Polygons and update state to match? #278
Comments
@zeroasterisk You need to use refs for the polygon that triggered the event.
on this function you receive the polygon and then you can iterate each of its paths to get the lat and lng values |
this adds the listener on every mousedown |
No, on mouse down it sends the ref of the polygon element that triggered it, with the ref then you can get the polygon position etc. |
Try using Also, 6.0.0 is released on npm beta tag now. See the changelog here. We also have a new demo page. Feel free to try it: |
Please refer to Getting Help section in the README (or #469). |
Thank you @iamgutz, that was very helpful. Here is a slightly more up to date way of doing it.
|
Hi @zeroasterisk ! Did you manage to resolve this? I am having the same issue right now. |
Hi @davidjbradshaw ! Thanks for your answer. I have a question with regards to the update of What I'm doing: Reason for doing this: What is the problem: I'm wondering what did I do wrong that causes this problem? Any help would be appreciated! |
Hi @davidjbradshaw , I find the problem why ONLY the first time Solution: |
Hi,
The props updates properly but Polygon doesn't. I first had the path as an state in same component but I felt it would work if I update it in parent component and pass it as props, but it didn't fix. I read this forum and some others but I couldn't find out the answer. Thank you |
if you add a ref to the polygon, you can call .Path() and .Paths from, the ref.
newPath will be the new coordinates, where polygon is reference to the |
@davidjbradshaw , @liutongchen : |
im having this issue now and how can we updated the ref value with hooks? cant seem to get the updated paths after editing the polygon |
If I allow editable polygons, I can listen for
onMouseup
and get back some "stuff" but I don't see anything which tells me which polygon I've just updated.I have
this.state.polygons
as an array of polygon objects which contain paths...[{"id":0,"editable":true,"path":[{"lat":38.25764366831546,"lng":-85.7516598701477},{"lat":38.25656530505969,"lng":-85.75185298919678},{"lat":38.25808174881664,"lng":-85.75474977493286}],"area":16623.009493033773,"options":{"fillColor":"#caebba"}}]
What I'm looking for is (I think) a way to update state from what happens to be drawn/edited... either for all Polygons, or for the edited one... but I can't seem to find a listener which tells me which one it is...
NOTE - I know that if I draw the polygons with drawing tools, I have events
onOverlaycomplete
andonPolygoncomplete
to use and link into w/ more options (raw google map objects) but that doesn't help me when I create with<Polygon />
The text was updated successfully, but these errors were encountered: