Complex filter design

I need to build a complex filter for a mapping plugin. The map displays links between different entities. There are many types of entities, each with their own attributes, many types of links between entities and each link can have a direction too.

I need to build a filter for the map, so that users can choose what they want to see on the map. All aspects of the map must be filterable. This means:

Filter by specific entities, filter by entities with specific attributes, filter by entities with specific attributes and specific link directions.

Filter by specific attributes and filter by specific attributes with a specific link direction.

Filter by specific link direction.

In other words, everything must be filterable on every level.

What kind of design patterns can you suggest, or examples, so that the filter system is still fairly intuitive to use, yet includes all of the above?