Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add multiselect flag for geometry layers (fill, line) #582

Merged
merged 1 commit into from
Jan 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions djinni/map/layers/tiled/vector/tiled_vector_layer.djinni
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ vector_layer_feature_info = record {

tiled_2d_map_vector_layer_selection_callback_interface = interface +c +j +o {
did_select_feature(feature_info: vector_layer_feature_info, layer_identifier: string, coord: coord): bool;
did_multi_select_layer_features(feature_infos: list<vector_layer_feature_info>, layer_identifier: string, coord: coord): bool;
did_click_background_confirmed(coord: coord) : bool;
}

Expand Down
2 changes: 1 addition & 1 deletion shared/public/BackgroundVectorLayerDescription.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ class BackgroundVectorLayerDescription: public VectorLayerDescription {
BackgroundVectorStyle style,
std::optional<int32_t> renderPassIndex,
std::shared_ptr<Value> interactable):
VectorLayerDescription(identifier, "", "", 0, 0, nullptr, renderPassIndex, interactable),
VectorLayerDescription(identifier, "", "", 0, 0, nullptr, renderPassIndex, interactable, false),
style(style) {};

std::unique_ptr<VectorLayerDescription> clone() override {
Expand Down
7 changes: 4 additions & 3 deletions shared/public/LineVectorLayerDescription.h
Original file line number Diff line number Diff line change
Expand Up @@ -133,14 +133,15 @@ class LineVectorLayerDescription: public VectorLayerDescription {
std::shared_ptr<Value> filter,
LineVectorStyle style,
std::optional<int32_t> renderPassIndex,
std::shared_ptr<Value> interactable):
VectorLayerDescription(identifier, source, sourceId, minZoom, maxZoom, filter, renderPassIndex, interactable),
std::shared_ptr<Value> interactable,
bool multiselect):
VectorLayerDescription(identifier, source, sourceId, minZoom, maxZoom, filter, renderPassIndex, interactable, multiselect),
style(style) {};

std::unique_ptr<VectorLayerDescription> clone() override {
return std::make_unique<LineVectorLayerDescription>(identifier, source, sourceLayer, minZoom, maxZoom,
filter ? filter->clone() : nullptr, style, renderPassIndex,
interactable ? interactable->clone() : nullptr);
interactable ? interactable->clone() : nullptr, multiselect);
}

virtual UsedKeysCollection getUsedKeys() const override {
Expand Down
7 changes: 4 additions & 3 deletions shared/public/PolygonVectorLayerDescription.h
Original file line number Diff line number Diff line change
Expand Up @@ -98,14 +98,15 @@ class PolygonVectorLayerDescription: public VectorLayerDescription {
std::shared_ptr<Value> filter,
PolygonVectorStyle style,
std::optional<int32_t> renderPassIndex,
std::shared_ptr<Value> interactable):
VectorLayerDescription(identifier, source, sourceId, minZoom, maxZoom, filter, renderPassIndex, interactable),
std::shared_ptr<Value> interactable,
bool multiselect):
VectorLayerDescription(identifier, source, sourceId, minZoom, maxZoom, filter, renderPassIndex, interactable, multiselect),
style(style) {};

std::unique_ptr<VectorLayerDescription> clone() override {
return std::make_unique<PolygonVectorLayerDescription>(identifier, source, sourceLayer, minZoom, maxZoom,
filter ? filter->clone() : nullptr, style, renderPassIndex,
interactable ? interactable->clone() : nullptr);
interactable ? interactable->clone() : nullptr, multiselect);
}

virtual UsedKeysCollection getUsedKeys() const override {
Expand Down
2 changes: 1 addition & 1 deletion shared/public/RasterVectorLayerDescription.h
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ class RasterVectorLayerDescription: public VectorLayerDescription {
bool underzoom,
bool overzoom,
std::optional<::RectCoord> bounds):
VectorLayerDescription(identifier, source, "", minZoom, maxZoom, nullptr, renderPassIndex, interactable),
VectorLayerDescription(identifier, source, "", minZoom, maxZoom, nullptr, renderPassIndex, interactable, false),
style(style), url(url), underzoom(underzoom), overzoom(overzoom), adaptScaleToScreen(adaptScaleToScreen), numDrawPreviousLayers(numDrawPreviousLayers),
maskTiles(maskTiles), zoomLevelScaleFactor(zoomLevelScaleFactor), bounds(bounds) {};

Expand Down
2 changes: 1 addition & 1 deletion shared/public/SymbolVectorLayerDescription.h
Original file line number Diff line number Diff line change
Expand Up @@ -510,7 +510,7 @@ class SymbolVectorLayerDescription: public VectorLayerDescription {
SymbolVectorStyle style,
std::optional<int32_t> renderPassIndex,
std::shared_ptr<Value> interactable):
VectorLayerDescription(identifier, source, sourceId, minZoom, maxZoom, filter, renderPassIndex, interactable),
VectorLayerDescription(identifier, source, sourceId, minZoom, maxZoom, filter, renderPassIndex, interactable, false),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The constructor of SymbolVectorLayerDescription initializes VectorLayerDescription with a hardcoded false for the multiselect parameter. This contradicts the PR objectives of adding multiselect functionality.

- VectorLayerDescription(identifier, source, sourceId, minZoom, maxZoom, filter, renderPassIndex, interactable, false),
+ VectorLayerDescription(identifier, source, sourceId, minZoom, maxZoom, filter, renderPassIndex, interactable, true),

Consider making multiselect a parameter of SymbolVectorLayerDescription's constructor to allow dynamic control over this feature.


Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
VectorLayerDescription(identifier, source, sourceId, minZoom, maxZoom, filter, renderPassIndex, interactable, false),
VectorLayerDescription(identifier, source, sourceId, minZoom, maxZoom, filter, renderPassIndex, interactable, true),

style(style) {};

std::unique_ptr<VectorLayerDescription> clone() override {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

#include "Coord.h"
#include <string>
#include <vector>

struct VectorLayerFeatureInfo;

Expand All @@ -14,5 +15,7 @@ class Tiled2dMapVectorLayerSelectionCallbackInterface {

virtual bool didSelectFeature(const VectorLayerFeatureInfo & featureInfo, const std::string & layerIdentifier, const ::Coord & coord) = 0;

virtual bool didMultiSelectLayerFeatures(const std::vector<VectorLayerFeatureInfo> & featureInfos, const std::string & layerIdentifier, const ::Coord & coord) = 0;

virtual bool didClickBackgroundConfirmed(const ::Coord & coord) = 0;
};
1 change: 1 addition & 0 deletions shared/public/Tiled2dMapVectorTile.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ class Tiled2dMapVectorTile : public ActorObject,
double dpFactor = 1.0;

std::weak_ptr<Tiled2dMapVectorLayerSelectionCallbackInterface> selectionDelegate;
bool multiselect = false;

const std::shared_ptr<Tiled2dMapVectorStateManager> featureStateManager;
};
7 changes: 5 additions & 2 deletions shared/public/VectorLayerDescription.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ class VectorLayerDescription {
int maxZoom;
std::shared_ptr<Value> filter;
std::optional<int32_t> renderPassIndex;
bool multiselect;

virtual VectorLayerType getType() = 0;

Expand Down Expand Up @@ -58,15 +59,17 @@ class VectorLayerDescription {
int maxZoom,
std::shared_ptr<Value> filter,
std::optional<int32_t> renderPassIndex,
std::shared_ptr<Value> interactable):
std::shared_ptr<Value> interactable,
bool multiselect):
identifier(identifier),
source(source),
sourceLayer(sourceId),
minZoom(minZoom),
maxZoom(maxZoom),
filter(filter),
renderPassIndex(renderPassIndex),
interactable(interactable) {}
interactable(interactable),
multiselect(multiselect) {}

virtual ~VectorLayerDescription() = default;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,7 @@ Tiled2dMapVectorLayerParserResult Tiled2dMapVectorLayerParserHelper::parseStyleJ

std::optional<int32_t> renderPassIndex;
std::shared_ptr<Value> interactable = globalIsInteractable;
bool layerMultiselect = false;

std::shared_ptr<Value> blendMode;
if (val["metadata"].is_object()) {
Expand All @@ -232,6 +233,9 @@ Tiled2dMapVectorLayerParserResult Tiled2dMapVectorLayerParserHelper::parseStyleJ
if (!val["metadata"]["interactable"].is_null()) {
interactable = parser.parseValue(val["metadata"]["interactable"]);
}
if (!val["metadata"]["multiselect"].is_null()) {
layerMultiselect = val["metadata"].value("multiselect", false);
}
if (!val["metadata"]["blend-mode"].is_null()) {
blendMode = parser.parseValue(val["metadata"]["blend-mode"]);
}
Expand Down Expand Up @@ -301,7 +305,8 @@ Tiled2dMapVectorLayerParserResult Tiled2dMapVectorLayerParserHelper::parseStyleJ
filter,
style,
renderPassIndex,
interactable);
interactable,
layerMultiselect);

layers.push_back(layerDesc);

Expand Down Expand Up @@ -360,7 +365,7 @@ Tiled2dMapVectorLayerParserResult Tiled2dMapVectorLayerParserHelper::parseStyleJ
filter,
style,
renderPassIndex,
interactable);
interactable); // in-layer layerMultiselect not yet supported
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The comment indicates that in-layer layerMultiselect support is not yet implemented for SymbolVectorLayerDescription. This is a missed opportunity to fully integrate multiselect functionality across all layer types. Consider extending the multiselect support to symbol vector layers as well.

-                                                                            interactable); // in-layer layerMultiselect not yet supported
+                                                                            interactable, layerMultiselect);

Ensure that the SymbolVectorLayerDescription constructor and class definition are updated accordingly to support this parameter.


Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
interactable); // in-layer layerMultiselect not yet supported
interactable, layerMultiselect);

layers.push_back(layerDesc);
} else if (val["type"] == "fill") {

Expand All @@ -379,7 +384,8 @@ Tiled2dMapVectorLayerParserResult Tiled2dMapVectorLayerParserHelper::parseStyleJ
filter,
style,
renderPassIndex,
interactable);
interactable,
layerMultiselect);

layers.push_back(layerDesc);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ Tiled2dMapVectorTile::Tiled2dMapVectorTile(const std::weak_ptr<MapInterface> &ma
if (auto strongMapInterface = mapInterface.lock()) {
dpFactor = strongMapInterface->getCamera()->getScreenDensityPpi() / 160.0;
}

multiselect = description->multiselect;
}

void Tiled2dMapVectorTile::updateVectorLayerDescription(const std::shared_ptr<VectorLayerDescription> &description,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -409,17 +409,23 @@ bool Tiled2dMapVectorLineTile::onClickConfirmed(const Vec2F &posScreen) {

auto lineDescription = std::static_pointer_cast<LineVectorLayerDescription>(description);

std::vector<VectorLayerFeatureInfo> featureInfos;
for (auto const &[lineCoordinateVector, featureContext]: hitDetection) {
for (auto const &coordinates: lineCoordinateVector) {
auto lineWidth = lineDescription->style.getLineWidth(EvaluationContext(zoomIdentifier, dpFactor, featureContext, featureStateManager));
if (LineHelper::pointWithin(coordinates, point, lineWidth, coordinateConverter)) {
if (strongSelectionDelegate->didSelectFeature(featureContext->getFeatureInfo(), description->identifier, point)) {
if (multiselect) {
featureInfos.push_back(featureContext->getFeatureInfo());
} else if (strongSelectionDelegate->didSelectFeature(featureContext->getFeatureInfo(), description->identifier, point)) {
return true;
}
}
}
}

if (multiselect && !featureInfos.empty()) {
return strongSelectionDelegate->didMultiSelectLayerFeatures(featureInfos, description->identifier, point);
}

return false;
}
Loading
Loading