Get coordinates of the mouse pointer
This source code of this example is adapted from the MapLibre GL JS example - Get coordinates of the mouse pointer.
Uncomment the following line to install leafmap if needed.
In [1]:
Copied!
# %pip install "leafmap[maplibre]"
# %pip install "leafmap[maplibre]"
In [2]:
Copied!
import ipywidgets as widgets
import leafmap.maplibregl as leafmap
import ipywidgets as widgets
import leafmap.maplibregl as leafmap
In [3]:
Copied!
# import os
# os.environ["MAPTILER_KEY"] = "YOUR_API_KEY"
# import os
# os.environ["MAPTILER_KEY"] = "YOUR_API_KEY"
In [4]:
Copied!
m = leafmap.Map(center=[-74.5, 40], zoom=9, style="streets")
m
m = leafmap.Map(center=[-74.5, 40], zoom=9, style="streets")
m
Failed to retrieve the MapTiler style. Defaulting to 'dark-matter' style.
In [5]:
Copied!
m.clicked
m.clicked
Out[5]:
{}
In [6]:
Copied!
output = widgets.Output()
def log_lng_lat(lng_lat):
with output:
output.clear_output()
print(lng_lat.new)
m.observe(log_lng_lat, names="clicked")
output
output = widgets.Output()
def log_lng_lat(lng_lat):
with output:
output.clear_output()
print(lng_lat.new)
m.observe(log_lng_lat, names="clicked")
output