Skip to content

Commit 20f2a38

Browse files
authored
Merge pull request #5458 from mind84/rel_id_child_placement
[Refactoring] Rely on relation id for children popup positioning
2 parents 7a306e1 + 26001d2 commit 20f2a38

File tree

1 file changed

+14
-31
lines changed

1 file changed

+14
-31
lines changed

assets/src/legacy/map.js

+14-31
Original file line numberDiff line numberDiff line change
@@ -1090,7 +1090,8 @@ window.lizMap = function() {
10901090

10911091
// prepare utilities object
10921092
let rUtilities = {
1093-
rLayerId : rLayerId // pivot id or table id
1093+
rLayerId : rLayerId, // pivot id or table id
1094+
relationId: relation.relationId, // relationId
10941095
};
10951096
const pivotAttributeLayerConf = lizMap.getLayerConfigById( rLayerId, lizMap.config.attributeLayers, 'layerId' );
10961097
// check if child is a pivot table
@@ -1144,7 +1145,8 @@ window.lizMap = function() {
11441145
if ( rGetLayerConfig ) {
11451146
preProcessRequest = {
11461147
oneToN:true,
1147-
layer:rGetLayerConfig[1]
1148+
layer:rGetLayerConfig[1],
1149+
relationId:relation.relationId,
11481150
}
11491151
let ut = {
11501152
referencingField: relation.referencingField,
@@ -1332,7 +1334,10 @@ window.lizMap = function() {
13321334

13331335
parentDiv.append(childPopup);
13341336

1335-
childPopupElements.push(childPopup);
1337+
childPopupElements.push({
1338+
childPopupElement:childPopup,
1339+
relationId:utilities.relationId,
1340+
});
13361341

13371342
// Trigger event for single popup children
13381343
lizMap.events.triggerEvent(
@@ -1366,33 +1371,11 @@ window.lizMap = function() {
13661371

13671372
// place children in the right div, if any
13681373
let relations = parentDiv.children('.container.popup_lizmap_dd').find(".popup_lizmap_dd_relation");
1369-
relations.each((ind,relation) => {
1370-
let referencingLayerId = $(relation).attr('data-referencing-layer-id');
1371-
if (referencingLayerId) {
1372-
let relLayerId = null;
1373-
let referencingLayerConfig = lizMap.getLayerConfigById( referencingLayerId, lizMap.config.attributeLayers, 'layerId' );
1374-
if (referencingLayerConfig && referencingLayerConfig[1]?.pivot == 'True' && config.relations.pivot && config.relations.pivot[referencingLayerId]) {
1375-
// relation is a pivot, search for "m" child layers
1376-
let mLayer = Object.keys(config.relations.pivot[referencingLayerId]).filter((k)=>{ return k !== layerId})
1377-
if (mLayer.length == 1) {
1378-
relLayerId = mLayer[0];
1379-
}
1380-
} else {
1381-
// relation is 1:n, search for n layer
1382-
relLayerId = referencingLayerId;
1383-
}
1384-
1385-
if (relLayerId) {
1386-
let childLayer = childPopupElements.filter((child)=>{
1387-
let lName = child.attr("data-layername");
1388-
let lId = lName ? lizMap.config.layers?.[lName]?.id : '';
1389-
return relLayerId == lId;
1390-
})
1391-
1392-
if(childLayer.length == 1) {
1393-
$(relation).append(childLayer[0])
1394-
}
1395-
}
1374+
relations.each((ind, relation) => {
1375+
let relationId = relation.dataset.relationId;
1376+
let elementToMove = childPopupElements.filter(c => c.relationId == relationId);
1377+
if (elementToMove.length == 1) {
1378+
$(relation).append(elementToMove[0].childPopupElement);
13961379
}
13971380
});
13981381

@@ -1401,7 +1384,7 @@ window.lizMap = function() {
14011384
"lizmappopupallchildrendisplayed",
14021385
{
14031386
parentPopupElement: self.parents('.lizmapPopupSingleFeature'),
1404-
childPopupElements: childPopupElements
1387+
childPopupElements: childPopupElements.map(c => c.childPopupElement)
14051388
}
14061389
);
14071390
});

0 commit comments

Comments
 (0)