question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Dynamically create layers with DataFilterExtension

See original GitHub issue

Hi,

I’m currently working on a project that requires user to upload new GeoJson files, create GeoJsonLayers and apply filters on the layer based on the number of additional information the user has. I’m having trouble with getting the data filters to work.

The GeoJson datasets are in the following format

{
    type: "...",
    features: [
        {
            type: "feature",
            properties: {"info1": value1, "info2": value2 ...},
            geometry: {type: "polygon", coordinates: {[..., ..., ...], ....}}
        },
        ..
        ..
        ..
    ]
}

Additional informations are stored in the properties object, stored as key-value pairs.

To create/destroy layers dynamically, I am storing the list of DeckGL layers in an array, I am either appending a new layer to the array, or to delete, search for the layer with the same id and pop it from the array. The array would look like this:

const [list_of_layers, set_list_of_layers] = useState(
            new GeoJsonLayer({ .... }),
            new GeoJsonLayer({ .... }),
            ..
            ..
)

When the user adds a new layer, we do the following:

set_list_of_layers([...list_of_layers, new GeoJsonLayer({
                id: "custom_0_xxx",
                data: get_file_values,
                visible: true
                ..
                ..
            })
        ])

At this point, extensions: [new DataFilterExtension({filterSize: N})] is not initialized in the layer as we do not know the filterSize.

On the browser-side, the user will have input options to filter layer points by defining boundaries on the additional information. One example of additional information is year-of-event, the user can choose a boundary min-max value, e.g. [2012, 2017] and the layer should filter out relevant data points using DataFilterExtension, showing only data-points that have occured within 2012-2017.

To edit the previous layer, we copy the props, destroy the previous layer and create a new layer as such (this is adapted loosely from our current code):

const prevProps = layer.props;
set_list_of_layers(list_of_layers.filter(layer => !layer.id === target_id));
set_list_of_layers([...list_of_layers,
            new GeoJsonLayer({
                ...prevProps,
                getFilterValue: d => d.properties["info1"],
                filterRange: [min, max],
                extensions: [new DataFilterExtension({filterSize: 1})]            
            })
        ])

Theoretically, this should create a new layer that shows only data-points within the filter range. However, all the data-points are non-visible.

image

A snippet of the layer props from console shows that the props are passed as expected, but is not visible. The filtering works if the initial layer is passed the extensions: new DataFilterExtension props, but this seems to be a workaround.

I was hoping to better understand how I can improve the implementation of editing the DataFilterExtension dynamically in my layers.

Cheers

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:5

github_iconTop GitHub Comments

1reaction
KhorZLcommented, Jun 9, 2020

Gotcha! This workaround works for me. On another note, is there a way to filter string values? For example, if my dataset has a list of countries and I would like to filter these countries based on the country’s name.

0reactions
KhorZLcommented, Jun 14, 2020

Closing this issue as I found a workaround the problem, which is to apply getFillColor conditionally. Thanks for all your help!

Read more comments on GitHub >

github_iconTop Results From Across the Web

MapImageLayer - create dynamic map layers | Sample Code
This sample demonstrates how to create dynamic map layers in a MapImageLayer. A dynamic map layer allows you to alter properties of a...
Read more >
DataFilterExtension - deck.gl
The DataFilterExtension adds GPU-based data filtering functionalities to layers. It allows the layer to show/hide objects based on user-defined properties. This ...
Read more >
Updating Geojson layers dynamically in a deck.gl map
I can't update the layers I create in the deck dynamically. I initialized the map after creating initial layers (a feature collection ...
Read more >
How To: Add dynamic layer from a existing layer to the map ...
There might be a need to add dynamic layer from an existing layer (a.k.a cloned layer) into the map object using ArcIMS Java...
Read more >
Dynamic user Marker Layers in Maps - Salesforce Help
Once the layer builder is open, for All Accounts, add a Field Filter and select Owner ID (Lookup). Under the second field drop-down...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found