Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
A
Asc Geostac
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
aflab
astrogeology
Asc Geostac
Commits
66e1535f
Commit
66e1535f
authored
1 year ago
by
Zack
Browse files
Options
Downloads
Patches
Plain Diff
refactored code to increase readability
parent
d76c5dd8
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/js/AstroMap.js
+43
-40
43 additions, 40 deletions
src/js/AstroMap.js
with
43 additions
and
40 deletions
src/js/AstroMap.js
+
43
−
40
View file @
66e1535f
...
@@ -2,9 +2,6 @@ import L from "leaflet";
...
@@ -2,9 +2,6 @@ import L from "leaflet";
import
"
proj4leaflet
"
;
import
"
proj4leaflet
"
;
import
AstroProj
from
"
./AstroProj
"
;
import
AstroProj
from
"
./AstroProj
"
;
import
LayerCollection
from
"
./LayerCollection
"
;
import
LayerCollection
from
"
./LayerCollection
"
;
import
FecthData
from
"
./FetchData
"
;
import
{
data
}
from
"
autoprefixer
"
;
/**
/**
* @class AstroMap
* @class AstroMap
...
@@ -269,21 +266,7 @@ export default L.Map.AstroMap = L.Map.extend({
...
@@ -269,21 +266,7 @@ export default L.Map.AstroMap = L.Map.extend({
*/
*/
refreshFeatures
:
function
(
visibleCollectionId
,
collectionsObj
)
{
refreshFeatures
:
function
(
visibleCollectionId
,
collectionsObj
)
{
// Will we need more than 6 colors for more than 6 different collections?
this
.
removePreviousLayers
(
this
.
_geoLayers
,
L
);
let
colors
=
[
"
#17A398
"
,
"
#EE6C4D
"
,
"
#662C91
"
,
"
#F3DE2C
"
,
"
#33312E
"
,
"
#0267C1
"
];
let
lightcolors
=
[
"
#3DE3D5
"
,
"
#F49C86
"
,
"
#9958CC
"
,
"
#F7E96F
"
,
"
#DDDDDD
"
,
"
#2A9BFD
"
];
// Old, removes separate control
// if(this._footprintControl) {
// this._footprintControl.remove();
// }
// removes layers previously loaded
for
(
let
i
=
0
;
i
<
this
.
_geoLayers
.
length
;
i
++
){
if
(
this
.
_geoLayers
[
i
])
{
L
.
LayerCollection
.
layerControl
.
removeLayer
(
this
.
_geoLayers
[
i
]);
this
.
_geoLayers
[
i
].
clearLayers
();
}
}
// initialize featureCollection as an array
// initialize featureCollection as an array
// (convert obj passed from FootprintResults.jsx)
// (convert obj passed from FootprintResults.jsx)
...
@@ -300,40 +283,31 @@ export default L.Map.AstroMap = L.Map.extend({
...
@@ -300,40 +283,31 @@ export default L.Map.AstroMap = L.Map.extend({
// For each Collection (and each geoLayer)
// For each Collection (and each geoLayer)
for
(
let
i
=
0
;
i
<
featureCollections
.
length
;
i
++
)
{
for
(
let
i
=
0
;
i
<
featureCollections
.
length
;
i
++
)
{
let
title
=
featureCollections
[
i
].
title
;
let
curr_collection
=
featureCollections
[
i
];
let
title
=
curr_collection
.
title
;
let
sld_text
=
featureCollections
[
i
].
styleSheets
;
let
sld_text
=
curr_collection
.
styleSheets
;
// set style if available
let
features_in_curr_collection
=
curr_collection
.
features
.
length
;
let
sld_style
=
null
;
let
wrappedFeatures
=
null
;
let
myStyle
=
null
;
// Add each _geoLayer that has footprints to the FootprintCollection object.
// Add each _geoLayer that has footprints to the FootprintCollection object.
// The collection title is used as the property name
// The collection title is used as the property name
// [old] and it shows up as the layer title when added to the separate Leaflet control
// [old] and it shows up as the layer title when added to the separate Leaflet control
if
(
feature
Collections
[
i
].
features
.
length
>
0
)
{
if
(
feature
s_in_curr_collection
>
0
)
{
if
(
sld_text
!=
null
)
{
sld_style
=
this
.
setStyle
(
sld_text
,
this
.
SLDStyler
,
i
);
this
.
SLDStyler
=
new
L
.
SLDStyler
(
sld_text
);
wrappedFeatures
=
this
.
cloneWestEast
(
curr_collection
.
features
);
myStyle
=
this
.
SLDStyler
.
getStyleFunction
();
}
else
{
// Set colors if available
myStyle
=
i
<
colors
.
length
?
{
fillColor
:
colors
[
i
],
color
:
lightcolors
[
i
]}
:
{};
}
// Wrap features
let
wrappedFeatures
=
this
.
cloneWestEast
(
featureCollections
[
i
].
features
);
this
.
_geoLayers
[
i
]
=
L
.
geoJSON
(
wrappedFeatures
,
{
this
.
_geoLayers
[
i
]
=
L
.
geoJSON
(
wrappedFeatures
,
{
id
:
featureC
ollection
s
[
i
]
.
id
,
id
:
curr_c
ollection
.
id
,
style
:
myS
tyle
style
:
sld_s
tyle
})
})
this
.
_geoLayers
[
i
].
on
({
click
:
this
.
handleClick
});
// Add click listener
this
.
_geoLayers
[
i
].
on
({
click
:
this
.
handleClick
});
// Add click listener
// Add layers to map if they should be visible
// Add layers to map if they should be visible
if
(
featureC
ollection
s
[
i
]
.
id
===
visibleCollectionId
)
{
if
(
curr_c
ollection
.
id
===
visibleCollectionId
)
{
this
.
_geoLayers
[
i
].
addTo
(
this
);
this
.
_geoLayers
[
i
].
addTo
(
this
);
this
.
SLDStyler
.
symbolize_with_icons
(
this
.
_geoLayers
[
i
],
this
);
this
.
SLDStyler
.
symbolize_with_icons
(
this
.
_geoLayers
[
i
],
this
);
}
}
...
@@ -347,6 +321,8 @@ export default L.Map.AstroMap = L.Map.extend({
...
@@ -347,6 +321,8 @@ export default L.Map.AstroMap = L.Map.extend({
}
}
}
}
// Add collections to a separate control
// Add collections to a separate control
// this._footprintControl = L.control // 1. Make a leaflet control
// this._footprintControl = L.control // 1. Make a leaflet control
// .layers(null, this._footprintCollection, {collapsed: true}) // 2. Add the footprint collections to the control as layers
// .layers(null, this._footprintCollection, {collapsed: true}) // 2. Add the footprint collections to the control as layers
...
@@ -355,6 +331,33 @@ export default L.Map.AstroMap = L.Map.extend({
...
@@ -355,6 +331,33 @@ export default L.Map.AstroMap = L.Map.extend({
}
}
},
},
setStyle
:
function
(
sld_style
,
SLDStyler
,
index
){
let
colors
=
[
"
#17A398
"
,
"
#EE6C4D
"
,
"
#662C91
"
,
"
#F3DE2C
"
,
"
#33312E
"
,
"
#0267C1
"
];
let
lightcolors
=
[
"
#3DE3D5
"
,
"
#F49C86
"
,
"
#9958CC
"
,
"
#F7E96F
"
,
"
#DDDDDD
"
,
"
#2A9BFD
"
];
let
defaultStyle
=
null
;
if
(
sld_style
!=
null
)
{
SLDStyler
=
new
L
.
SLDStyler
(
sld_style
);
return
SLDStyler
.
getStyleFunction
();
}
defaultStyle
=
index
<
colors
.
length
?
{
fillColor
:
colors
[
index
],
color
:
lightcolors
[
index
]}
:
{};;
return
defaultStyle
;
},
// removes layers previously loaded
removePreviousLayers
:
function
(
geoLayers
,
L
)
{
// removes layers previously loaded
let
collection_amount
=
geoLayers
.
length
;
for
(
let
i
=
0
;
i
<
collection_amount
;
i
++
){
if
(
geoLayers
[
i
])
{
L
.
LayerCollection
.
layerControl
.
removeLayer
(
geoLayers
[
i
]);
geoLayers
[
i
].
clearLayers
();
}
}
},
/**
/**
* @function AstroMap.prototype.parseJSON
* @function AstroMap.prototype.parseJSON
* @description Parses the USGS JSON, creates layer objects for a particular target and projection,
* @description Parses the USGS JSON, creates layer objects for a particular target and projection,
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment