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

How to get a reference to the map in the html #27

Closed loretoparisi closed 8 years ago

loretoparisi commented 8 years ago

I'm rendering this map

map = Map(
        identifier='map',
        style='height:100%;width:100%;top:0;left:0;position:absolute;z-index:200;',
        lat=deflat,
        lng=deflng,
        markers=markers,
        zoom='15', )
    return render_template('map.html', mymap=map)

and in the html

{{mymap.js}}

Now I want to add markers dynamically to this map with jQuery like

var marker = new google.maps.Marker({
    position: myLatlng,
    title:"Hello World!"
});

// To add the marker to the map, call setMap();
marker.setMap(map);

so I need a reference to this map object in the page, so how?

rochacbruno commented 8 years ago

Fixed in 0.2.1 please update and use map as a javascript global, or set Map(varname='foo'...) if you need different name. Thanks

rochacbruno commented 8 years ago

BTW: identifier is the map name to be used in HTML DOM element, varname is the name used in JS. if none passed will be map by default

loretoparisi commented 8 years ago

@rochacbruno 👍