Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

I have gotton some help in creating a custom control for leaflet, but I am still having trouble upgrading to the CSS styles used by the latest versions of Leaflet. Basically, all I need is a icon in the white box, with the drop shadow around it.

Here is what I have working so far, take a look and feel free to fork it:


share|improve this question
add comment

1 Answer

up vote 2 down vote accepted

Got it.

For a demo look at the CodePen Demo: http://codepen.io/DrYSG/pen/zJsiG

Here are the JS and the CSS snippets that do the relevant work:

L.Control.Command = L.Control.extend({
options: {
    position: 'topleft',

onAdd: function (map) {
    var controlDiv = L.DomUtil.create('div', 'leaflet-control-command');
        .addListener(controlDiv, 'click', L.DomEvent.stopPropagation)
        .addListener(controlDiv, 'click', L.DomEvent.preventDefault)
    .addListener(controlDiv, 'click', function () { MapShowCommand(); });

    var controlUI = L.DomUtil.create('div', 'leaflet-control-command-interior', controlDiv);
    controlUI.title = 'Map Commands';
    return controlDiv;


L.control.command = function (options) { return new L.Control.Command(options); };

and the CSS:

    background-image: url(images/command.png);
    width: 20px;
    height: 20px;
    background-position: 50% 50%;
    background-repeat: no-repeat;
    display: block;
    padding: 3px;
    border-radius: 4px;
    -webkit-border-radius: 4px;
    -moz-border-radius: 4px;
    box-shadow: 0 1px 7px rgba(0, 0, 0, 0.65);
    cursor: auto;
    text-align: center;
    background-color: #FFFFFF;

    background-color: #F4F4F4;
share|improve this answer
add comment

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.