Skip to content

Commit 56f504e

Browse files
authored
Merge pull request #505 from open-pv/feature/azimuth
Add azimuth to slope display
2 parents c84a75c + 0ba6915 commit 56f504e

File tree

5 files changed

+25
-6
lines changed

5 files changed

+25
-6
lines changed

public/locales/de/translation.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,5 +158,6 @@
158158
"companies": "Installateure in Ihrer Nähe",
159159
"bbe": "Kein eigenes Dach? Tritt doch einer Bürgerenergiegenossenschaft bei!"
160160
},
161-
"slope": "Neigung"
161+
"slope": "Neigung",
162+
"azimuth": "Azimuth"
162163
}

public/locales/en/translation.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,5 +137,6 @@
137137
"companies": "Installers near you",
138138
"bbe": "No own roof? Join a community energy cooperative!"
139139
},
140-
"slope": "Slope"
140+
"slope": "Slope",
141+
"azimuth": "Azimuth"
141142
}

src/components/ThreeViewer/Controls/CustomMapControl.jsx

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,11 @@ function CustomMapControl() {
8080
event.preventDefault()
8181
const intersects = getIntersects()
8282
const intersectedFace = ignoreSprites(intersects).face
83-
const slope = calculateSlopeFromNormal(intersectedFace.normal)
83+
const [slope, azimuth] = calculateSlopeAzimuthFromNormal(
84+
intersectedFace.normal,
85+
)
8486
sceneContext.setSlope(Math.round(slope))
87+
sceneContext.setAzimuth(Math.round(azimuth))
8588
}
8689

8790
useEffect(() => {
@@ -125,8 +128,17 @@ function CustomMapControl() {
125128

126129
export default CustomMapControl
127130

128-
const calculateSlopeFromNormal = (normal) => {
131+
const calculateSlopeAzimuthFromNormal = (normal) => {
129132
const up = new THREE.Vector3(0, 0, 1)
130133
const angleRad = normal.angleTo(up)
131-
return THREE.MathUtils.radToDeg(angleRad)
134+
const slope = THREE.MathUtils.radToDeg(angleRad)
135+
136+
// Swap y and x in atan to get clockwise angle from y-axis
137+
const azimuthRad = Math.atan2(normal.x, normal.y)
138+
let azimuth = THREE.MathUtils.radToDeg(azimuthRad)
139+
if (azimuth < 0) {
140+
azimuth += 360
141+
}
142+
143+
return [slope, azimuth]
132144
}

src/components/ThreeViewer/Overlay.jsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,9 @@ function Overlay({ frontendState, setFrontendState, geoLocation }) {
273273
const MouseHoverInfo = () => {
274274
return (
275275
<div className='attribution' id='footer-on-hover'>
276-
{t('slope') + ': ' + sceneContext.slope}°
276+
{t('slope')}: {sceneContext.slope}°
277+
<br />
278+
{t('azimuth')}: {sceneContext.azimuth}°
277279
</div>
278280
)
279281
}

src/components/ThreeViewer/Scene.jsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ const Scene = ({
3535
// highlighted PVSystems for deletion or calculation
3636
const [selectedPVSystem, setSelectedPVSystem] = useState([])
3737
const [slope, setSlope] = useState('')
38+
const [azimuth, setAzimuth] = useState('')
3839

3940
window.setPVPoints = setPVPoints
4041
const position = [
@@ -61,6 +62,8 @@ const Scene = ({
6162
setShowTerrain,
6263
slope,
6364
setSlope,
65+
azimuth,
66+
setAzimuth,
6467
}}
6568
>
6669
<Overlay

0 commit comments

Comments
 (0)