Skip to content

filter map (or other visualization page) to a subset of the collection #103

Closed

Description

@eastofesten

I want to have be able to show the map & timeline for a subset of my collection as well as my full collection. The subset will be based on location (for example, I want to be able to show the map for "New York" and have a separate map for all items including New York.) I should be able to do this by editing the map-js.html like so:
`{%- assign items = items | where_exp: 'item', 'item.objectid != nil' | where_exp: 'item','item.latitude' -%}

{%- capture place -%}
{{ page.location }}
{%- endcapture -%}

{%- assign items = items[place] -%}`

But this doesn't seem to filter as expected (my New York map shows no items). Is there a recommended way to do such a thing?

Activity

  1. evanwill commented on Nov 13, 2023

    @evanwill
    Contributor

    @sheishistoric you want to create a "New York" specific version of the map page that only has points for the items with "New York" as the location?

    I would add that as another where_exp in the Liquid setting up the "items", after the existing ones. It would look something like:

    {%- assign items = items | where_exp: 'item', 'item.objectid != nil' | where_exp: 'item','item.latitude' | where_exp: 'item', 'item.location == "New York"' -%}
    

    That would set up the "items" as the subset you want, then you won't need to modify anything else below.
    If you are creating multiple map pages in the collection, a simple approach is to create multiple copies of the "map-js.html", like "map-js-newyork.html" that contain your individual customizations.

  2. eastofesten commented on Nov 14, 2023

    @eastofesten
    Author
  3. evanwill commented on Nov 14, 2023

    @evanwill
    Contributor

    Oh actually, I think I see what you mean better--> like you would like to be able to set the "location" in the page front matter so you could use the map layout for multiple different map pages?

    So that would be possible with a quick customization of the map-js.html file-->
    replace the "_includes/js/map-js.html" in your project repository with this customized version.

    This version supports the options "location", "latitude", "longitude", and "zoom" in the page front matter. With no front matter, the map will be the standard CB map. To create a new customized map page with the data filtered by a specific value in the "location" column, you would add front matter options in the yml front matter of the page:

    ---
    title: Custom Map
    layout: map
    permalink: /map-example.html
    location: "Moscow, Idaho"
    latitude: 46.727485 
    longitude: -117.014185
    zoom: 12
    ---
    
    

    You could create additional pages with the "layout: map", and customize each with different options.

    The version I linked above uses this Liquid to filter the items:

    {% if page.location %}
    {%- assign items = items | where_exp: 'item', 'item.location == page.location' -%}
    {% endif %}
    

    So the "location" field would have to match exactly to what you set in the location option.
    You could replace == with contains if you want it to just contain the text in the location option, not exactly match.
    You could replace item.location in the express with a different metadata field if desired, like item.title or item.date etc...

  4. eastofesten commented on Nov 14, 2023

    @eastofesten
    Author

    Okay, yes! That's what I was thinking - thank you.

  5. evanwill commented on Nov 14, 2023

    @evanwill
    Contributor

    I am going to convert this to a Discussion in case other people want to do this!

  6. locked and limited conversation to collaborators on Nov 14, 2023
  7. converted this issue into a discussion #104 on Nov 14, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions