Skip to content
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

inline horizontal button #88

Closed
shinnobi opened this issue Jun 10, 2019 · 11 comments
Closed

inline horizontal button #88

shinnobi opened this issue Jun 10, 2019 · 11 comments

Comments

@shinnobi
Copy link

shinnobi commented Jun 10, 2019

i want to create inline horizontal buttons ( default is vertical) how to do that (ie. add class to button)

my code is below

var fileTime = [00,12]
for (var i=0;i<fileTime.length;i++){
  (function () {
    var time = String(fileTime[i].pad(2))
    var mybutton = L.easyButton({
      id: time,
      states: [{
        icon: '<strong>' + time + '</strong>',
        onClick: function (e) {
          changeMapByButton(time)
          alert(time)
        }
      }]
    });
    mybutton.addTo(map)
  })();
}
@atstp
Copy link
Contributor

atstp commented Jun 11, 2019

You can group your buttons with L.easyBar and then style that bar with the .leaflet-bar selector.

Based on the code you shared, it would look roughly like this:

var fileTimes = [00,12];
var buttons = fileTimes.map(function(t){
    var time = String(t.pad(2))
    return L.easyButton({
      id: time,
      states: [{
        icon: '<strong>' + time + '</strong>',
        onClick: function (e) {
          changeMapByButton(time)
          alert(time)
        }
      }]
    });
  });

var bar = L.easyBar(buttons);  // wrap your buttons with an easyBar
bar.addTo(map); // add the bar to your map

then a little bit of css to get your buttons aligned:

.leaflet-bar {
    /* style your buttons horizontally here */
}

This code is untested, but the general idea should help you get started.

@shinnobi
Copy link
Author

shinnobi commented Jun 11, 2019

i have already done this but not work

my css for leafletbar
.leaflet-bar {
position: fixed;
z-index: 1000;
top: 20px;
left: 75px;
}

it move this bar to top but button didn't in one line @atstp

@atstp
Copy link
Contributor

atstp commented Jun 11, 2019

the code you shared adds each button separately. Based on what you're describing, you need to use an L.easyBar to group the buttons.

var buttons = [];                          // NOTE: use a separate array to collect the buttons
var fileTime = [00,12]
for (var i=0;i<fileTime.length;i++){
  (function () {
    var time = String(fileTime[i].pad(2))
    var mybutton = L.easyButton({
      id: time,
      states: [{
        icon: '<strong>' + time + '</strong>',
        onClick: function (e) {
          changeMapByButton(time)
          alert(time)
        }
      }]
    });
    buttons.push(mybutton)                 // NOTE: add to the buttons array instead of the map
  })();
}

var bar = L.easyBar(buttons);              // NOTE: create an easyBar with the buttons
bar.addTo(map);                            // NOTE: add the bar to the map

This will group the buttons under a parent element that you can then style to fit your needs.

@shinnobi
Copy link
Author

shinnobi commented Jun 12, 2019

@atstp as i said above i have completely done this code you mentioned but when i add my css to leaflet bar
.leaflet-bar {
position: fixed;
z-index: 1000;
top: 20px;
left: 75px;
}

it move this bar on top but button inside it didn't in one line

@atstp
Copy link
Contributor

atstp commented Jun 12, 2019

okay, in that case, I need a bit more info to give you better guidance.

First, what do you think is causing your issue, and what have you already tried to resolve it?

Also, if you share a minimal, running example, that would make it easier for me to help you.

@shinnobi
Copy link
Author

@atstp
this is mycode http://jsfiddle.net/b2zxLdor/18/

@atstp
Copy link
Contributor

atstp commented Jun 12, 2019

thanks!

What have you tried that has not worked? what did you expect, and what results did you get?

@shinnobi
Copy link
Author

done i have just fixed my problem thanks for help

@DrPDash
Copy link

DrPDash commented Dec 30, 2019

@shinnobi : can you update your jsfiddle? or show the styling snippet here? thanks

@guidez
Copy link

guidez commented Feb 26, 2020

@shinnobi You committed one of the most cardinal sins of google searches: "I fixed it!"... And you didn't provide the fix. Please. Provide. The fix.

@shinnobi
Copy link
Author

sorry for late commend i upload this code http://jsfiddle.net/w47s96pt/ for inline button
thanks you for all

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants