Skip to content

Commit

Permalink
#303 Use originOFfset
Browse files Browse the repository at this point in the history
  • Loading branch information
tariqksoliman committed Jan 23, 2023
1 parent addd3ac commit 2897f20
Show file tree
Hide file tree
Showing 4 changed files with 85 additions and 12 deletions.
27 changes: 26 additions & 1 deletion src/essence/Basics/Formulae_/Formulae_.js
Original file line number Diff line number Diff line change
Expand Up @@ -2236,12 +2236,37 @@ var Formulae_ = {
return false
},
azElDistBetween(latLngEl_A, latLngEl_B) {
return azElDistBetween(
//Formulae_.azElBetween2(latLngEl_A, latLngEl_B)

const b = azElDistBetween(
latLngEl_A,
latLngEl_B,
Formulae_.radiusOfPlanetMajor,
Formulae_.radiusOfPlanetMinor
)
return b
},
azElBetween2(latLngEl_A, latLngEl_B) {
const crs = window.mmgisglobal.customCRS
const a = crs.project(latLngEl_A)
const b = crs.project(latLngEl_B)

const dist = Math.sqrt(
Math.pow(b.x - a.x, 2) +
Math.pow(b.y - a.y, 2) +
Math.pow(latLngEl_B.el - latLngEl_A.el, 2)
)

const el =
Math.asin((latLngEl_B.el - latLngEl_A.el) / dist) * (180 / Math.PI)

let az = Math.atan2(b.x - a.x, b.y - a.y) * (180 / Math.PI)
if (az < 0) az += 360
console.log({
az: az,
el: el,
dist: dist,
})
},
// Breaks an array in multiple arrays of some size
chunkArray(arr, size) {
Expand Down
2 changes: 2 additions & 0 deletions src/essence/Basics/Formulae_/subformulae/azElDistBetween.js
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,8 @@ export default function azElDistBetween(
majorRadius,
minorRadius
) {
majorRadius = 3396190 + 1000
minorRadius = majorRadius
const result = { az: 0, el: 0, dist: 0 }
const a = parseLocation(latLngEl_A)
if (a != null) {
Expand Down
1 change: 1 addition & 0 deletions src/essence/Basics/Layers_/LayerConstructors.js
Original file line number Diff line number Diff line change
Expand Up @@ -904,6 +904,7 @@ const pairings = (geojson, layerObj, leafletLayerObject) => {
: true,
pairedLayers: layers,
pairProp: pairProp,
originOffsetOrder: pairingsVar.originOffsetOrder,
type: 'pairings',
geojson: geojson,
layer: layer,
Expand Down
67 changes: 56 additions & 11 deletions src/essence/Basics/Viewer_/Photosphere.js
Original file line number Diff line number Diff line change
Expand Up @@ -203,13 +203,57 @@ export default function (domEl, lookupPath, options, Map_) {
L_.layersGroupSublayers[layerName].pairings &&
L_.layersGroupSublayers[layerName].pairings.on
) {
const sourceCoords = feature.geometry.coordinates
if (imageObj.srclng != null)
sourceCoords[0] = parseFloat(imageObj.srclng)
if (imageObj.srclat != null)
sourceCoords[1] = parseFloat(imageObj.srclat)
if (imageObj.srcelv != null)
sourceCoords[2] = parseFloat(imageObj.srcelv)
let sourceCoords = feature.geometry.coordinates
let originOffsetOrder =
L_.layersGroupSublayers[layerName].pairings
.originOffsetOrder
if (originOffsetOrder)
originOffsetOrder = originOffsetOrder.map((o) =>
o.toLowerCase()
)

console.log(imageObj.originOffset, originOffsetOrder)
// Allow sourceCoords offset with originOffset and support configurable axis order
// prettier-ignore
if( imageObj.originOffset != null ) {
const crs = window.mmgisglobal.customCRS
const scp = crs.project({lng: sourceCoords[0], lat: sourceCoords[1]})
sourceCoords = [scp.x, scp.y, sourceCoords[2]]
if(imageObj.originOffset[0] != null) {
if( originOffsetOrder != null && originOffsetOrder[0] != null) {
const pos = originOffsetOrder[0].includes('z') ? 2 : originOffsetOrder[0].includes('y') ? 1 : 0
const sign = originOffsetOrder[0].includes('-') ? -1 : 1
console.log(pos, sign)
sourceCoords[pos] += sign * imageObj.originOffset[0]
}
else
sourceCoords[0] += imageObj.originOffset[0]
}
if(imageObj.originOffset[1] != null) {
if( originOffsetOrder != null && originOffsetOrder[1] != null) {
const pos = originOffsetOrder[1].includes('z') ? 2 : originOffsetOrder[1].includes('y') ? 1 : 0
const sign = originOffsetOrder[1].includes('-') ? -1 : 1
sourceCoords[pos] += sign * imageObj.originOffset[1]
}
else
sourceCoords[1] += imageObj.originOffset[1]
}
if(imageObj.originOffset[2] != null) {
if( originOffsetOrder != null && originOffsetOrder[2] != null) {
const pos = originOffsetOrder[2].includes('z') ? 2 : originOffsetOrder[2].includes('y') ? 1 : 0
const sign = originOffsetOrder[2].includes('-') ? -1 : 1
sourceCoords[pos] += sign * imageObj.originOffset[2]
}
else
sourceCoords[2] += imageObj.originOffset[2]
}
const scup = crs.unproject({x: sourceCoords[0], y: sourceCoords[1]})
sourceCoords = [scup.lng, scup.lat, sourceCoords[2]]
}

console.log(sourceCoords, feature.geometry.coordinates)

currentImageObj._center = sourceCoords

const pairValue = F_.getIn(
feature.properties,
Expand Down Expand Up @@ -413,10 +457,11 @@ export default function (domEl, lookupPath, options, Map_) {
Map_.rmNotNull(Map_.tempPhotosphereWedge)

let start = [geometry.coordinates[1], geometry.coordinates[0]]
if (currentImageObj.srclat != null)
start[0] = parseFloat(currentImageObj.srclat)
if (currentImageObj.srclng != null)
start[1] = parseFloat(currentImageObj.srclng)
if (currentImageObj._center != null)
start = [
currentImageObj._center[1],
currentImageObj._center[0],
]
let end
let rp
let line
Expand Down

0 comments on commit 2897f20

Please sign in to comment.