Mouse position

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.
| # %pip install "leafmap[maplibre]"
|
| import ipywidgets as widgets
import leafmap.maplibregl as leafmap
|
To run this notebook, you will need an API key from MapTiler. Once you have the API key, you can uncomment the following code block and replace YOUR_API_KEY with your actual API key. Then, run the code block code to set the API key as an environment variable.
| # import os
# os.environ["MAPTILER_KEY"] = "YOUR_API_KEY"
|
| m = leafmap.Map(center=[-74.5, 40], zoom=9, style="streets")
m
|
| 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
|
