flask-extensions / Flask-GoogleMaps

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

Filter option for markers #41

Closed VelizarVESSELINOV closed 1 year ago

VelizarVESSELINOV commented 7 years ago

It will be nice to be able to filter by type of markers, example

Display:

getcake commented 3 years ago

@VelizarVESSELINOV Hey I know this is super old but did you ever find a good way of doing this?

getcake commented 1 year ago

@VelizarVESSELINOV Hey I know this is super old but did you ever find a good way of doing this?

I do not plan on implementing this as a permanent feature, however if anyone's curious as to how this could (sloppily) be done, this is what I did:

filterMarkers = function(category) {

    for (i = 0; i < {{gmap.varname}}_markers.length; i++) {
        marker ={{gmap.varname}}_markers[i];
        // If is same category or category not picked
        if (marker.category == category || category.length === 0) {
            marker.setVisible(true);
        }
        // Categories don't match 
        else {
            marker.setVisible(false);
        }
    }
}
    def build_marker_dict(self, marker, icon=None):
        # type: (Union[List, Tuple], Optional[Icon]) -> Dict
        marker_dict = {
            "lat": marker[0],
            "lng": marker[1],
            "icon": icon or DEFAULT_ICON,
            "category": category
        }
        if len(marker) > 2:
            marker_dict["infobox"] = marker[2]
        if len(marker) > 3:
            marker_dict["icon"] = marker[3]
        if len(marker) > 4:
            marker_dict["category"] = marker[4]
        return marker_dict