-
Notifications
You must be signed in to change notification settings - Fork 77
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Show number of active layers on a badge #269
Open
crisner
wants to merge
14
commits into
publiclab:main
Choose a base branch
from
crisner:issue-201-show-number-of-active-layers
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
7108446
Add a control for displaying badge
crisner 68738c2
Add styles for the badge
crisner 8601df6
Align badge
crisner ff5b714
Display badge on the map
crisner 9414af2
Move code to display number of active layers into a function
crisner 6958884
Include badge to display number of active layers
crisner 2f64322
Save layers control to a variable
crisner da8f401
Fix bug that hid the badge
crisner 6ee3bc4
Add extra parameter for layers control
crisner c03b0b4
Add badge functionality to readme file
crisner 420e2f8
Resolve merge conflicts by accepting both changes
crisner 2c5d354
Extract badge styles to a seperate stylesheet
crisner 2addd18
Copy badge stylesheet to dist on build
crisner 863687b
Add link to stylesheet in index.html and readme.md
crisner File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -29,4 +29,4 @@ z-index: 10; } | |
padding-bottom: 25px; | ||
margin-right: 65px; | ||
display: inline; | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
activeLayersBadge = function(map, leafletControl) { | ||
var touched = false; | ||
var activeOverlays = leafletControl.getActiveOverlayNames(); | ||
var badge = L.control.badge(activeOverlays.length, { position: 'topright' }).addTo(map); | ||
|
||
map.on('layeradd', function(ev) { | ||
// Displays badge on page load | ||
$(badge.getContainer()).css("display", "block"); | ||
if(touched) { | ||
$(badge.getContainer()).css("display", "none"); | ||
} | ||
}); | ||
|
||
map.on('overlayadd', function(ev) { | ||
this.removeControl(badge); | ||
$(badge.getContainer()).css("display", "none"); | ||
activeOverlays = leafletControl.getActiveOverlayNames(); | ||
badge = L.control.badge(activeOverlays.length, { position: 'topright' }).addTo(map); | ||
$(badge.getContainer()).css("display", "none"); | ||
}); | ||
|
||
map.on('overlayremove', function(ev) { | ||
this.removeControl(badge); | ||
activeOverlays = leafletControl.getActiveOverlayNames(); | ||
badge = L.control.badge(activeOverlays.length, { position: 'topright' }).addTo(map); | ||
$(badge.getContainer()).css("display", "none"); | ||
}); | ||
|
||
L.DomEvent.on(leafletControl.getContainer(), 'mouseover', function (ev) { | ||
touched = true; | ||
$(badge.getContainer()).css("display", "none"); | ||
}); | ||
|
||
L.DomEvent.on(leafletControl.getContainer(), 'mouseout', function (ev) { | ||
touched = false; | ||
$(badge.getContainer()).css("display", "block"); | ||
}); | ||
|
||
return badge; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
/*--- Badge styles ---*/ | ||
.badge { | ||
width: 30px; | ||
height: 30px; | ||
padding: 4px 2px 0; | ||
border-radius: 50px; | ||
border: 2px solid #908f8f; | ||
background: white; | ||
color: black; | ||
font-weight: bold; | ||
font-size: 1.4em; | ||
margin-left: 80%; | ||
position: absolute; | ||
text-align: center; | ||
top: 9px; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
L.Control.Badge = L.Control.extend({ | ||
|
||
initialize: function(content, options) { | ||
this.content = content; | ||
L.setOptions(this, options); | ||
}, | ||
|
||
onAdd: function(map) { | ||
var badgeElement = L.DomUtil.create('div'); | ||
|
||
badgeElement.classList.add('badge'); | ||
badgeElement.innerHTML = this.content; | ||
|
||
return badgeElement; | ||
}, | ||
|
||
onRemove: function(map) { | ||
// Nothing to do here | ||
} | ||
|
||
}); | ||
|
||
L.control.badge = function(content, options) { | ||
return new L.Control.Badge(content, options); | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Excellent!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's add this badge functionality to Readme as well. Telling that this is automatically there if you use
L.LayerGroup.EnvironmentalLayers().addTo(map);
otherwise using the above function (which calls listeners) you can add!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay 👍