Skip to main content

Create beautiful JavaScript maps with one line of Python

Project description

Mapkick.py

Create beautiful JavaScript maps with one line of Python. No more fighting with mapping libraries!

See it in action

For static maps, check out Mapkick Static.py, and for charts, check out Chartkick.py

Build Status

Installation

Run:

pip install mapkick

Mapkick uses Mapbox GL JS v1. To use tiles from Mapbox, create a Mapbox account to get an access token and set MAPBOX_ACCESS_TOKEN in your environment.

Then follow the instructions for your web framework:

Django

Add to INSTALLED_APPS in settings.py

INSTALLED_APPS = [
    'mapkick.django',
    # ...
]

Load the JavaScript

{% load static %}

<script src="{% static 'mapkick.bundle.js' %}"></script>

Create a map in a view

from mapkick.django import Map

def index(request):
    map = Map([{'latitude': 37.7829, 'longitude': -122.4190}])
    return render(request, 'home/index.html', {'map': map})

And add it to the template

{{ map }}

Flask

Register the blueprint

from mapkick.flask import mapkick_blueprint

app.register_blueprint(mapkick_blueprint)

Load the JavaScript

<script src="{{ url_for('mapkick.static', filename='mapkick.bundle.js') }}"></script>

Create a map in a route

from mapkick.flask import Map

def index():
    map = Map([{'latitude': 37.7829, 'longitude': -122.4190}])
    return render_template('home/index.html', map=map)

And add it to the template

{{ map }}

Maps

Point map

Map([{'latitude': 37.7829, 'longitude': -122.4190}])

Area map

AreaMap([{'geometry': {'type': 'Polygon', 'coordinates': ...}}])

Data

Data can be a list

Map([{'latitude': 37.7829, 'longitude': -122.4190}])

Or a URL that returns JSON (same format as above)

Map('/restaurants')

Point Map

Use latitude or lat for latitude and longitude, lon, or lng for longitude

You can specify a label, tooltip, and color for each data point

{
  'latitude': ...,
  'longitude': ...,
  'label': 'Hot Chicken Takeover',
  'tooltip': '5 stars',
  'color': '#f84d4d'
}

Area Map

Use geometry with a GeoJSON Polygon or MultiPolygon

You can specify a label, tooltip, and color for each data point

{
  'geometry': {'type': 'Polygon', 'coordinates': ...},
  'label': 'Hot Chicken Takeover',
  'tooltip': '5 stars',
  'color': '#0090ff'
}

Options

Width and height

Map(data, width='800px', height='500px')

Marker color

Map(data, markers={'color': '#f84d4d'})

Show tooltips on click instead of hover

Map(data, tooltips={'hover': False})

Allow HTML in tooltips (must sanitize manually)

Map(data, tooltips={'html': True})

Map style

Map(data, style='mapbox://styles/mapbox/outdoors-v12')

Zoom and controls

Map(data, zoom=15, controls=True)

Refresh data from a remote source every n seconds

Map(url, refresh=60)

Pass options directly to the mapping library

Map(data, library={'hash': True})

See the documentation for Mapbox GL JS for more info

History

View the changelog

Contributing

Everyone is encouraged to help improve this project. Here are a few ways you can help:

To get started with development:

git clone https://github.com/ankane/mapkick.py.git
cd mapkick.py
pip install -r requirements.txt
pytest

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

mapkick-0.2.0.tar.gz (221.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

mapkick-0.2.0-py3-none-any.whl (220.0 kB view details)

Uploaded Python 3

File details

Details for the file mapkick-0.2.0.tar.gz.

File metadata

  • Download URL: mapkick-0.2.0.tar.gz
  • Upload date:
  • Size: 221.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.12.7

File hashes

Hashes for mapkick-0.2.0.tar.gz
Algorithm Hash digest
SHA256 879d4b69114f6b2e8de19de0519771ffda13ff662375e7c2959f05e3d2d0c9dd
MD5 9397206fd5e5dea427f0cf5b48f42f35
BLAKE2b-256 267fe8c1758ecaea3730b9384020b4843766eebff341636d11d1ba4c97af1011

See more details on using hashes here.

File details

Details for the file mapkick-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: mapkick-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 220.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.12.7

File hashes

Hashes for mapkick-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 b2601c0d5e19694a48fc0b394342c5d4fc5d34ddec3524e14ac811959c71faf7
MD5 0f054273bcdbfb916d7fab313586db1c
BLAKE2b-256 0d47b2b4726d0e75d97458a1ac6aa3514135a774e5f2c8486777a2e11e3fa649

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page