Snippets

Piotr Szrajber Smart M.App - disable white stroke in the choropleth

Created by Piotr Szrajber
/*
* Smart M.App - remove white stroke from the choropleth style
* 2018-10-08 Piotr Szrajber <piotr.szrajber@hexagon.com>
*/

// waits until choropleth widget is ready
function waitForChoropleths(callback) {
    gsp.bi.stage.findWidgets({
        descriptors: [{
            chartM: {
                chart: "choropleth"
            }
        }]
    }, function(widgets) {
        if (!widgets || !widgets[0]) {
            TIMEOUT = setTimeout(function() {
                waitForChoropleths(callback);
            }, 500);
        } else {
            clearTimeout(TIMEOUT);
            callback(widgets);
        }
    });
}

// modify style of the geometries
function overwriteStyle(widget) {
    /*
    {
        "stroke": true,
        "color": "#ffffff",
        "weight": 2,
        "opacity": 0.9,
        "fill": true,
        "fillColor": "#cccccc",
        "fillOpacity": 0.9,
        "fillRule": "evenodd",
        "dashArray": null,
        "lineCap": "round",
        "lineJoin": "round",
        "clickable": true,
        "pointerEvents": "auto",
        "className": "",
        "radius": 10,
        "strokeColor": "#ffffff",
        "strokeOpacity": 0.9,
        "strokeWidth": 2,
        "strokeLineCap": "round",
        "strokeLineJoin": "round"
    }
    */

    let painter = widget.chart.painter(),
        defaultStyle = painter.defaultStyle(),
        paintStyle = painter.paintStyle(),
        clearStyle = painter.clearStyle();

    defaultStyle.stroke = false;
    defaultStyle.weight = 0;
    painter.defaultStyle(defaultStyle);

    clearStyle.stroke = false;
    clearStyle.weight = 0;
    painter.clearStyle(clearStyle);

    painter.paintStyle((feature) => {
        let style = paintStyle.call(this, feature);
        style.stroke = false;
        style.weight = 0;
        return style;
    });
}

function repaint(widget) {
    let painter = widget.chart.painter();
    painter.unmount();
    painter.mount();
    painter.paint();
}

waitForChoropleths((widgets) => {
    overwriteStyle(widgets[0]);
    repaint(widgets[0]);
});

Comments (0)

HTTPS SSH

You can clone a snippet to your computer for local editing. Learn more.