mobile-sdk icon indicating copy to clipboard operation
mobile-sdk copied to clipboard

[FR] fast VectorElements getBounds

Open farfromrefug opened this issue 4 years ago • 2 comments

While working with clusters there is one feature you usually need: the MapBounds of a clustered item. Right now there is no easy way to compute the bounds from VectorElements (which you get from the buildClusterElement method). So you need to do something like this:

PointGeometryVector vector = new PointGeometryVector();
for (int i = 0; i<nbElements; i++) {
    vector.add((PointGeometry)elements.get(i).getGeometry());
}
MapBounds mapBounds = new MultiPointGeometry(vector).getBounds();
VariantArrayBuilder builder = new VariantArrayBuilder();
builder.addDouble(mapBounds.getMin().getX());
builder.addDouble(mapBounds.getMin().getY());
builder.addDouble(mapBounds.getMax().getX());
builder.addDouble(mapBounds.getMax().getY());
marker.setMetaDataElement("bbox", builder.buildVariant());

Would be really nice to have a one liner to compute MapBounds from a VectorElements (what i wrote is potentially slow on Android due to JNI).

farfromrefug avatar Oct 08 '21 10:10 farfromrefug

@farfromrefug There are two buildClusterElement variants in ClusterElementBuilder (the one without explicit VectorElementVector should be much faster, just for info). Perhaps it would make sense to add additional MapBounds argument to both methods.

Adding specific methods to *Vector classes is not that simple due to technical reasons, such classes are generated from C++ templates.

Tagging this with 'idea-maybe-future', it makes sense to me.

mtehver avatar Oct 09 '21 10:10 mtehver

@mtehver very interesting point about the 2 variants of the method! I completely missed that. I will allow both and compute the bbox only on the second one. I understand their might be technical issues (felt there was a reason you did not add it ;) ). So i would say that yes it would be a great addition to add additional MapBounds arg to both method. Without it it is impossible to know how to zoom on a cluster. EDIT: it seems we cant change the builderMode. I only see getBuilderMode not setBuilderMode. Am i missing something?

farfromrefug avatar Oct 09 '21 10:10 farfromrefug