Skip to content
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

Add support for displaying spectral profiles from in situ data #105

Closed
giswqs opened this issue Aug 5, 2024 · 0 comments · Fixed by #106
Closed

Add support for displaying spectral profiles from in situ data #105

giswqs opened this issue Aug 5, 2024 · 0 comments · Fixed by #106

Comments

@giswqs
Copy link
Member

giswqs commented Aug 5, 2024

A proof of concept.

import matplotlib.pyplot as plt
from ipyleaflet import Map, Marker, Popup
from ipywidgets import Output

# Sample data
points = [
    {'name': 'Point 1', 'location': [40.7128, -74.0060], 'data': [1, 2, 3, 4, 5]},
    {'name': 'Point 2', 'location': [34.0522, -118.2437], 'data': [2, 3, 4, 5, 6]},
    {'name': 'Point 3', 'location': [37.7749, -122.4194], 'data': [3, 4, 5, 6, 7]},
]

# Function to create the chart
def create_chart(data, title):
    fig, ax = plt.subplots(figsize=(10, 6))  # Adjust the figure size here
    ax.plot(data)
    ax.set_title(title)
    ax.set_xlabel('Time')
    ax.set_ylabel('Value')
    output = Output(layout={'width': '400px', 'height': '300px'})  # Adjust the output widget size here
    with output:
        plt.show()
    return output

# Create a map
m = Map(center=[39.8283, -98.5795], zoom=4)

# Define a callback function to create and show the popup
def callback_with_popup_creation(point):
    def f(**kwargs):
        marker_center = kwargs['coordinates']
        marker_name = point['name']
        marker_data = point['data']
        output = create_chart(marker_data, marker_name)
        popup = Popup(
            location=marker_center,
            child=output,
            min_width=400,
            max_width=800  # Adjust the max width here
        )
        m.add_layer(popup)
    return f

# Add points to the map
for point in points:
    marker = Marker(location=point['location'], title=point['name'])
    marker.on_click(callback_with_popup_creation(point))
    m.add_layer(marker)

# Display the map
m.layout.height = '600px'
m

image

@giswqs giswqs changed the title Add support for display spectral profiles from in situ data Add support for displaying spectral profiles from in situ data Aug 5, 2024
@giswqs giswqs linked a pull request Aug 5, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant