From b86a1abe40d2d70a72cf5e6275f5daaed56fdbbf Mon Sep 17 00:00:00 2001 From: Stepan Kuzmin <533564+stepankuzmin@users.noreply.github.com> Date: Tue, 12 Nov 2024 13:02:06 +0200 Subject: [PATCH] [GLJS-1062] Improve `queryRenderedFeatures` support in the Interactions API (internal-1945) --- .../style/style_layer/model_style_layer.ts | 19 +- debug/featuresets.html | 160 +++----- src/data/feature_index.ts | 4 +- src/source/query_features.ts | 6 +- src/source/tile.ts | 4 +- src/style-spec/reference/v8.json | 2 +- src/style/query_geometry.ts | 6 +- src/style/style.ts | 273 ++++++++----- src/ui/events.ts | 12 +- src/ui/interactions.ts | 136 ++++--- src/ui/map.ts | 208 +++++----- src/util/vectortile_to_geojson.ts | 6 +- test/release/index.js | 5 + test/release/local_release_page_list.txt | 1 + test/unit/style/style.test.ts | 22 +- test/unit/style/style_imports.test.ts | 6 +- test/unit/ui/interaction_set.test.ts | 131 ++++++ test/unit/ui/interactions.test.ts | 378 +++++++++++++----- test/util/vitest.ts | 2 +- vitest.config.base.ts | 2 +- 20 files changed, 892 insertions(+), 491 deletions(-) create mode 100644 test/unit/ui/interaction_set.test.ts diff --git a/3d-style/style/style_layer/model_style_layer.ts b/3d-style/style/style_layer/model_style_layer.ts index d1ff845e690..7c2f02cefd5 100644 --- a/3d-style/style/style_layer/model_style_layer.ts +++ b/3d-style/style/style_layer/model_style_layer.ts @@ -10,6 +10,7 @@ import EXTENT from '../../../src/style-spec/data/extent'; import {convertModelMatrixForGlobe, queryGeometryIntersectsProjectedAabb} from '../../util/model_util'; import Tiled3dModelBucket from '../../data/bucket/tiled_3d_model_bucket'; import EvaluationParameters from '../../../src/style/evaluation_parameters'; +import Feature from '../../../src/util/vectortile_to_geojson'; import type {vec3} from 'gl-matrix'; import type {Transitionable, Transitioning, PossiblyEvaluated, PropertyValue, ConfigOptions} from '../../../src/style/properties'; @@ -24,7 +25,6 @@ import type ModelManager from '../../render/model_manager'; import type {Node} from '../../data/model'; import type {VectorTileFeature} from '@mapbox/vector-tile'; import type {FeatureFilter} from '../../../src/style-spec/feature_filter/index'; -import type Feature from '../../../src/util/vectortile_to_geojson'; import type {CanonicalTileID} from '../../../src/source/tile_id'; import type {LUT} from "../../../src/util/lut"; @@ -239,14 +239,15 @@ class ModelStyleLayer extends StyleLayer { const position = new LngLat(0, 0); tileToLngLat(tile.tileID.canonical, position, nodeInfo.node.anchor[0], nodeInfo.node.anchor[1]); - queryFeature = { - type: 'Feature', - geometry: {type: "Point", coordinates: [position.lng, position.lat]}, - properties: nodeInfo.feature.properties, - id: nodeInfo.feature.id, - state: {}, // append later - layer: this.serialize() - }; + + const {z, x, y} = tile.tileID.canonical; + queryFeature = new Feature({} as unknown as VectorTileFeature, z, x, y, nodeInfo.feature.id); + queryFeature.properties = nodeInfo.feature.properties; + queryFeature.geometry = {type: 'Point', coordinates: [position.lng, position.lat]}; + queryFeature.layer = {...this.serialize(), id: this.fqid}; + queryFeature.state = {}; + queryFeature.tile = tile.tileID.canonical; + return {queryFeature, intersectionZ}; } } diff --git a/debug/featuresets.html b/debug/featuresets.html index 6407ef1b990..0d1f823b609 100644 --- a/debug/featuresets.html +++ b/debug/featuresets.html @@ -3,7 +3,7 @@ Mapbox GL JS debug page - +