Scroll in layer menu

1,261 views
Skip to first unread message

Jean-Michel Vien

unread,
Mar 13, 2014, 12:02:15 AM3/13/14
to leafl...@googlegroups.com
Hi,

I am making a map with over 20 layers or marker group. The problem is that for user with lower resolution than mine or with mobile devices can't see all layers since the menu is longer than screen.... it also apply while I am not in fullscreen mode, I can't see the lastest items in the menu unless I go to fullscreen.

Is it possible to have a scroll bar when the menu size is higher than the div size ?

aston...@gmail.com

unread,
Mar 13, 2014, 7:41:28 AM3/13/14
to leafl...@googlegroups.com

autod...@gmail.com

unread,
Mar 13, 2014, 4:44:23 PM3/13/14
to leafl...@googlegroups.com
Have you thought about writing your own layer controller?

Jean-Michel Vien

unread,
Mar 13, 2014, 4:55:45 PM3/13/14
to leafl...@googlegroups.com
‎Not at all... I was wondering if there was an easy way to go... I am far from being javascript dev...

Jean-Michel Vien

Sent from my BlackBerry 10 smartphone‎
Sent: Thursday, March 13, 2014 16:44
Subject: [Leaflet] Re: Scroll in layer menu

--

---
You received this message because you are subscribed to a topic in the Google Groups "Leaflet" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/leaflet-js/FfMifbzrptY/unsubscribe.
To unsubscribe from this group and all its topics, send an email to leaflet-js+...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Charlie Geiger

unread,
Mar 13, 2014, 9:07:35 PM3/13/14
to leafl...@googlegroups.com
I was able to implement this into my project. If you have mobile and desktop users running the same application it requires some trickery in terms of setting css to hide/display elements based upon the device / window width. Here is part of what I have done to provide a completely different UI/UX to mobile and desktop users.

JavaScript/jQuery

//Create desktop layer control 
var layerControlDesktop = new L.control.layers( baseLayers, overlays, {collapsed: true} );
layerControlDesktop.addTo(map);

//Create mobile layer control
var layerControlMobile = new L.control.layers( baseLayers, overlays, {collapsed: false} );
layerControlMobile.addTo(map);

//Append layer control to specific div
$('#yourWrapperDiv').append( layerControlMobile.onAdd(map) ).addClass('mobileSettings');

CSS

/* MOBILE */
@media(max-width:500px) {
    .leaflet-control-layers:nth-of-type(1){
        display: block;
    }
    .leaflet-control-layers:nth-of-type(2){
        display: none;
    }
    #yourWrapperDiv {
        max-height: 150px;
        overflow-x: hidden;
        overflow-y: scroll;
        -webkit-overflow-scrolling: touch;
    }
}

/* DESKTOP */
@media(min-width:500px) {
    .leaflet-control-layers:nth-of-type(1){
        display: none;
    }
    .leaflet-control-layers:nth-of-type(2) {
        display: block;
    }
}

The idea then would be to set a max height to the specific div that you appended the layer menu to so that mobile users can scroll, and the desktop users get the regular native layer menu. The next step after getting the mobile layers nested inside of a div would be to style those list items differently so they do not look out of place. Another good idea would be to have the height of the wrapper toggle, I currently have my inside of an expandable div that responds to touch input and it saves space for when the user does not need access to the options. I attached an image to give you an idea of what you can do in terms of completely obfuscating the original layer menu into something new.
settings.png

Jean-Michel Vien

unread,
Mar 13, 2014, 10:05:57 PM3/13/14
to leafl...@googlegroups.com
Thanks ! I'll test it soon.

Thanks again !

Jean-Michel Vien

Sent from my BlackBerry 10 smartphone‎
From: Charlie Geiger
Sent: Thursday, March 13, 2014 21:07
Subject: [Leaflet] Re: Scroll in layer menu

Jean-Michel Vien

unread,
Mar 14, 2014, 12:49:24 AM3/14/14
to leafl...@googlegroups.com
Solved by a reply into a similar post made after mine:


Bryan McBride
Mar 13 (1 hour ago)
The easies thing to do is set a max-height on the layer control and allow users to scroll by overriding the leaflet-control-layers class with something like this:

.leaflet-control-layers {
  max-height: 200px;
  overflow: auto;
}

BRYAN
Reply all
Reply to author
Forward
0 new messages