��权限没有,则隐藏 function forum_list_access_filter($forumlist, $gid, $allow = 'allowread') { global $grouplist; if (empty($forumlist)) return array(); if (1 == $gid) return $forumlist; $forumlist_filter = $forumlist; $group = $grouplist[$gid]; foreach ($forumlist_filter as $fid => $forum) { if (empty($forum['accesson']) && empty($group[$allow]) || !empty($forum['accesson']) && empty($forum['accesslist'][$gid][$allow])) { unset($forumlist_filter[$fid]); } unset($forumlist_filter[$fid]['accesslist']); } return $forumlist_filter; } function forum_filter_moduid($moduids) { $moduids = trim($moduids); if (empty($moduids)) return ''; $arr = explode(',', $moduids); $r = array(); foreach ($arr as $_uid) { $_uid = intval($_uid); $_user = user_read($_uid); if (empty($_user)) continue; if ($_user['gid'] > 4) continue; $r[] = $_uid; } return implode(',', $r); } function forum_safe_info($forum) { //unset($forum['moduids']); return $forum; } function forum_filter($forumlist) { foreach ($forumlist as &$val) { unset($val['brief'], $val['announcement'], $val['seo_title'], $val['seo_keywords'], $val['create_date_fmt'], $val['icon_url'], $val['modlist']); } return $forumlist; } function forum_format_url($forum) { global $conf; if (0 == $forum['category']) { // 列表URL $url = url('list-' . $forum['fid'], '', FALSE); } elseif (1 == $forum['category']) { // 频道 $url = url('category-' . $forum['fid'], '', FALSE); } elseif (2 == $forum['category']) { // 单页 $url = url('read-' . trim($forum['brief']), '', FALSE); } if ($conf['url_rewrite_on'] > 1 && $forum['well_alias']) { if (0 == $forum['category'] || 1 == $forum['category']) { $url = url($forum['well_alias'], '', FALSE); } elseif (2 == $forum['category']) { // 单页 $url = ($forum['threads'] && $forum['brief']) ? url($forum['well_alias'] . '-' . trim($forum['brief']), '', FALSE) : url($forum['well_alias'], '', FALSE); } } return $url; } function well_forum_alias() { $forumlist = forum_list_cache(); if (empty($forumlist)) return ''; $key = 'forum-alias'; static $cache = array(); if (isset($cache[$key])) return $cache[$key]; $cache[$key] = array(); foreach ($forumlist as $val) { if ($val['well_alias']) $cache[$key][$val['fid']] = $val['well_alias']; } return array_flip($cache[$key]); } function well_forum_alias_cache() { global $conf; $key = 'forum-alias-cache'; static $cache = array(); // 用静态变量只能在当前 request 生命周期缓存,跨进程需要再加一层缓存:redis/memcached/xcache/apc if (isset($cache[$key])) return $cache[$key]; if ('mysql' == $conf['cache']['type']) { $arr = well_forum_alias(); } else { $arr = cache_get($key); if (NULL === $arr) { $arr = well_forum_alias(); !empty($arr) AND cache_set($key, $arr); } } $cache[$key] = empty($arr) ? '' : $arr; return $cache[$key]; } ?>javascript - Clickable L.control on leaflet - Stack Overflow
最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Clickable L.control on leaflet - Stack Overflow

programmeradmin4浏览0评论

I am trying to add a L.Control element to my leaflet map. However once I added the element to my map, I noticed that its not clickable. I would like to display a form inside this L.Control element, however I cant select any elements from my drop down menus, since the clicks always go through to the map.

Here a JSfiddle: /

as well as my JS code:

var map = L.map('map').setView([0.27, 37.66], 6);

        // add an OpenStreetMap tile layer
        L.tileLayer('http://{s}.tile.osm/{z}/{x}/{y}.png', {
        attribution: '&copy; <a href="">OpenStreetMap</a> contributors'
        }).addTo(map);


        var mainMenu = L.Control.extend({
                options: {position: 'topright'},

        onAdd : function (map) { 
                this._div = L.DomUtil.create('div', 'mainMenu');
                this._div.innerHTML =  '<h3>Main Menu</h3>';

        this._div.innerHTML +=  '<h4>Data:</h4> MODIS NDVI <h4>AOI:</h4> Kenya, Africa <br><br>'
        this._div.innerHTML +=  '<h4>Indicator:</h4>'
        this._div.innerHTML +=  '<form><form id="form" class="form" action="" method="POST">' +
                        '<select name="indicator"><option value="NDVI_ABS">NDVI<br>' + 
                        '<option value="NDVI_VCI">VCI<br>' +
                        '<option value="RAIN_ABS">Precipitation<br>' +
                        '</select>';                        
        this._div.innerHTML += '<input type="submit" value="Refresh Map"  name="submit"></form>';   
        return this._div;     
                },                                  
        });
        map.addControl(new mainMenu());

Any suggestions on how to make it clickable?

I am trying to add a L.Control element to my leaflet map. However once I added the element to my map, I noticed that its not clickable. I would like to display a form inside this L.Control element, however I cant select any elements from my drop down menus, since the clicks always go through to the map.

Here a JSfiddle: http://jsfiddle/fd3dnnc1/1/

as well as my JS code:

var map = L.map('map').setView([0.27, 37.66], 6);

        // add an OpenStreetMap tile layer
        L.tileLayer('http://{s}.tile.osm/{z}/{x}/{y}.png', {
        attribution: '&copy; <a href="http://osm/copyright">OpenStreetMap</a> contributors'
        }).addTo(map);


        var mainMenu = L.Control.extend({
                options: {position: 'topright'},

        onAdd : function (map) { 
                this._div = L.DomUtil.create('div', 'mainMenu');
                this._div.innerHTML =  '<h3>Main Menu</h3>';

        this._div.innerHTML +=  '<h4>Data:</h4> MODIS NDVI <h4>AOI:</h4> Kenya, Africa <br><br>'
        this._div.innerHTML +=  '<h4>Indicator:</h4>'
        this._div.innerHTML +=  '<form><form id="form" class="form" action="" method="POST">' +
                        '<select name="indicator"><option value="NDVI_ABS">NDVI<br>' + 
                        '<option value="NDVI_VCI">VCI<br>' +
                        '<option value="RAIN_ABS">Precipitation<br>' +
                        '</select>';                        
        this._div.innerHTML += '<input type="submit" value="Refresh Map"  name="submit"></form>';   
        return this._div;     
                },                                  
        });
        map.addControl(new mainMenu());

Any suggestions on how to make it clickable?

Share Improve this question edited Dec 1, 2014 at 17:35 maRtin asked Dec 1, 2014 at 17:29 maRtinmaRtin 6,52611 gold badges45 silver badges68 bronze badges
Add a ment  | 

3 Answers 3

Reset to default 6

If you take a look at the source of L.Control.Layers which is supplied with Leaflet you can see that they use L.DomEvent to disable or stop propagation of click and/or scroll events on the container. You should do exactly the same and it will work as expected:

if (!L.Browser.touch) {
    L.DomEvent
        .disableClickPropagation(this._div)
        .disableScrollPropagation(this._div);
} else {
    L.DomEvent.on(this._div, 'click', L.DomEvent.stopPropagation);
}

An updated Fiddle: http://jsfiddle/az9w0r5L/

Did you hook up a click handler to your button? I updated your fiddle with this:

$('#refreshBtn').on('click', function () {
    alert('hello world');
});

and I get the alert.

I found a solution: I am actually not using L.Control anymore, but I decided to use a new div tag instead with the use of CSS (z-index):

JSFiddle: http://jsfiddle/fd3dnnc1/3/

#menu {
position: absolute;
width: 300px;
z-index: 100;
}


#map {
height:100%;
width:100%;
z-index: 1;
}

<div id="map"></div>
<div id="menu">Menu Content here</div>
发布评论

评论列表(0)

  1. 暂无评论