Thursday, 27 May 2021

How to copy a marker's location on folium Map by clicking on it?


I am able to print the location of a given marker on the map using folium.plugins.MousePosition.
class GeoMap:
        
    def update(self, location_center:np.array, locations: np.array):
        self.map = folium.Map(location_center, zoom_start=10)
        for i in range(locations.shape[0]):
            location = tuple(locations[i, j] for j in range(locations.shape[1]))
            folium.Marker(
                location=location,
            ).add_to(self.map)
        formatter = "function(num) {return L.Util.formatNum(num, 3) + ' ยบ ';};"
        plugins.MousePosition(
            position="topright",
            separator=" | ",
            empty_string="NaN",
            lng_first=True,
            num_digits=20,
            prefix="Coordinates:",
            lat_formatter=formatter,
            lng_formatter=formatter,
        ).add_to(self.map)
        
    def display(self):
        display(self.map)

But, I would like to enable the user to copy a marker's location on a folium Map by clicking on it. I suppose that there may be a way to get the location of a marker using a on_click event (in Python). But, I did not find any example on the web.

I am using Python, but if you have a solution that works well using Python and some Javascript it will be fine too.

Any help would be really appreciated !

Thanks,



from How to copy a marker's location on folium Map by clicking on it?

No comments:

Post a Comment