Skip to content

Add custom markers feature and remove streamlit deprecated configurations - #139

Open
migueljgranizo wants to merge 6 commits into
marceloprates:mainfrom
migueljgranizo:feature/GH-1-add-custom-markers
Open

Add custom markers feature and remove streamlit deprecated configurations#139
migueljgranizo wants to merge 6 commits into
marceloprates:mainfrom
migueljgranizo:feature/GH-1-add-custom-markers

Conversation

@migueljgranizo

Copy link
Copy Markdown

This PR introduces a custom markers feature that allows users to place visual symbols at specific coordinates on maps,
and updates Streamlit components to use the new parameter names to fix deprecation warnings.

Changes

✨ Custom Markers Feature

New Functionality

  • Added draw_custom_markers() function in prettymaps/draw.py:493 for rendering custom markers on maps
  • Integrated custom markers into the plot() function via custom_markers parameter
  • Full preset integration with markers.default_style configuration

Coordinate Format Support
The implementation supports three flexible ways to specify marker locations:

  1. Explicit coordinates: {'lat': 52.3676, 'lon': 4.9041, ...}
  2. Tuple query: {'query': (52.3676, 4.9041), ...}
  3. String query (geocoding): {'query': 'Amsterdam Central Station', ...}

String queries leverage OpenStreetMap Nominatim for automatic geocoding, allowing users to specify locations by name.

Validation & Safety

  • Coordinate range validation (lat: -90 to 90, lon: -180 to 180)
  • Automatic bounds checking to skip markers outside map perimeter
  • Graceful error handling with optional logging for skipped markers

Styling Options
Each marker supports full customization:

  • marker: Matplotlib marker style (circle, star, triangle, etc.)
  • size: Marker size in points²
  • color: Face color (hex or named)
  • edgecolor: Edge color
  • linewidth: Edge width
  • alpha: Transparency (0.0 to 1.0)
  • zorder: Rendering order

🎨 Streamlit UI Enhancements

Marker Management Interface (app.py:126-327)

  • "Add New Marker" form with flexible location input that auto-detects coordinate vs place name format
  • "Manage Existing Markers" section with edit/delete functionality
  • Real-time marker counter showing {len(st.session_state.custom_markers)} markers
  • Session state management for markers and editing state
  • Collapsible expanders to keep UI clean

User Experience Improvements

  • Smart location parser: automatically detects if input is coordinates or place name
  • Advanced options toggle for edge styling, opacity, and z-order
  • Live preview with marker count and bounds warning
  • Clean marker display showing name, location, type, and color

🔧 Deprecation Fixes

Updated Streamlit Parameters (app.py:469, 521, 531, 540, 549, 555, 558)

  • Replaced deprecated use_container_width=True with width="stretch"
  • Affects:
    • Generate map button
    • Download PNG/SVG buttons
    • Image displays (generated map and placeholder)
  • Fixes Streamlit v1.37+ deprecation warnings

File Handling Improvements (app.py:521-531)

  • Proper file reading with context managers to avoid resource warnings
  • Pre-read file data before passing to st.download_button()

📚 Documentation

Comprehensive README Section (README.md:1059-1285)

  • Complete feature overview and comparison table (custom markers vs keypoints)
  • Usage examples for all three coordinate formats
  • Full parameter reference table
  • Advanced styling examples
  • Validation and bounds checking explanation
  • Preset integration guide
  • Streamlit frontend user guide

Technical Details

Implementation Location

  • prettymaps/draw.py:493-647: Core draw_custom_markers() function
  • app.py:29-35: Session state initialization
  • app.py:126-327: UI components
  • app.py:493: Integration with prettymaps.plot() call

Dependencies

  • Uses existing OSMnx geocoding for string queries (ox.geocode())
  • GeoPandas for marker geometry management
  • Matplotlib for marker rendering

Breaking Changes

None. This is a purely additive feature with backward compatibility maintained.

Captura de pantalla 2025-12-09 121450 Captura de pantalla 2025-12-09 121510

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 this pull request may close these issues.

1 participant