权限没有,则隐藏 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 - Unable to use Custom Icons in Leaflet - Stack Overflow
最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Unable to use Custom Icons in Leaflet - Stack Overflow

programmeradmin9浏览0评论

Continuing with the map navigation application I am trying to create, I have encountered the following error:

I parse the OSM tile and get a list of all the Points of Interest. This is successful. I then want to put a marker in Leaflet, using a few custom icons. The code for the mentioned parts is as follows

First the includes:

<link rel="stylesheet"href="./includes/leaflet.css" />
<link rel="stylesheet" href="./includes/style.css" type="text/css">
<script src=".5/leaflet.js"></script>
<script src="./includes/jquery.js"></script>
<script src="./includes/geo.js" type="text/javascript"></script>
<script src="./includes/gears_init.js" type="text/javascript"></script>
<script type="text/javascript">

For those nav Points that are found I have a custom icon like this:

if($.inArray(EleID, MarkerArray)==-1)
                {

                    if(LocType!="")
                    {
                        var markerLocation = new L.LatLng(EleLat,EleLon);
                        var Icon = new CustomIcon("./images/"+LocType+".png");
                        var marker = new L.Marker(markerLocation,{icon : Icon});

                        if(EleText!="")
                        {
                            marker.bindPopup(EleText);

                        }

                        Layergroup.addLayer(marker);
                        MarkerArray.push(EleID);
                    }

                }

These icons are in the ./image/ directory ,with their type being the name of the icon (p.ex. hotel in hotel.png)

Finally I create the map in the Body Section of the HTML document

var map = new L.Map('map');


        var cloudmadeUrl = '/{z}/{x}/{y}.png',
            cloudmadeAttrib = 'Map data CC-BY-SA &amp; ODbL 2012 OpenStreetMap contributors, Data via <a href="/">Overpass API</a>',
            cloudmade = new L.TileLayer(cloudmadeUrl, {maxZoom: 18, attribution: cloudmadeAttrib});


        var CustomIcon = L.Icon.extend({
            iconUrl: './images/hotel.png',
            shadowUrl: './images/shadow.png',
            iconSize: new L.Point(32, 32),
            opacity: 0.5,
            //shadowSize: new L.Point(68, 95),
            iconAnchor: new L.Point(16, 16),
            popupAnchor: new L.Point(0, -18)
        });

While this worked great with an old leaflet script I had, it doesnt work with the updated version I am working with giving me this error:


Uncaught Error: iconUrl not set in Icon options (see the docs). leaflet.js:6


I am not exactly sure where the IconURL is being set inside the leaflet, does anyone have any idea what I am doing wrong?

Continuing with the map navigation application I am trying to create, I have encountered the following error:

I parse the OSM tile and get a list of all the Points of Interest. This is successful. I then want to put a marker in Leaflet, using a few custom icons. The code for the mentioned parts is as follows

First the includes:

<link rel="stylesheet"href="./includes/leaflet.css" />
<link rel="stylesheet" href="./includes/style.css" type="text/css">
<script src="http://cdn.leafletjs./leaflet-0.5/leaflet.js"></script>
<script src="./includes/jquery.js"></script>
<script src="./includes/geo.js" type="text/javascript"></script>
<script src="./includes/gears_init.js" type="text/javascript"></script>
<script type="text/javascript">

For those nav Points that are found I have a custom icon like this:

if($.inArray(EleID, MarkerArray)==-1)
                {

                    if(LocType!="")
                    {
                        var markerLocation = new L.LatLng(EleLat,EleLon);
                        var Icon = new CustomIcon("./images/"+LocType+".png");
                        var marker = new L.Marker(markerLocation,{icon : Icon});

                        if(EleText!="")
                        {
                            marker.bindPopup(EleText);

                        }

                        Layergroup.addLayer(marker);
                        MarkerArray.push(EleID);
                    }

                }

These icons are in the ./image/ directory ,with their type being the name of the icon (p.ex. hotel in hotel.png)

Finally I create the map in the Body Section of the HTML document

var map = new L.Map('map');


        var cloudmadeUrl = 'http://a.tile.openstreetmap/{z}/{x}/{y}.png',
            cloudmadeAttrib = 'Map data CC-BY-SA &amp; ODbL 2012 OpenStreetMap contributors, Data via <a href="http://www.overpass-api.de/">Overpass API</a>',
            cloudmade = new L.TileLayer(cloudmadeUrl, {maxZoom: 18, attribution: cloudmadeAttrib});


        var CustomIcon = L.Icon.extend({
            iconUrl: './images/hotel.png',
            shadowUrl: './images/shadow.png',
            iconSize: new L.Point(32, 32),
            opacity: 0.5,
            //shadowSize: new L.Point(68, 95),
            iconAnchor: new L.Point(16, 16),
            popupAnchor: new L.Point(0, -18)
        });

While this worked great with an old leaflet script I had, it doesnt work with the updated version I am working with giving me this error:


Uncaught Error: iconUrl not set in Icon options (see the docs). leaflet.js:6


I am not exactly sure where the IconURL is being set inside the leaflet, does anyone have any idea what I am doing wrong?

Share Improve this question edited Jun 14, 2013 at 7:50 Adil Shaikh 44.7k17 gold badges95 silver badges112 bronze badges asked Jun 14, 2013 at 7:49 SpyrosSpyros 1971 gold badge5 silver badges17 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 7

When defining your CustomIcon by extending L.Icon.extend(), you have to wrap your options up in the options object. Like so:

var CustomIcon = L.Icon.extend({
   options: {
        iconUrl: './images/hotel.png',
        shadowUrl: './images/shadow.png',
        iconSize: new L.Point(32, 32),
        opacity: 0.5,
        //shadowSize: new L.Point(68, 95),
        iconAnchor: new L.Point(16, 16),
        popupAnchor: new L.Point(0, -18)
      }
    });
发布评论

评论列表(0)

  1. 暂无评论