Flask-GoogleMaps icon indicating copy to clipboard operation
Flask-GoogleMaps copied to clipboard

Filter option for markers

Open VelizarVESSELINOV opened this issue 9 years ago • 1 comments

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

Display:

  • [ ] Blue markers
  • [ ] Red markers
  • [x] Green markers

VelizarVESSELINOV avatar Sep 22 '16 04:09 VelizarVESSELINOV

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

getcake avatar Jul 19 '21 02:07 getcake

@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:

  • first, adding this function to gmapjs.html
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);
        }
    }
}
  • then, within the build_marker_dict function of __init__.py, adding a "category" field like so:
    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

getcake avatar Dec 01 '22 19:12 getcake