Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

No provision for kml PolyStyle <fill> tag #217

Open
Ojaybee opened this issue Apr 9, 2016 · 1 comment
Open

No provision for kml PolyStyle <fill> tag #217

Ojaybee opened this issue Apr 9, 2016 · 1 comment

Comments

@Ojaybee
Copy link

Ojaybee commented Apr 9, 2016

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;
},
@brunob
Copy link
Collaborator

brunob commented Apr 10, 2016

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants