Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
G
Géocontrib Frontend
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Redmine
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Terraform modules
Analyze
Contributor 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
GéoContrib
Géocontrib Frontend
Commits
7cc0d30a
Commit
7cc0d30a
authored
2 years ago
by
Timothee P
Browse files
Options
Downloads
Patches
Plain Diff
comment and simplify areChangesInBasemaps function to improve readability
parent
de0b64dd
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/components/Map/SidebarLayers.vue
+23
-22
23 additions, 22 deletions
src/components/Map/SidebarLayers.vue
with
23 additions
and
22 deletions
src/components/Map/SidebarLayers.vue
+
23
−
22
View file @
7cc0d30a
...
...
@@ -151,38 +151,41 @@ export default {
// Check if there are changes in the basemaps settings. Changes are detected if:
// - one basemap has been added or deleted
// - one layer has been added or deleted to a basemap
areChangesInBasemaps
(
basemapFromServer
,
basemapFromLocalstorage
=
{})
{
areChangesInBasemaps
(
basemapFromServer
,
basemapFromLocalstorage
)
{
// prevent undefined later even if in this case the function is not called anyway
if
(
!
basemapFromLocalstorage
)
return
false
;
let
isSameBasemaps
=
false
;
let
isSameLayers
=
true
;
let
isSameTitles
=
true
;
// Compare the length and the id values of the basemaps
const
idBasemapsServer
=
basemapFromServer
.
map
((
b
)
=>
b
.
id
).
sort
();
const
idBasemapsLocalstorage
=
basemapFromLocalstorage
.
length
?
basemapFromLocalstorage
.
map
((
b
)
=>
b
.
id
).
sort
()
:
{};
const
idBasemapsLocalstorage
=
basemapFromLocalstorage
.
map
((
b
)
=>
b
.
id
).
sort
()
||
{};
isSameBasemaps
=
idBasemapsServer
.
length
===
idBasemapsLocalstorage
.
length
&&
idBasemapsServer
.
every
(
(
value
,
index
)
=>
value
===
idBasemapsLocalstorage
[
index
]
);
// For each basemap, compare the length and id values of the layers
// if basemaps changed, return that changed occured to avoid more processing
if
(
!
isSameBasemaps
)
return
true
;
outer_block
:
{
// For each basemap from the server, compare the length and id values of the layers
for
(
const
basemapServer
of
basemapFromServer
)
{
// Prepare an array of layer ids from the server and sort them
const
idLayersServer
=
basemapServer
.
layers
.
map
((
b
)
=>
b
.
id
).
sort
();
if
(
basemapFromLocalstorage
.
length
)
{
for
(
const
basemapLocalstorage
of
basemapFromLocalstorage
)
{
if
(
basemapServer
.
id
===
basemapLocalstorage
.
id
)
{
const
idLayersLocalstorage
=
basemapLocalstorage
.
layers
.
map
((
b
)
=>
b
.
id
)
.
sort
();
isSameLayers
=
idLayersServer
.
length
===
idLayersLocalstorage
.
length
&&
idLayersServer
.
every
(
(
value
,
index
)
=>
value
===
idLayersLocalstorage
[
index
]
);
if
(
!
isSameLayers
)
{
break
outer_block
;
}
// loop over basemaps from localStorage and check if layers id match the ones from the server
for
(
const
basemapLocalstorage
of
basemapFromLocalstorage
)
{
if
(
basemapServer
.
id
===
basemapLocalstorage
.
id
)
{
const
idLayersLocalstorage
=
basemapLocalstorage
.
layers
.
map
((
b
)
=>
b
.
id
)
.
sort
();
isSameLayers
=
idLayersServer
.
length
===
idLayersLocalstorage
.
length
&&
idLayersServer
.
every
(
(
value
,
index
)
=>
value
===
idLayersLocalstorage
[
index
]
);
if
(
!
isSameLayers
)
{
break
outer_block
;
}
}
}
...
...
@@ -191,9 +194,7 @@ export default {
const
titlesBasemapsServer
=
basemapFromServer
.
map
((
b
)
=>
b
.
title
)
.
sort
();
const
titlesBasemapsLocalstorage
=
basemapFromLocalstorage
.
length
?
basemapFromLocalstorage
.
map
((
b
)
=>
b
.
title
).
sort
()
:
{};
const
titlesBasemapsLocalstorage
=
basemapFromLocalstorage
.
map
((
b
)
=>
b
.
title
).
sort
()
||
{};
isSameTitles
=
titlesBasemapsServer
.
every
(
(
title
,
index
)
=>
title
===
titlesBasemapsLocalstorage
[
index
]
...
...
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