mapbox / mapbox-unity-sdk

Mapbox Unity SDK - https://www.mapbox.com/unity/
Other
723 stars 212 forks source link

Feature Collection and querying #492

Open brnkhy opened 6 years ago

brnkhy commented 6 years ago

Another feature we're missing at the moment is the ability to query for existing map features. i.e. searching for buildings in an area, road segments close to a point, list of all pois in range etc. While most of this is actually belongs to app logic (distance checks, area checks etc), we need to have a collection to let devs runs these operations.

My suggestion here is rather close to my suggestion in that factory ticket (https://github.com/mapbox/mapbox-unity-sdk/issues/491), create collection assets (scriptable objects) to keep the objects which then we can feed into other module.

cache pinkish lines represents adding to collection, blue and green lines represents possible usage through reference to the collection module.

So we'll have isolated stand alone collection assets and they'll live in the background as scriptable objects. If we want to add something to collection, we can do it through a modifier (add to collection modifier in that shot) or maybe even add this functionality to the modifier stacks and just make it a checkbox or something. And whenever you need something from the collection, all you'll need is a reference that collection.

Good thing about this is that it isn't introducing any new dependencies. If there's a collection assigned, it'll add to that. If not, it'll not and work just as usual. So in example, we can add this to all our existing examples (and devs to their projects) easily without breaking anything at all.

Another thing I like about this is that collection logic is all isolated from the rest of the stuff. This means we can have a basic implementation using a List at first, then maybe create another using a Dictionary and when we feel hardcore enough we can implement a kdtree/quadtree one for maximum search performance.

MiroMuse commented 6 years ago

@brnkhy has created a sample script and @atripathi-mb needs to put this into an api. Then will use this for implementation of selecting a mesh and swapping out.

brnkhy commented 6 years ago

I pushed the implementation here; https://github.com/mapbox/mapbox-unity-sdk/tree/featureCollections

It adds feature collections and a kd tree based collection. Basic Vector example have a new modifier to add buildings to collection. I haven't pushed a test case actually, but you can see building count in the collection when you select collection scriptable object.

As I said there's only one implementation (kdtree) at the moment and I suggest using a concrete usage (for base class) for now. It's kinda hard to interface them because all collections will probably have different kind of querying.

cc @atripathi-mb