Coder Social home page Coder Social logo

Comments (3)

kylebarron avatar kylebarron commented on June 16, 2024

The idea here is to let the user draw a box on the screen and select items from their visualization. The items may either be highlighted on the JS side in the map or, also, the row indexes can be sent back from JS to Python so that the user can call gdf.iloc[layer.selected_indexes].

The predominant question is: how do you draw a bounding box in deck.gl?

Option 1: "Manual" approach

Deck has a pickObjects method on the map class to find the objects that intersect with the box. I believe the input box should be in screen space, as it's described to be pixels. This means that what we need to do is enable a selection tool and access the pixel range of the map canvas from that selection. I don't know how to do this myself, and maybe nebula.gl would help with this, or maybe it's better to read up on how e.g. leaflet-draw works.

Option 2: Nebula.gl

nebula.gl is a library that works with deck.gl to enable editing of geospatial data. In theory, this should solve the problem for us using its SelectionLayer, but the library seems to be no longer maintained.


Once we have the data from pickObjects, we can take those row indexes and update them on the widget state to send the data back to Python.

from lonboard.

hanbyul-here avatar hanbyul-here commented on June 16, 2024

Some related findings discussions we had today.

For 'Drawing-bbox' UI part

Existing options - Nebula.gl

As mentioned, Nebula.gl seems to be not maintained anymore.

Use react-map-gl-draw

I was hoping we could use react-map-gl-draw plugin with ReactMapGL's useControl hook. However, the current way of using Mapbox (Inside of as a child of ) seems to confuse the plugin. I could not draw anything with the control added on. I can't pinpoint why, maybe DeckGL layer is interfering the interaction between mapbox-gl-draw and mapbox gl? or mapbox-gl-draw cannot reach Mapbox?

We discussed using the DeckGL layer as a MapboxOverlay, which will give a better integration with other Mapbox controls. Considering this will change how all the layers will work internally, it seems not worth the risk.

For passing the data to layer part

pickObjects method belongs to DeckGL instance. (So the layer doesn't have access to these objects.) To expose the selected indices in a coherent way (attaching selected objects to the layer level), We would need to associate selected indices to each layer. Since selected objects have the layer that they belong to, we can use that info and attach it to the layers? Maybe using Submodelstates which have the layers?:

lonboard/src/index.tsx

Lines 68 to 73 in 96611f5

let [subModelState, setSubModelState] = useState<
Record<string, BaseLayerModel>
>({});
let model = useModel();
let [childLayerIds] = useModelState<string[]>("layers");

from lonboard.

batpad avatar batpad commented on June 16, 2024

@kylebarron and I started hacking on this a bit when we met last week, many thanks to @isaacbrodsky for the initial PR that was a great starting point.

This is the PR where I've been working: #417

Here's a screen recording of what the interaction looks like currently:

BboxScreengrab.mp4

The bit to get working is passing the selected indexes back to Python, but that should be reasonably straightforward. And the code needs a bunch of cleanups.

It would also be nice to get some design help :)

Seeing how complex this could get in the future (do we support drawing arbitrary polygons, etc) - @kylebarron, am wondering how this code should be structured -- I'll leave further comments on the PR.

from lonboard.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.