leaflet-plugins icon indicating copy to clipboard operation
leaflet-plugins copied to clipboard

No provision for kml PolyStyle <fill> tag

Open Ojaybee opened this issue 8 years ago • 1 comments

Even when PolyStyle is set to 00000000 polygons still had a faint fill. I've added the fill attribute to allow no fill option (full parseStyle function with additions commented):

parseStyle: function (xml) {
    var style = {}, poptions = {}, ioptions = {}, el, id;
    // added the attribute fill
    var attributes = {color: true, width: true, Icon: true, href: true, hotSpot: true, fill: true};

    function _parse (xml) {
        var options = {};
        for (var i = 0; i < xml.childNodes.length; i++) {
            var e = xml.childNodes[i];
            var key = e.tagName;
            if (!attributes[key]) { continue; }
            if (key === 'hotSpot')
            {
                for (var j = 0; j < e.attributes.length; j++) {
                    options[e.attributes[j].name] = e.attributes[j].nodeValue;
                }
            } else {
                var value = e.childNodes[0].nodeValue;
                if (key === 'color') {
                    options.opacity = parseInt(value.substring(0, 2), 16) / 255.0;
                    options.color = '#' + value.substring(6, 8) + value.substring(4, 6) + value.substring(2, 4);
                } else if (key === 'width') {
                    options.weight = value;
                } else if (key === 'Icon') {
                    ioptions = _parse(e);
                    if (ioptions.href) { options.href = ioptions.href; }
                } else if (key === 'href') {
                    options.href = value;
                } else if (key === 'fill') { // adds the key for fill
                    options.fill = value;
                }
            }
        }
        return options;
    }

    el = xml.getElementsByTagName('LineStyle');
    if (el && el[0]) { style = _parse(el[0]); }
    el = xml.getElementsByTagName('PolyStyle');
    if (el && el[0]) { poptions = _parse(el[0]); }
    if (poptions.color) { style.fillColor = poptions.color; }
    if (poptions.opacity) { style.fillOpacity = poptions.opacity; }
    // sets fillOpacity to 0 if fill tag = 0 otherwise uses alpha 
    if (poptions.fill == 0) { style.fillOpacity = poptions.fill; }
    el = xml.getElementsByTagName('IconStyle');
    if (el && el[0]) { ioptions = _parse(el[0]); }

    if (ioptions.href) {
        console.log(ioptions.href);
        style.icon = new L.KMLIcon({
            iconUrl: ioptions.href,
            shadowUrl: null,
            anchorRef: {x: ioptions.x, y: ioptions.y},
            anchorType: {x: ioptions.xunits, y: ioptions.yunits}
        });
    }

    id = xml.getAttribute('id');
    if (id && style) {
        style.id = id;
    }

    return style;
},

Ojaybee avatar Apr 09 '16 17:04 Ojaybee

Thx for the patch, can you provide a fiddle to show it in action please + propose your patch in a pull request ?

brunob avatar Apr 10 '16 08:04 brunob