Skip to content

Commit

Permalink
feature: new multiselectionstyle for features in active layer (#1846)
Browse files Browse the repository at this point in the history
* New multiselectionstyle, inActiveLayer

New multiselectionstyle, inActiveLayer

* Update infowindow.js

* Update infowindow.js

* Merge from master

* Skip state property

* Fix for listlayout

* Update infowindow_expandableList.js

* Update selectionmanager.js

* Update selectionmanager.js
  • Loading branch information
jokd authored Oct 31, 2023
1 parent 65fdb72 commit e06b796
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 26 deletions.
2 changes: 1 addition & 1 deletion src/featurelayer.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export default function featurelayer(features, map) {
const featureLayer = new VectorLayer({
source: featureLayerStore,
map,
zIndex: 1
zIndex: 9
});
return {
addFeature: function addFeature(feature) {
Expand Down
41 changes: 24 additions & 17 deletions src/infowindow.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@ function showInfowindow() {
mainContainer.classList.remove('hidden');
}

function getActiveSelectionGroup() {
return activeSelectionGroup;
}

function makeElementDraggable(elm) {
const elmnt = elm;
let pos1 = 0;
Expand Down Expand Up @@ -155,6 +159,22 @@ function render(viewerId) {
makeElementDraggable(mainContainer);
}

function highlightListElement(featureId) {
sublists.forEach((sublist) => {
const elements = sublist.getElementsByClassName('listelement');
for (let index = 0; index < elements.length; index += 1) {
const element = elements[index];
if (element.id === featureId) {
setTimeout(() => {
element.classList.add('highlighted');
}, 100);
} else {
element.classList.remove('highlighted');
}
}
});
}

function showSelectedList(selectionGroup) {
if (activeSelectionGroup === selectionGroup) {
return;
Expand All @@ -179,14 +199,16 @@ function showSelectedList(selectionGroup) {
}
const subexportToAppend = subexports.get(selectionGroup);
exportContainer.appendChild(subexportToAppend);

selectionManager.clearHighlightedFeatures();
selectionManager.refreshAllLayers();
urvalElements.forEach((value, key) => {
if (key === selectionGroup) {
value.classList.add('selectedurvalelement');
} else {
value.classList.remove('selectedurvalelement');
}
});
highlightListElement();
}

/**
Expand Down Expand Up @@ -216,22 +238,6 @@ function createUrvalElement(selectionGroup, selectionGroupTitle) {
subexports.set(selectionGroup, subexportComponent);
}

function highlightListElement(featureId) {
sublists.forEach((sublist) => {
const elements = sublist.getElementsByClassName('listelement');
for (let index = 0; index < elements.length; index += 1) {
const element = elements[index];
if (element.id === featureId) {
setTimeout(() => {
element.classList.add('highlighted');
}, 100);
} else {
element.classList.remove('highlighted');
}
}
});
}

function createExpandableContent(listElementContentContainer, content, elementId) {
const items = content.querySelectorAll('ul > li');
const foldedItems = [];
Expand Down Expand Up @@ -424,6 +430,7 @@ function init(options) {
render(options.viewer.getId());

return {
getActiveSelectionGroup,
createListElement,
removeListElement,
expandListElement,
Expand Down
8 changes: 7 additions & 1 deletion src/infowindow_expandableList.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,10 @@ function showInfowindow() {
mainContainer.classList.remove('hidden');
}

function getActiveSelectionGroup() {
return activeSelectionGroup;
}

function makeElementDraggable(elm) {
const elmnt = elm;
let pos1 = 0;
Expand Down Expand Up @@ -166,12 +170,13 @@ function render(viewerId) {
makeElementDraggable(mainContainer);
}

// This function actually does nothing but is kept for the selectionmanager, hopefully the infowindow_expandableList.js will soon be merged with infowindow.js
function showSelectedList(selectionGroup) {
if (activeSelectionGroup === selectionGroup) {
return;
}

activeSelectionGroup = selectionGroup;
activeSelectionGroup = null;
}

function createUrvalElement(selectionGroup, selectionGroupTitle) {
Expand Down Expand Up @@ -426,6 +431,7 @@ function init(options) {
render(options.viewer.getId());

return {
getActiveSelectionGroup,
createListElement,
removeListElement,
expandListElement,
Expand Down
28 changes: 21 additions & 7 deletions src/selectionmanager.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,13 @@ const Selectionmanager = function Selectionmanager(options = {}) {
});
}

/**
* Clears highlighted features
*/
function clearHighlightedFeatures() {
highlightedFeatures = [];
}

/**
* Highlights the feature with fid id.
* All other items are un-highlighted
Expand Down Expand Up @@ -159,19 +166,24 @@ const Selectionmanager = function Selectionmanager(options = {}) {
}

/**
* Callback function that styles a feature when it is drawn.
* @param {any} feature
* Returns a style function to be used when a feature is drawn.
* @param {any} selectionGroup
*/
function featureStyler(feature) {
if (highlightedFeatures.includes(feature)) {
return Style.createStyleRule(multiselectStyleOptions.highlighted);
function getFeatureStyler(selectionGroup) {
function featureStyler(feature) {
if (highlightedFeatures.includes(feature)) {
return Style.createStyleRule(multiselectStyleOptions.highlighted);
} else if (selectionGroup === infowindow.getActiveSelectionGroup()) {
return Style.createStyleRule(multiselectStyleOptions.inActiveLayer ? multiselectStyleOptions.inActiveLayer : multiselectStyleOptions.selected);
}
return Style.createStyleRule(multiselectStyleOptions.selected);
}
return Style.createStyleRule(multiselectStyleOptions.selected);
return featureStyler;
}

function createSelectionGroup(selectionGroup, selectionGroupTitle) {
const urvalLayer = featurelayer(null, map);
urvalLayer.setStyle(featureStyler);
urvalLayer.setStyle(getFeatureStyler(selectionGroup));
urval.set(selectionGroup, urvalLayer);
infowindow.createUrvalElement(selectionGroup, selectionGroupTitle);
}
Expand Down Expand Up @@ -350,13 +362,15 @@ const Selectionmanager = function Selectionmanager(options = {}) {
addOrHighlightItem,
removeItemById,
clearSelection,
clearHighlightedFeatures,
createSelectionGroup,
highlightFeature,
highlightFeatureById,
getNumberOfSelectedItems,
getSelectedItems,
getSelectedItemsForASelectionGroup,
getUrval,
refreshAllLayers,
onInit() {
selectedItems = new Collection([], { unique: true });
urval = new Map();
Expand Down

0 comments on commit e06b796

Please sign in to comment.