Skip to content

Commit

Permalink
#557 Viewer Panel Pdfs - support with draw layers
Browse files Browse the repository at this point in the history
  • Loading branch information
tariqksoliman committed Jun 18, 2024
1 parent f295027 commit cae65a6
Show file tree
Hide file tree
Showing 6 changed files with 108 additions and 108 deletions.
92 changes: 92 additions & 0 deletions src/essence/Basics/Layers_/Layers_.js
Original file line number Diff line number Diff line change
Expand Up @@ -3267,6 +3267,98 @@ const L_ = {
}
return features
},
propertiesToImages(props, baseUrl) {
baseUrl = baseUrl || ''
var images = []
//Use "images" key first
if (props.hasOwnProperty('images')) {
for (var i = 0; i < props.images.length; i++) {
if (props.images[i].url) {
var url = baseUrl + props.images[i].url
if (!F_.isUrlAbsolute(url)) url = L_.missionPath + url
if (props.images[i].isModel) {
images.push({
url: url,
texture: props.images[i].texture,
name:
(props.images[i].name ||
props.images[i].url.match(
/([^\/]*)\/*$/
)[1]) + ' [Model]',
type: 'model',
isPanoramic: false,
isModel: true,
values: props.images[i].values || {},
master: props.images[i].master,
})
} else {
if (props.images[i].isPanoramic) {
images.push({
...props.images[i],
url: url,
name:
(props.images[i].name ||
props.images[i].url.match(
/([^\/]*)\/*$/
)[1]) + ' [Panoramic]',
type: 'photosphere',
isPanoramic: true,
isModel: false,
values: props.images[i].values || {},
master: props.images[i].master,
})
}
images.push({
url: url,
name:
props.images[i].name ||
props.images[i].url.match(/([^\/]*)\/*$/)[1],
type: props.images[i].type || 'image',
isPanoramic: false,
isModel: false,
values: props.images[i].values || {},
master: props.images[i].master,
})
}
}
}
}
//If there isn't one, search all string valued props for image urls
else {
for (var p in props) {
if (
typeof props[p] === 'string' &&
props[p].toLowerCase().match(/\.(jpeg|jpg|gif|png|xml)$/) !=
null
) {
var url = props[p]
if (!F_.isUrlAbsolute(url)) url = L_.missionPath + url
images.push({
url: url,
name: p,
isPanoramic: false,
isModel: false,
})
}
if (
typeof props[p] === 'string' &&
(props[p].toLowerCase().match(/\.(obj)$/) != null ||
props[p].toLowerCase().match(/\.(dae)$/) != null)
) {
var url = props[p]
if (!F_.isUrlAbsolute(url)) url = L_.missionPath + url
images.push({
url: url,
name: p,
isPanoramic: false,
isModel: true,
})
}
}
}

return images
},
}

//Takes in a configData object and does a depth-first search through its
Expand Down
108 changes: 2 additions & 106 deletions src/essence/Basics/Map_/Map_.js
Original file line number Diff line number Diff line change
Expand Up @@ -698,19 +698,13 @@ function featureDefaultClick(feature, layer, e) {
}

function keepGoing() {
//View images
var propImages = propertiesToImages(
feature.properties,
layer.options.metadata ? layer.options.metadata.base_url || '' : ''
)

Kinds.use(
L_.layers.data[layer.options.layerName].kind,
Map_,
feature,
layer,
layer.options.layerName,
propImages,
null,
e
)

Expand All @@ -724,13 +718,7 @@ function featureDefaultClick(feature, layer, e) {
}
}

Viewer_.changeImages(propImages, feature, layer)
for (var i in propImages) {
if (propImages[i].type == 'radargram') {
//Globe_.radargram( layer.options.layerName, feature.geometry, propImages[i].url, propImages[i].length, propImages[i].depth );
break
}
}
Viewer_.changeImages(feature, layer)

//figure out how to construct searchStr in URL. For example: a ChemCam target can sometime
//be searched by "target sol", or it can be searched by "sol target" depending on config file.
Expand Down Expand Up @@ -1191,98 +1179,6 @@ function allLayersLoaded() {
}
}

function propertiesToImages(props, baseUrl) {
baseUrl = baseUrl || ''
var images = []
//Use "images" key first
if (props.hasOwnProperty('images')) {
for (var i = 0; i < props.images.length; i++) {
if (props.images[i].url) {
var url = baseUrl + props.images[i].url
if (!F_.isUrlAbsolute(url)) url = L_.missionPath + url
if (props.images[i].isModel) {
images.push({
url: url,
texture: props.images[i].texture,
name:
(props.images[i].name ||
props.images[i].url.match(/([^\/]*)\/*$/)[1]) +
' [Model]',
type: 'model',
isPanoramic: false,
isModel: true,
values: props.images[i].values || {},
master: props.images[i].master,
})
} else {
if (props.images[i].isPanoramic) {
images.push({
...props.images[i],
url: url,
name:
(props.images[i].name ||
props.images[i].url.match(
/([^\/]*)\/*$/
)[1]) + ' [Panoramic]',
type: 'photosphere',
isPanoramic: true,
isModel: false,
values: props.images[i].values || {},
master: props.images[i].master,
})
}
images.push({
url: url,
name:
props.images[i].name ||
props.images[i].url.match(/([^\/]*)\/*$/)[1],
type: props.images[i].type || 'image',
isPanoramic: false,
isModel: false,
values: props.images[i].values || {},
master: props.images[i].master,
})
}
}
}
}
//If there isn't one, search all string valued props for image urls
else {
for (var p in props) {
if (
typeof props[p] === 'string' &&
props[p].toLowerCase().match(/\.(jpeg|jpg|gif|png|xml)$/) !=
null
) {
var url = props[p]
if (!F_.isUrlAbsolute(url)) url = L_.missionPath + url
images.push({
url: url,
name: p,
isPanoramic: false,
isModel: false,
})
}
if (
typeof props[p] === 'string' &&
(props[p].toLowerCase().match(/\.(obj)$/) != null ||
props[p].toLowerCase().match(/\.(dae)$/) != null)
) {
var url = props[p]
if (!F_.isUrlAbsolute(url)) url = L_.missionPath + url
images.push({
url: url,
name: p,
isPanoramic: false,
isModel: true,
})
}
}
}

return images
}

function buildToolBar() {
d3.select('#mapToolBar').html('')

Expand Down
2 changes: 1 addition & 1 deletion src/essence/Basics/Viewer_/PDFViewer.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ const ReactPDF = (props) => {
style={{
position: 'fixed',
top: '40px',
left: '46px',
left: bcr ? `${bcr.left + 6}px` : '46px',
display: 'flex',
height: '30px',
justifyContent: 'center',
Expand Down
7 changes: 6 additions & 1 deletion src/essence/Basics/Viewer_/Viewer_.js
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,12 @@ var Viewer_ = {
},
//images is [ { 'url': '', 'name': '', 'isPanoramic': false },{...}, ... ]
//Shows the first image too
changeImages: function (images, feature, layer) {
changeImages: function (feature, layer) {
let images = L_.propertiesToImages(
feature.properties,
layer.options.metadata ? layer.options.metadata.base_url || '' : ''
)

// Don't refresh if the same exact point is clicked,
// that's just annoying. So skip over it.
if (
Expand Down
1 change: 1 addition & 0 deletions src/essence/Tools/Draw/DrawTool.js
Original file line number Diff line number Diff line change
Expand Up @@ -741,6 +741,7 @@ var DrawTool = {
d
)

Viewer_.changeImages(layer.feature, layer)
Globe_.highlight(
Globe_.findSpriteObject(
layer.options.layerName,
Expand Down
6 changes: 6 additions & 0 deletions src/essence/Tools/Draw/DrawTool_Editing.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import L_ from '../../Basics/Layers_/Layers_'
import LayerGeologic from '../../Basics/Layers_/LayerGeologic/LayerGeologic'
import Globe_ from '../../Basics/Globe_/Globe_'
import Map_ from '../../Basics/Map_/Map_'
import Viewer_ from '../../Basics/Viewer_/Viewer_'
import UserInterface_ from '../../Basics/UserInterface_/UserInterface_'
import CursorInfo from '../../Ancillary/CursorInfo'
import turf from 'turf'
Expand Down Expand Up @@ -2770,6 +2771,11 @@ var Editing = {
}
return newProperties
}

Viewer_.changeImages(
DrawTool.contextMenuLayer.feature,
DrawTool.contextMenuLayer
)
},
getSnapGuides: function (layer) {
var guides = []
Expand Down

0 comments on commit cae65a6

Please sign in to comment.