Skip to content

Commit

Permalink
#372 Reselect feature on updateVectorLayer and appendLineString
Browse files Browse the repository at this point in the history
  • Loading branch information
tariqksoliman committed Jun 1, 2023
1 parent 68d9a02 commit 9161bc4
Show file tree
Hide file tree
Showing 3 changed files with 110 additions and 59 deletions.
14 changes: 12 additions & 2 deletions src/essence/Basics/Layers_/LayerConstructors.js
Original file line number Diff line number Diff line change
Expand Up @@ -805,9 +805,9 @@ const pairings = (geojson, layerObj, leafletLayerObject) => {
return
}

const getPairingLayer = (dontCalculate) => {
const getPairingLayer = (dontCalculate, forceGeojson) => {
const pairingLineFeatures = []

if (forceGeojson) geojson = forceGeojson
if (!dontCalculate)
geojson.features.forEach((f) => {
const featureCenter = centroid(f).geometry.coordinates
Expand Down Expand Up @@ -897,6 +897,16 @@ const pairings = (geojson, layerObj, leafletLayerObject) => {

const layer = getPairingLayer(true)

layer.addDataEnhanced = function (geojson, layerName, subName, Map_) {
Map_.rmNotNull(L_.layers.attachments[layerName][subName].layer)
L_.layers.attachments[layerName][subName].geojson = geojson
L_.layers.attachments[layerName][subName].layer = getPairingLayer(
false,
geojson
)
Map_.map.addLayer(L_.layers.attachments[layerName][subName].layer)
}

return {
on: L_.layers.attachments[layerObj.name]?.pairings
? L_.layers.attachments[layerObj.name]?.pairings.on
Expand Down
152 changes: 96 additions & 56 deletions src/essence/Basics/Layers_/Layers_.js
Original file line number Diff line number Diff line change
Expand Up @@ -212,10 +212,18 @@ const L_ = {
L_._onLayerToggleSubscriptions[k](s.name, !on)
})
},
toggleLayerHelper: async function (s, on, ignoreToggleStateChange) {
toggleLayerHelper: async function (
s,
on,
ignoreToggleStateChange,
globeOnly
) {
if (s.type !== 'header') {
if (on) {
if (L_.Map_.map.hasLayer(L_.layers.layer[s.name])) {
if (
L_.Map_.map.hasLayer(L_.layers.layer[s.name]) &&
globeOnly != true
) {
try {
$('.drawToolContextMenuHeaderClose').click()
} catch (err) {}
Expand Down Expand Up @@ -261,7 +269,7 @@ const L_ = {
L_.Globe_.litho.toggleLayer(s.name, false)
} else L_.Globe_.litho.removeLayer(s.name)
} else {
if (L_.layers.layer[s.name]) {
if (L_.layers.layer[s.name] && globeOnly != true) {
if (L_.layers.attachments[s.name]) {
for (let sub in L_.layers.attachments[s.name]) {
if (L_.layers.attachments[s.name][sub].on) {
Expand Down Expand Up @@ -302,13 +310,18 @@ const L_ = {
break
case 'labels':
case 'pairings':
L_.layers.attachments[s.name][
sub
].layer.on(
false,
if (
L_.layers.attachments[s.name][sub]
.layer
)
L_.layers.attachments[s.name][
sub
].layer.on(
false,
L_.layers.attachments[s.name][
sub
].layer
)
break
default:
L_.Map_.map.addLayer(
Expand Down Expand Up @@ -396,37 +409,43 @@ const L_ = {
}
} else {
let hadToMake = false
if (L_.layers.layer[s.name] === false) {
if (
L_.layers.layer[s.name] === false &&
globeOnly != true
) {
await L_.Map_.makeLayer(s, true)
Description.updateInfo()
hadToMake = true
}
if (L_.layers.layer[s.name]) {
if (!hadToMake) {
// Refresh annotation popups
if (L_.layers.layer[s.name]._layers)
Object.keys(
L_.layers.layer[s.name]._layers
).forEach((key) => {
const l =
L_.layers.layer[s.name]._layers[key]
if (l._isAnnotation) {
L_.layers.layer[s.name]._layers[key] =
L_.createAnnotation(
if (globeOnly != true) {
if (!hadToMake) {
// Refresh annotation popups
if (L_.layers.layer[s.name]._layers)
Object.keys(
L_.layers.layer[s.name]._layers
).forEach((key) => {
const l =
L_.layers.layer[s.name]._layers[key]
if (l._isAnnotation) {
L_.layers.layer[s.name]._layers[
key
] = L_.createAnnotation(
l._annotationParams.feature,
l._annotationParams.className,
l._annotationParams.layerId,
l._annotationParams.id1
)
}
})
}
})
}
L_.Map_.map.addLayer(L_.layers.layer[s.name])
L_.layers.layer[s.name].setZIndex(
L_._layersOrdered.length +
1 -
L_._layersOrdered.indexOf(s.name)
)
}
L_.Map_.map.addLayer(L_.layers.layer[s.name])
L_.layers.layer[s.name].setZIndex(
L_._layersOrdered.length +
1 -
L_._layersOrdered.indexOf(s.name)
)
if (s.type === 'vector') {
L_.Globe_.litho.addLayer(
s.layer3dType || 'clamped',
Expand Down Expand Up @@ -478,23 +497,25 @@ const L_ = {
}
}

if (!ignoreToggleStateChange) {
if (on) L_.layers.on[s.name] = false
if (!on) L_.layers.on[s.name] = true
}
if (globeOnly != true) {
if (!ignoreToggleStateChange) {
if (on) L_.layers.on[s.name] = false
if (!on) L_.layers.on[s.name] = true
}

if (s.type === 'vector') L_._updatePairings(s.name, !on)
if (s.type === 'vector') L_._updatePairings(s.name, !on)

if (!on && s.type === 'vector') {
L_.Map_.orderedBringToFront()
}
L_._refreshAnnotationEvents()
if (!on && s.type === 'vector') {
L_.Map_.orderedBringToFront()
}
L_._refreshAnnotationEvents()

// Toggling rereveals hidden features, so make sure they stay hidden
if (L_.toggledOffFeatures && L_.toggledOffFeatures.length > 0) {
L_.toggledOffFeatures.forEach((f) => {
L_.toggleFeature(f, false)
})
// Toggling rereveals hidden features, so make sure they stay hidden
if (L_.toggledOffFeatures && L_.toggledOffFeatures.length > 0) {
L_.toggledOffFeatures.forEach((f) => {
L_.toggleFeature(f, false)
})
}
}
},
_refreshAnnotationEvents() {
Expand Down Expand Up @@ -656,10 +677,11 @@ const L_ = {
break
case 'labels':
case 'pairings':
sublayer.layer.on(
false,
sublayer.layer
)
if (sublayer.layer)
sublayer.layer.on(
false,
sublayer.layer
)
break
default:
map.addLayer(sublayer.layer)
Expand Down Expand Up @@ -829,8 +851,7 @@ const L_ = {
// Remove layer
L_.Map_.rmNotNull(L_.layers.layer[layer._layerName])
// Remove sublayers
L_.syncSublayerData(layer._layerName, true)

await L_.syncSublayerData(layer._layerName, true)
// Remake Layer
await L_.Map_.makeLayer(
L_.layers.data[layer._layerName],
Expand All @@ -839,10 +860,20 @@ const L_ = {
)

if (initialOn) {
L_.toggleLayerHelper(L_.layers.data[layer._layerName], false)
await L_.toggleLayerHelper(L_.layers.data[layer._layerName], false)
L_.layers.on[layer._layerName] = true
}
L_.syncSublayerData(layer._layerName)
await L_.syncSublayerData(layer._layerName)

if (initialOn) {
// Reselect activeFeature
if (L_.activeFeature) {
L_.selectFeature(
L_.activeFeature.layerName,
L_.activeFeature.feature
)
}
}
},
clearGeoJSONData: function (layer) {
if (layer._sourceGeoJSON) layer._sourceGeoJSON = F_.getBaseGeoJSON()
Expand Down Expand Up @@ -2480,7 +2511,7 @@ const L_ = {
}
},
// Make a layer's sublayer match the layers data again
syncSublayerData: function (layerName, onlyClear) {
syncSublayerData: async function (layerName, onlyClear) {
layerName = L_.asLayerUUID(layerName)

try {
Expand All @@ -2500,23 +2531,32 @@ const L_ = {
subUpdateLayers[sub].layer != null
) {
subUpdateLayers[sub].layer.clearLayers()
if (subUpdateLayers[sub].layer._layers)
Object.keys(
subUpdateLayers[sub].layer._layers
).forEach((l) => {
L_.Map_.rmNotNull(
subUpdateLayers[sub].layer._layers[l]
)
})

if (!onlyClear) {
if (
typeof subUpdateLayers[sub].layer
.addDataEnhanced === 'function'
)
) {
subUpdateLayers[sub].layer.addDataEnhanced(
geojson,
layerName,
sub,
L_.Map_
)
else if (
} else if (
typeof subUpdateLayers[sub].layer.addData ===
'function'
)
) {
subUpdateLayers[sub].layer.addData(geojson)
}
}
}
}
Expand All @@ -2528,7 +2568,7 @@ const L_ = {
)
}

L_.globeLithoLayerHelper(L_.layers.data[layerName], onlyClear)
await L_.globeLithoLayerHelper(L_.layers.data[layerName], onlyClear)
},
clearVectorLayerInfo: function () {
// Clear the InfoTools data
Expand All @@ -2548,10 +2588,10 @@ const L_ = {
// because if the layer is toggled off, it is not on the globe
if (L_.layers.on[s.name]) {
// turn off
await L_.toggleLayerHelper(s, true, true)
await L_.toggleLayerHelper(s, true, true, true)
// Toggle the layer so its drawn in the globe
// turn on
if (!onlyClear) L_.toggleLayerHelper(s, false, true)
if (!onlyClear) await L_.toggleLayerHelper(s, false, true, true)
}
}
},
Expand Down
3 changes: 2 additions & 1 deletion src/essence/Basics/Map_/Map_.js
Original file line number Diff line number Diff line change
Expand Up @@ -360,12 +360,13 @@ let Map_ = {
L_.layers.attachments[
L_._layersOrdered[hasIndex[i]]
][s].type !== 'model'
)
) {
Map_.map.addLayer(
L_.layers.attachments[
L_._layersOrdered[hasIndex[i]]
][s].layer
)
}
}
}
}
Expand Down

0 comments on commit 9161bc4

Please sign in to comment.