-
Notifications
You must be signed in to change notification settings - Fork 72
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
Adding a popup window when the user clicks on the Geocoding result #22
Comments
Hey Franclin, |
Hi @codelikepro22 thanks for prompt reply. I was talking about this video: https://www.youtube.com/watch?v=JyPn_o_UJCM What I wanted to achieve was that when I click on a result from the geocoding process and a marker is dropped at the location, I wanted to be able to click on that marker to display a popup window. Hope this makes sense. |
You mean here to show the address of the marker in popup? Otherwise we still don't have the images and the other details of the room added yet. We still in the phase of adding the room and this is one of the steps. |
Yes I mean adding some basic information about the marker in the popup. So basically, here is the typical workflow:
It is the code necessary to display that popup window that I am talking about. |
One last question. Do you need it only after search so you need the same name or address you clicked on in the dropdown menu or you want it even if the user drags the marker to another place then clicks on it later. Because the first one is very easy and very quick and the other one for all the cases it will be little bit slower because you need to communicate every time with mapbox to change the longitude and latitude to real address. On the other side the first one we already have the address as a result from the search in the geocoder |
You know what. I will put here both solutions and you choose the right one for you |
I need it only after the search. Ideally, when the user clicks on the suggestion, the marker appears on the map at the location, then when I click on that marker I want a popup to appear. The content of that popup will be a form. I don't want to handle dragging markers for now (maybe in the future). |
You need to change these files in our project: `import MapBoxGeocoder from '@mapbox/mapbox-gl-geocoder'; const Geocoder = () => { export default Geocoder; src/components/addRoom/addLocation/AddLocation.js `import { Box, Typography } from '@mui/material'; const AddLocation = () => { const [showPopup, setShowPopup] = useState(false); useEffect(() => { return ( export default AddLocation; src/context/ContextProvider.js `import { const initialState = { const Context = createContext(initialState); export const useValue = () => { const ContextProvider = ({ children }) => { export default ContextProvider; |
The slower solution but more efficient for all cases: src/components/addRoom/addLocation/AddLocation.js `import { Box, Typography } from '@mui/material'; const AddLocation = () => { useEffect(() => { return ( export default AddLocation; |
I advise you also to watch all the videos of the project from the beginning to understand what is going on |
Thanks for that. I do have a few other questions please:
So basically, the result geometry coordinates available on line 20 in sidebar/GeocoderInput.js I want to be able to access it from the ClusterMap.js file to display it in the popup. That is what I am trying to achieve and if possible without reducers as my projet is quite simple. I may look into using reducers at a latter version if needed. Thanks for your brilliant answers! |
You always can replace the reducer and global context with local state. Just create new state for location and instead of dispatch just use set state but you need here to pass setLocation as a prop to geocoder |
Thanks a lot for your advice, that works just fine! I will definitely watch the other videos, they are very inspirational, well done! |
Thanks for the brilliant tutorial, really great and helpful. Just wanted to ask you how I can add a popup window when clicking on a marker returned by the Geocoding.
For instance, when you search for the word Mumbai at 15.41 on YouTube, I would like to add a popup info when the user clicks on the blue icon. Any thought how I can achieve that pls?
The text was updated successfully, but these errors were encountered: