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

Fix missing railway by development mode #1179

Merged
merged 3 commits into from
Jan 10, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
6 changes: 2 additions & 4 deletions web/siteplan/src/feature/FMAFeature.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,12 +61,10 @@ export default class FMAFeature extends LageplanFeature<FMAComponent> {

// Rescale the feature according to the current zoom level
// to keep a constant size
style
.getImage()
.setScale(scale)
style.getImage()?.setScale(scale)

// Rotate the feature
style.getImage().setRotation((fma.position.rotation * Math.PI) / 180)
style.getImage()?.setRotation((fma.position.rotation * Math.PI) / 180)

return style
})
Expand Down
3 changes: 2 additions & 1 deletion web/siteplan/src/feature/LageplanFeature.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ import { Position } from '../model/Position'
import { isPlanningObject, SiteplanColorValue, SiteplanState } from '../model/SiteplanModel'
import SvgService from '../service/SvgService'
import {
createFeature, getFeatureBoundArea,
createFeature,
getFeatureBoundArea,
getFeatureBounds,
getFeatureData,
getFeatureGUID,
Expand Down
73 changes: 62 additions & 11 deletions web/siteplan/src/feature/TrackFeature.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import { LineString } from 'ol/geom'
import Geometry from 'ol/geom/Geometry'
import Polygon from 'ol/geom/Polygon'
import { Fill, Stroke, Style } from 'ol/style'
import { createFeature, FeatureType, getFeatureData } from './FeatureInfo'
import { createFeature, FeatureType, getFeatureData, getFeatureGUID, getFeatureType } from './FeatureInfo'

/**
* Container for all track features
Expand Down Expand Up @@ -65,7 +65,8 @@ export default class TrackFeature extends LageplanFeature<Track> {
track,
trackSection,
trackSegment
), this.createTrackOutlineFeature(track.guid, trackSection, trackSegment)
)
, this.createTrackOutlineFeature(track.guid, trackSection, trackSegment)
]
}

Expand Down Expand Up @@ -292,38 +293,88 @@ export default class TrackFeature extends LageplanFeature<Track> {
])
const initialTracks = this.getObjectsModel(initial)
const finalTracks = this.getObjectsModel(final)
const isDiffSection = initialTracks.some(initialTrack => {
let exsitDiffSection = false
initialTracks.forEach(initialTrack => {
const finalTrack = finalTracks.find(x => x.guid === initialTrack.guid)
if (!finalTrack) {
return false
return
}

let isNotEqual = false
const initialSections = initialTrack.sections
const finalSections = finalTrack.sections
if (initialSections.length > finalSections.length) {
const missingSections = this.getMissingElements<TrackSection>(initialSections, finalSections, x => x.guid)
this.coloringMissingElements(initialTrack, missingSections, SiteplanColorValue.COLOR_REMOVED)
isNotEqual = true
exsitDiffSection = true
} else if (initialSections.length < finalSections.length) {
const missingSections = this.getMissingElements<TrackSection>(finalSections, initialSections, x => x.guid)
this.coloringMissingElements(finalTrack, missingSections, SiteplanColorValue.COLOR_ADDED)
isNotEqual = true
exsitDiffSection = true
}

finalTrack.sections.forEach(finalSection => {
const initialSection = initialTrack.sections.find(x => x.guid === finalSection.guid)
if (initialSection && compare(finalSection, initialSection)) {
this.setObjectColor(initialTrack, finalSection.guid, SiteplanColorValue.COLOR_REMOVED)
this.setObjectColor(finalTrack, finalSection.guid, SiteplanColorValue.COLOR_ADDED)
isNotEqual = true
exsitDiffSection = true
}
})
return isNotEqual
})

return isDiffDesignation || isDiffSection
const test = isDiffDesignation || exsitDiffSection
? this.createCompareFeatures(initial, final)
: this.getFeatures(final)
return test
}
TruongQuangSB marked this conversation as resolved.
Show resolved Hide resolved

protected createCompareFeatures (initial: SiteplanState, final: SiteplanState): Feature<Geometry>[] {
mariusheine marked this conversation as resolved.
Show resolved Hide resolved
// Grouped section feature by track
const initialFeatureGroups = this.getFeatures(initial)
.groupBy(feature => getFeatureGUID(feature))
const finalFeatureGroups = this.getFeatures(final)
.groupBy(feature => getFeatureGUID(feature))
const result: Feature<Geometry>[] = []
Object.entries(initialFeatureGroups).forEach(initialGroup => {
const trackID = initialGroup[0]
const finalFeatureGroup = Object.entries(finalFeatureGroups).find(finalGroup =>
finalGroup[0] === trackID)

if (!finalFeatureGroup) {
result.push(...initialGroup[1])
return
}

initialGroup[1].forEach(initialFeature => {
const initialSectionGuid = this.getFeatureSectionGuid(initialFeature)
const initialSegment = (getFeatureData(initialFeature) as TrackSectionFeatureData)?.segment
const finalSegmentFeatures = finalFeatureGroup[1]
.filter(finalFeature => initialSectionGuid === this.getFeatureSectionGuid(finalFeature))
const finalFeature = finalSegmentFeatures.find(finalFeature => {
const finalSegment = getFeatureData(finalFeature)?.segment
return compare(initialSegment, finalSegment)
})

if (finalFeature) {
finalSegmentFeatures.forEach(feature => {
if (!result.includes(feature)) {
result.push(feature)
}
})
}

result.push(initialFeature)
TruongQuangSB marked this conversation as resolved.
Show resolved Hide resolved
})
})

return result
}

private getFeatureSectionGuid (feature: Feature<Geometry>): string | undefined {
if (getFeatureType(feature) !== FeatureType.Track) {
return undefined
}

const data = getFeatureData(feature) as TrackSectionFeatureData
return data?.section?.guid
}
}
Loading