最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Set tooltip on custom leafletjs control - Stack Overflow

programmeradmin4浏览0评论

I have made several custom buttons in Leafletjs - now I would like to add a hover-over tooltip to explain what the button does. I've tried putting a "title:" and "tooltip:" in the options but still do not see the text when I hover over the control.

var load = L.Control.extend({
    options: {
        position: 'topright'

    },

    onAdd: function(map) {
        var container = L.DomUtil.create('div', 'leaflet-bar leaflet-control leaflet-control-load-points');

        //container.style.backgroundColor = 'white';
        container.style.width = '25px';
        container.style.height = '25px';

        container.onclick = function() {
            clear_markers(markers);
            load_markers(markers);
        }
        return container;
    },
});

I have made several custom buttons in Leafletjs - now I would like to add a hover-over tooltip to explain what the button does. I've tried putting a "title:" and "tooltip:" in the options but still do not see the text when I hover over the control.

var load = L.Control.extend({
    options: {
        position: 'topright'

    },

    onAdd: function(map) {
        var container = L.DomUtil.create('div', 'leaflet-bar leaflet-control leaflet-control-load-points');

        //container.style.backgroundColor = 'white';
        container.style.width = '25px';
        container.style.height = '25px';

        container.onclick = function() {
            clear_markers(markers);
            load_markers(markers);
        }
        return container;
    },
});
Share Improve this question edited Feb 3, 2016 at 0:25 raphael 2,8435 gold badges29 silver badges57 bronze badges asked May 23, 2015 at 18:47 terra_maticsterra_matics 2393 silver badges8 bronze badges 2
  • You could try hint.css – Jonatas Walker Commented May 23, 2015 at 18:56
  • 1 The URL seems to be broken, a mere six years later. Whart on earth are the inter-tubes ing to??!! – Mawg Commented Jan 18, 2021 at 11:04
Add a ment  | 

1 Answer 1

Reset to default 7

To answer my own question I was using the wrong approach to add the title option. By creating the container first and then setting the title after I was able to populate the title field and have a tooltip work on hover over.

var load = L.Control.extend({
    options: {position: 'topright'},
    onAdd: function(map) {
        var container = L.DomUtil.create('div', 'leaflet-bar leaflet-control leaflet-control-load');
        container.title = "Enter Tooltip Here"
    }
});
发布评论

评论列表(0)

  1. 暂无评论