Leaflet / Leaflet.Icon.Glyph

Add glyphs from icon fonts to your LeafletJS markers
130 stars 45 forks source link

Can not use marker option pane #7

Closed EmiyaGm closed 7 years ago

EmiyaGm commented 7 years ago

options.pane = '111111111'; let marker = L.marker(latlng, options);

Uncaught TypeError: Cannot read property 'appendChild' of undefined

IvanSanchez commented 7 years ago

Can you publish a fiddle/codepen/playground that displays this behaviour?

EmiyaGm commented 7 years ago
var map = L.map('map',{
                crs:L.CRS.EPSG3857, 
                attributionControl: false
            }).setView([30, 104], 5);
            let osm = L.tileLayer.chinaProvider('GaoDe.Normal.Map',{});
            osm.addTo(map);
function addMarker(latlng,map,options,imgUrl,callBack){
        if(imgUrl){
            L.Icon.Glyph.MDI = L.Icon.Glyph.extend({
                options: {
                    prefix: 'mdi',
                    iconUrl: imgUrl.url,
                    iconSize: [imgUrl.width, imgUrl.height],
                    bgSize : {
                        x: imgUrl.bgwidth,
                        y: imgUrl.bgheight
                    }
                }
            });
            // Factory
            L.icon.glyph.mdi = function(options) { return new L.Icon.Glyph.MDI(options); };

            if(options){
                options.icon = L.icon.glyph.mdi({ glyph: 'package' });
            }else {
                options = {
                    icon : L.icon.glyph.mdi({ glyph: 'package' })
                };
            }
            options.pane = 'pane_test';
            let marker = L.marker(latlng, options);
            let layer = marker.addTo(map);
            if(callBack){
                callBack();
            }
            return layer;
        }else {
            let marker = L.marker(latlng);
            let layer = marker.addTo(map);
            if(callBack){
                callBack();
            }
            return layer;
        }

    }
var imgUrl = {
        url : '../dist/images/定位_normal.png',
        width : 26,
        height : 32,
        bgwidth : 26,
        bgheight : 32
    }
    var marker_options = {
        draggable : true
    }
addMarker([30,104],map,marker_options,imgUrl);
IvanSanchez commented 7 years ago

And where's the map.createPane() call?

EmiyaGm commented 7 years ago

Sorry,It's my problem, and my understanding of pane was wrong。You can close it