flask-extensions / Flask-GoogleMaps

Easy way to add GoogleMaps to Flask applications. maintainer: @getcake
https://flask-googlemaps.com
MIT License
647 stars 196 forks source link

Add heatmap layer #151

Closed getcake closed 3 years ago

getcake commented 3 years ago

147 requests the ability to add a heatmap layer as seen here

A heatmap layer can be enabled by asserting heatmap_layer = True within the Map object.

In order to build the heatmap, it requires its own list of coordinates, containing a dictionary with lat and lng values exclusively.

Below is a small example of one way this could be done.

@app.route("/")
def heatmap():

    data = [
        {
            "lat": 37.782551,
            "lng": -122.445368,
        },
        {
            "lat": 37.782745,
            "lng": -122.444586,
        },
        {
            "lat": 37.782842,
            "lng": -122.443688,
        },
        {
            "lat": 37.782919,
            "lng": -122.442815,
        },
    ]

    heatmap_example = Map(
        identifier="heatmap_example",
        lat=37.775,
        lng=-122.434,
        heatmap_layer=True,
        heatmap_data=[(d) for d in data],
    )

    return render_template("example.html", heatmap_example=heatmap_example)

Which will look something like this

image