-
-
Notifications
You must be signed in to change notification settings - Fork 60
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
Access to Marker Object(s) #132
Comments
Hi @mepa1363, The first thing you can do (and is officially supported) is to set your default marker options during in plugin initalization: var geocoder = L.control.geocoder('<your-api-key>', {
markers: {
draggable: true
}
}).addTo(map); Notice that I assigned the geocoder to a variable. This way I have access to it later, and read the console.log(geocoder.markers); // --> [ Array ]
geocoder.markers[0].setPopupContent('Hello world'); The array represents any markers that are currently visible, so if something in the plugin clears the markers on the map, then the references to that marker are cleaned up as well. Referring to the markers in this way is not documented but I think it's useful if it were officially supported, so please give it a try and let me know what you think. If we can iron out any kinks in this implementation then I'll go ahead and release it as a documented feature in a future version. |
Hi @louh, Thanks for your help. Everything worked well except for the function that unbinds (disable) the popup. Is there any way to disable popups? One more thing; I am using two geocoder controls in a single interface. Since the markers are draggable, I am sending the coordinates to the Mapzen reverse geocoder to get the address back. Now I want to change the text in the associated search box accordingly. Is there a built-in function to that? Thanks. |
Re: disabling popups. Hmm. It might be hard because the plugin binds and shows the popup immediately so there's not a way to hook into that and modify the behavior (without hacks). I did write a proposal for a popup option that would allow you to control its behavior, here: #72, which we would need to build into the plugin. Let me know if that would work the way you'd expect. Re: changing text in the search box after a reverse geocode - it sounds like you've implemented your own reverse geocoding functionality that occurs on marker dragging. You can set the input in the text box like this: geocoder._input.value = 'Your text'; (Assuming you have
|
Hi @louh, Thanks so much for you help. It works like a charm. |
I would like to know if there is a way (besides hacking the code) to get access to the marker object(s). What I'm looking for is to disable popup (or change its content), and to make the marker draggable.
Thanks.
The text was updated successfully, but these errors were encountered: