uber / nebula.gl

A suite of 3D-enabled data editing overlays, suitable for deck.gl
https://nebula.gl/
Other
695 stars 165 forks source link

Is there a way to toggle visibility on subLayers? #541

Open bishoym opened 3 years ago

bishoym commented 3 years ago

The DeckGL docs recommend using the visibility prop where frequent toggling of data is necessary.

If I'm using the EditableGeoJSONLayer, and passing it a FeatureCollection, is there a way to access this visible prop on a specific feature within the features array (by index)?

The visible prop at the top level toggles the entire Layer - and therefore all the features simultaneously. That's not quite the desired behaviour. Any help is much appreciated!

@supersonicclay

supersonicclay commented 3 years ago

You can provide deck.gl layers callbacks for changing how things are rendered. If you pass _subLayerProps to EditableGeoJsonLayer. And in those props, you can pass something like this:

const [myFeatures, setMyFeatures] = React.useState(...);

const layer = EditableGeoJsonLayer({
_subLayerProps: {
  geojson: {
    getLineColor: (feature) => {
      if (myFeatures.features.indexOf(feature) === INDEX_YOU_WANT_TO_HIDE) {
        return TRANSPARENT_COLOR;
      } else {
       return NORMAL_COLOR;
     }
   }
 });

Forgive any typos. That pseudocode is from memory. You can look at the API docs for deck.gl's GeoJsonLayer for the available props that control rendering (it may be getLineColor or maybe something else).

@ibgreen may also have a better solution than that.

bishoym commented 3 years ago

@supersonicclay yup, I've gotten quite familiar with the API surface of this particular class over the last couple of months 😅 and I've implemented your suggestion.

Good news is: It technically works. Bad news is: it's hacky and requires a refactor of vertex styling in order to avoid having a set of floating vertices in EditMode. image

Also, more crucially, it doesn't stop me from picking the layer which is unfortunately where I have to determine the solution as insufficient.

Like I said, I need access to the visible prop and that unfortunately doesn't support a callback.

I know we can extend the EditableGeoJSONLayer class, can you provide guidance as to how I might go about overriding the top-level visible prop from boolean to a callback which iterates over the underlying features?

MoxiCult commented 2 years ago

bishoym - did you find a solution? I am having a similar issue.