CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/pypi-gmaps

Google maps plugin for Jupyter notebooks with interactive visualization capabilities

Pending
Overview
Eval results
Files

figure-map.mddocs/

Figure and Map Management

Core functionality for creating and managing interactive map figures with Google Maps integration, viewport control, and layer composition. The Figure is the main entry point for displaying maps in Jupyter notebooks.

Capabilities

Configuration

Configure global settings for accessing the Google Maps API.

def configure(api_key=None):
    """
    Configure access to the GoogleMaps API.

    Parameters:
    - api_key (str, optional): String denoting the key to use when accessing Google maps, or None to not pass an API key

    Returns:
    None
    """

Figure Creation

Create a new map figure with customizable display options and initial viewport settings.

def figure(display_toolbar=True, display_errors=True, zoom_level=None, tilt=45, center=None, layout=None, map_type='ROADMAP', mouse_handling='COOPERATIVE'):
    """
    Create a gmaps figure.

    Parameters:
    - display_toolbar (bool): Whether to display the toolbar
    - display_errors (bool): Whether to display error messages
    - zoom_level (int, optional): Initial zoom level (0-21)
    - tilt (int): Tilt angle in degrees (0 or 45)
    - center (tuple, optional): Initial center as (latitude, longitude)
    - layout (dict, optional): Widget layout configuration
    - map_type (str): Map display type ('ROADMAP', 'SATELLITE', 'HYBRID', 'TERRAIN')
    - mouse_handling (str): Mouse interaction mode ('COOPERATIVE', 'GREEDY', 'NONE', 'AUTO')

    Returns:
    Figure: A new Figure instance
    """

Figure Widget

Main figure widget for displaying maps with layers and interactive elements.

class Figure:
    """
    Figure widget for displaying Google Maps in Jupyter notebooks.
    
    Attributes:
    - map_type (str): Map display type
    - tilt (int): Tilt angle in degrees
    - mouse_handling (str): Mouse interaction mode
    - layout (dict): Widget layout configuration
    """
    
    def add_layer(self, layer):
        """
        Add a data layer to the figure.

        Parameters:
        - layer: Layer instance (Heatmap, Markers, GeoJson, etc.)

        Returns:
        None
        """

Map Widget

Base map widget that handles Google Maps integration and viewport management.

class Map:
    """
    Base map widget for Google Maps integration.
    
    Attributes:
    - layers (list): List of map layers
    - data_bounds (list): Geographic bounds of data as [[south, west], [north, east]]
    - initial_viewport (InitialViewport): Initial zoom and center settings
    """
    
    def add_layer(self, layer):
        """
        Add layer to map.

        Parameters:
        - layer: Layer instance to add

        Returns:
        None
        """

Viewport Configuration

Configure the initial viewport settings for maps.

class InitialViewport:
    """
    Viewport configuration for maps.
    
    Attributes:
    - zoom_level (int): Zoom level (0-21)
    - center (tuple): Center coordinates as (latitude, longitude)
    """
    
    @staticmethod
    def from_data_bounds():
        """
        Create viewport centered on data bounds.

        Returns:
        InitialViewport: Configured viewport that automatically centers on map data
        """
    
    @staticmethod
    def from_zoom_center(zoom_level, center):
        """
        Create viewport with explicit zoom and center.

        Parameters:
        - zoom_level (int): Zoom level (0-21)
        - center (tuple): Center as (latitude, longitude)

        Returns:
        InitialViewport: Configured viewport
        """

Usage Examples

Basic Figure Creation

import gmaps

# Configure API access
gmaps.configure(api_key="YOUR_API_KEY")

# Create a basic figure
fig = gmaps.figure()
fig

Customized Figure

import gmaps

# Create figure with custom settings
fig = gmaps.figure(
    center=(37.7749, -122.4194),  # San Francisco
    zoom_level=10,
    map_type='SATELLITE',
    mouse_handling='GREEDY',
    layout={'height': '600px', 'width': '100%'}
)
fig

Adding Multiple Layers

import gmaps
import gmaps.datasets

gmaps.configure(api_key="YOUR_API_KEY")

# Create figure
fig = gmaps.figure(center=(37.7749, -122.4194), zoom_level=10)

# Add heatmap layer
earthquake_data = gmaps.datasets.load_dataset_as_df('earthquakes')
locations = earthquake_data[['latitude', 'longitude']]
heatmap = gmaps.heatmap_layer(locations)
fig.add_layer(heatmap)

# Add marker layer
marker_locations = [(37.7749, -122.4194), (37.7849, -122.4094)]
markers = gmaps.marker_layer(marker_locations)
fig.add_layer(markers)

fig

Install with Tessl CLI

npx tessl i tessl/pypi-gmaps

docs

datasets.md

directions.md

drawing.md

figure-map.md

geojson.md

heatmap.md

index.md

markers.md

transportation.md

tile.json