-
Notifications
You must be signed in to change notification settings - Fork 109
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
feat: created 'Circle' geometry component (#105) #178
feat: created 'Circle' geometry component (#105) #178
Conversation
First of all: WOW! Thanks so much for this. I hope I can make time later today to review, but from a quick glance looks amazing 🤩 |
Initial Valuesshould we add an const [center, setCenter] = React.useState({lat: 41.23296, lng: -95.877363});
const [radius, setRadius] = React.useState(15000);
return (
<>
<Circle
radius={radius}
center={center}
onRadiusChange={setRadius}
onCenterChange={setCenter}
draggable
editable
/>
<Circle
radius={10000}
center={{lat: 41, lng: -95}}
draggable
editable
/>
</>
) in the case above, because we have one controlled component and one that is uncontrolled |
23cf88c
to
e4b2b21
Compare
This is all very excellent stuff. I'm impressed by the overall quality of your work! I will definitely have a closer look at some point and adapt some of the patterns you used in the tests. I will add some notes to the code for some smaller issues I spotted. The only thing I would like to see changed for now is to move all additions you made to the main source tree into the example folder. So The lat/lng library functions can stay, but they could go together with the existing The reasoning for this is that we want to take additions to the main library a bit slower, and give new features some time to mature as part of the examples. This also gives us some time to think about if and how exactly we want to add them to the library (I wrote a bite more about this here). In the end I want to prevent having to make changes to features after they are merged and published with the library, and thus trigger a major release. On the other hand, I don't see a problem with updating the code of an example if we discover a way to do things differently. |
I've shuffled things around as you suggested - components and docs are now part of the "geometry" example. I went ahead and bundled up the About the tests, I scrapped them. They were pretty much a copy-pasta job from the marker tests with a few tweaks. Nothing too fancy. And yeah, I'm totally get your approach of taking it slow before shoving stuff into the main package. Letting things marinate a bit sounds like a smart move. Let's me know about anything else. Cheers |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Excellent, thanks. A couple more small notes, then we can get this merged.
examples/geometry/src/polygons.ts
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This file, without any comment kinda scares me. Should at least state what data this is, why it looks like this and how it was generated.
Maybe can be renamed to encoded-polygon-data.ts
or something like that to make this more clear.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah that a big scary file, TBH i took this from the project i'm working on, maybe it is better to simplify it to a simple triangle?
I just thought it looked cool XD
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, thats perfectly fine, examples should be looking interesting and useful :)
I think it just needs a comment that those are polygons of the districts of Omaha, Nebraska (?) in the encoded polyline algorithm format, with a link to this: https://developers.google.com/maps/documentation/utilities/polylinealgorithm and maybe a link to some tool you used to generate them.
to mitigate an inifinite re-render when the <Circle /> is being controlled, I've splitted the radius, and center from the other events, because they are listened to. I've added a equality guard before calling the setCenter and setRadius
I was using useMemo (sync) instead of useEffect (async) to update the google.maps.circle instance when the props where changing, causing setState to the parent when the child was rendering
can recieve `encodedPaths` instead of `paths`
merged docs to the example README merged both contorl panel to be in the same one added comments and docs
956c466
to
2625207
Compare
Again, thanks a lot. Last thing to do is to update the website files to add the example to the overview page, do you want to do that? The steps for that are described here: https://visgl.github.io/react-google-maps/docs/guides/writing-examples#adding-examples-to-the-website |
No problem, let's do things all the way. |
I have implemented a new React component for rendering circles on Google Maps within the existing library. Drawing inspiration from the
Marker
component, I made some code refinements, such as relocating the callbacks (e.g.,onClick
,onDrag
) to a ref. This adjustment ensures that theuseEffect
does not need to be re-executed unnecessarily, addressing potential issues with un-memoized functions passed by the parent component. I encountered this issue involving an infinite feedback loop caused by this scenario.Furthermore, I've included a sample application under
geometry
that showcases the circle component. This app allows users to interact with and manipulate the circle either through the map or via input controls.I've also based the doc on the
Marker
markdown file.This is my first time PR to an open-source project, so if i missed something, the feedback is welcome, thanks
Changes Made
geometry
) demonstrating circle manipulation via map interactions and input controls.docs/circle.md
file for easy reference.