• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

compassinformatics / cpsi-mapview / 15022980938

14 May 2025 02:11PM UTC coverage: 26.333% (+0.04%) from 26.29%
15022980938

push

github

geographika
Move describe to test globals

492 of 2344 branches covered (20.99%)

Branch coverage included in aggregate %.

1464 of 5084 relevant lines covered (28.8%)

1.17 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

10.96
/app/plugin/BasicTreeColumnLegends.js
1
/**
2
 * A plugin for Ext.grid.column.Column that overwrites the internal cellTpl to
3
 * support legends.
4
 */
5
Ext.define('CpsiMapview.plugin.BasicTreeColumnLegends', {
1✔
6
    extend: 'Ext.plugin.Abstract',
7
    alias: 'plugin.cmv_basic_tree_column_legend',
8
    pluginId: 'cmv_basic_tree_column_legend',
9

10
    requires: ['CpsiMapview.util.Legend'],
11

12
    /**
13
     * @private
14
     */
15
    originalCellTpl: Ext.clone(Ext.tree.Column.prototype.cellTpl).join(''),
16

17
    /**
18
     * The Xtemplate strings that will be used instead of the plain {value}
19
     * when rendering
20
     * We add a additional div in order to expand and collapse the legends. The syntax in templates is picky here...
21
     */
22
    valueReplacementTpl: [
23
        '{value}',
24
        '<tpl if="this.hasLegend(values.record)"><br />',
25
        '<tpl for="lines">',
26
        '<img src="{parent.blankUrl}"',
27
        ' class="{parent.childCls} {parent.elbowCls}-img ',
28
        '{parent.elbowCls}-<tpl if=".">line<tpl else>empty</tpl>"',
29
        ' role="presentation"/>',
30
        '</tpl>',
31
        '<img src="{blankUrl}" class="{childCls} x-tree-elbow-img">',
32
        '<img src="{blankUrl}" class="{childCls} x-tree-elbow-img">',
33
        '<img src="{blankUrl}" class="{childCls} x-tree-elbow-img">',
34
        '{[this.getLegendHtml(values.record)]}',
35
        '</tpl>'
36
    ],
37

38
    /**
39
     * The context for methods available in the template
40
     */
41
    valueReplacementContext: {
42
        hasLegend: function (rec) {
43
            const isChecked = rec.get('checked');
×
44
            const layer = rec.data;
×
45
            return isChecked && !(layer instanceof ol.layer.Group);
×
46
        },
47
        getLegendHtml: function (rec) {
48
            const staticMe = CpsiMapview.plugin.BasicTreeColumnLegends;
×
49
            const layer = rec.data;
×
50
            let layerKey = layer.get('layerKey');
×
51

52
            // a layer can have different legends for different styles
53
            // ensure each of these are cached
54
            if (layer.getSource && layer.getSource().getParams) {
×
55
                const styles = layer.getSource().getParams().STYLES;
×
56
                if (styles) {
×
57
                    layerKey += '_' + styles.toUpperCase();
×
58
                }
59
            } else {
60
                // for WFS we also use the WMS legend so make sure we create a cache
61
                // key for these or it will always use just the layerKey
62
                const activatedStyle = layer.get('activatedStyle');
×
63
                if (activatedStyle) {
×
64
                    layerKey += '_' + activatedStyle.toUpperCase();
×
65
                }
66
            }
67

68
            let legendUrl = layer.get('legendUrl');
×
69
            let w = layer.get('legendWidth');
×
70
            let h = layer.get('legendHeight');
×
71

72
            if (!legendUrl) {
×
73
                legendUrl = LegendUtil.createGetLegendGraphicUrl(layer);
×
74
            }
75
            // if the legend cannot be obtained (which happens e.g. for cascaded
76
            // WMS layers, as geoserver does not support legends for these
77
            // layers) we remove the broken image and the other dom elements
78
            // that otherwise would lead to vertical gap between layers in the
79
            // tree.
80
            if (!legendUrl) {
×
81
                // 1px×1px transparent gif
82
                legendUrl = staticMe.transparentGif;
×
83
                w = h = 1;
×
84
            }
85

86
            const legendDataUrl =
87
                CpsiMapview.view.LayerTree.legendImgLookup[layerKey];
×
88
            if (!legendDataUrl) {
×
89
                // load the legend image and cache it in an static lookup for later re-use
90
                // without any server request
91

92
                // check if there is an ongoing loading for the legend of this layer
93
                // since getLegendHtml is executed several times for one refresh due to
94
                // unknown reasons
95
                // Flag set / reset in LegendUtil.getLegendImgHtmlTpl
96
                const isLoading = LegendUtil['legendLoading_' + layerKey];
×
97
                if (isLoading) {
×
98
                    // skip loading
99
                    return LegendUtil.getLegendImgHtmlTpl(legendUrl, w, h);
×
100
                }
101

102
                LegendUtil.cacheLegendImgAsDataUrl(legendUrl, layerKey);
×
103
            } else {
104
                legendUrl = legendDataUrl;
×
105
            }
106

107
            return LegendUtil.getLegendImgHtmlTpl(legendUrl, w, h);
×
108
        }
109
    },
110

111
    statics: {
112
        transparentGif:
113
            'data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP' +
114
            '///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7',
115
        checkCleanup: function (img) {
116
            const staticMe = CpsiMapview.plugin.BasicTreeColumnLegends;
×
117
            const el = Ext.get(img);
×
118
            const w = parseInt(el.getAttribute('width'), 10);
×
119
            const h = parseInt(el.getAttribute('height'), 10);
×
120
            const src = el.getAttribute('src');
×
121
            if (w === 1 && h === 1 && src === staticMe.transparentGif) {
×
122
                const parent = Ext.get(img.parentNode);
×
123
                const removeElems = parent.query('br, img');
×
124
                Ext.each(removeElems, function (removeElem) {
×
125
                    Ext.get(removeElem).destroy();
×
126
                });
127
            }
128
        }
129
    },
130

131
    init: function (column) {
132
        const me = this;
1✔
133
        if (!(column instanceof Ext.grid.column.Column)) {
1!
134
            Ext.log.warn(
×
135
                'Plugin shall only be applied to instances of' +
136
                    ' Ext.grid.column.Column'
137
            );
138
            return;
×
139
        }
140
        const valuePlaceHolderRegExp = /\{value\}/g;
1✔
141
        const replacementTpl = me.valueReplacementTpl.join('');
1✔
142
        const newCellTpl = me.originalCellTpl.replace(
1✔
143
            valuePlaceHolderRegExp,
144
            replacementTpl
145
        );
146

147
        column.cellTpl = [newCellTpl, me.valueReplacementContext];
1✔
148
    }
149
});
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc