Add query annotation timeout (#3874)

This commit is contained in:
Adrian Cojocaru
2025-10-13 23:57:13 +03:00
committed by GitHub
parent 8f50a54927
commit 00ad11eb04
4 changed files with 22 additions and 8 deletions

View File

@@ -188,14 +188,26 @@ std::vector<Feature> AndroidRendererFrontend::queryRenderedFeatures(const Screen
return mapRenderer.actor().ask(fn, point, options).get();
}
AnnotationIDs AndroidRendererFrontend::queryPointAnnotations(const ScreenBox& box) const {
AnnotationIDs AndroidRendererFrontend::queryPointAnnotations(const ScreenBox& box,
const std::chrono::milliseconds& timeout) const {
// Waits for the result from the orchestration thread and returns
return mapRenderer.actor().ask(&Renderer::queryPointAnnotations, box).get();
auto future = mapRenderer.actor().ask(&Renderer::queryPointAnnotations, box);
if (future.wait_for(timeout) != std::future_status::ready) {
return {};
}
return future.get();
}
AnnotationIDs AndroidRendererFrontend::queryShapeAnnotations(const ScreenBox& box) const {
AnnotationIDs AndroidRendererFrontend::queryShapeAnnotations(const ScreenBox& box,
const std::chrono::milliseconds& timeout) const {
// Waits for the result from the orchestration thread and returns
return mapRenderer.actor().ask(&Renderer::queryShapeAnnotations, box).get();
auto future = mapRenderer.actor().ask(&Renderer::queryShapeAnnotations, box);
if (future.wait_for(timeout) != std::future_status::ready) {
return {};
}
return future.get();
}
FeatureExtensionValue AndroidRendererFrontend::queryFeatureExtensions(

View File

@@ -52,8 +52,8 @@ public:
std::vector<Feature> queryRenderedFeatures(const ScreenCoordinate&, const RenderedQueryOptions&) const;
std::vector<Feature> queryRenderedFeatures(const ScreenBox&, const RenderedQueryOptions&) const;
std::vector<Feature> querySourceFeatures(const std::string& sourceID, const SourceQueryOptions&) const;
AnnotationIDs queryPointAnnotations(const ScreenBox& box) const;
AnnotationIDs queryShapeAnnotations(const ScreenBox& box) const;
AnnotationIDs queryPointAnnotations(const ScreenBox& box, const std::chrono::milliseconds& timeout) const;
AnnotationIDs queryShapeAnnotations(const ScreenBox& box, const std::chrono::milliseconds& timeout) const;
// Feature extension query
FeatureExtensionValue queryFeatureExtensions(const std::string& sourceID,

View File

@@ -944,7 +944,7 @@ jni::Local<jni::Array<jlong>> NativeMapView::queryPointAnnotations(JNIEnv& env,
};
// Assume only points for now
mbgl::AnnotationIDs ids = rendererFrontend->queryPointAnnotations(box);
mbgl::AnnotationIDs ids = rendererFrontend->queryPointAnnotations(box, annotationRequestTimeout);
// Convert result
std::vector<jlong> longIds(ids.begin(), ids.end());
@@ -964,7 +964,7 @@ jni::Local<jni::Array<jlong>> NativeMapView::queryShapeAnnotations(JNIEnv& env,
{RectF::getRight(env, rect), RectF::getBottom(env, rect)},
};
mbgl::AnnotationIDs ids = rendererFrontend->queryShapeAnnotations(box);
mbgl::AnnotationIDs ids = rendererFrontend->queryShapeAnnotations(box, annotationRequestTimeout);
// Convert result
std::vector<jlong> longIds(ids.begin(), ids.end());

View File

@@ -362,6 +362,8 @@ private:
int width = 64;
int height = 64;
static constexpr auto annotationRequestTimeout = std::chrono::milliseconds(200);
// Ensure these are initialised last
std::unique_ptr<mbgl::Map> map;
};