• 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

9.73
/app/plugin/TreeColumnInResolutionRange.js
1
/**
2
 * Plugin to change opacity and font style of a layer tree node
3
 * if assigned layer is not in range
4
 */
5
Ext.define('CpsiMapview.plugin.TreeColumnInResolutionRange', {
1✔
6
    extend: 'Ext.plugin.Abstract',
7
    alias: 'plugin.cmv_tree_inresolutionrange',
8
    pluginId: 'cmv_tree_inresolutionrange',
9

10
    statics: {
11
        LINE_BREAK: '<br class="cpsi-resolution-range-popup-br" />'
12
    },
13

14
    /**
15
     * Initialize TreeColumnInResolutionRange plugin
16
     * @param {Ext.grid.column.Column} column The column to register the plugin
17
     *     for
18
     * @private
19
     */
20
    init: function (column) {
21
        const me = this;
1✔
22
        if (!(column instanceof Ext.grid.column.Column)) {
1!
23
            Ext.log.warn(
×
24
                'Plugin shall only be applied to instances of' +
25
                    ' Ext.grid.column.Column'
26
            );
27
            return;
×
28
        }
29
        const mapComponent = BasiGX.util.Map.getMapComponent();
1✔
30
        mapComponent.getStore().setChangeLayerFilterFn(me.changeLayerFilterFn);
1✔
31

32
        const map = mapComponent.getMap();
1✔
33
        const mapView = map.getView();
1✔
34

35
        mapView.on('change:resolution', function () {
1✔
36
            me.updateTreeNode(mapView);
×
37
        });
38

39
        me.cmp.up('treepanel').on('cmv-init-layertree', function () {
1✔
40
            me.updateTreeNode(mapView);
×
41
        });
42

43
        me.cmp.up('treepanel').on('boxready', function (tp) {
1✔
44
            if (tp.getStore().count()) {
×
45
                map.getView().dispatchEvent('change:resolution');
×
46
            }
47
        });
48
    },
49

50
    /**
51
     * Custom change layer filter function to be applied to store
52
     * @param {GeoExt.data.model.Layer} record An GeoExt layer model instance
53
     * @private
54
     */
55
    changeLayerFilterFn: function (record) {
56
        const layer = this;
×
57
        return layer.id === record.getOlLayer().id;
×
58
    },
59

60
    /**
61
     * When resolution changes in map: update tree nodes if needed
62
     * @param {ol.View} mapView The OL map view
63
     */
64
    updateTreeNode: function (mapView) {
65
        const me = this;
×
66
        const unit = mapView.getProjection().getUnits();
×
67
        const resolution = mapView.getResolution();
×
68
        const treepanel = me.cmp.up('treepanel');
×
69
        const nodeStore = treepanel.getStore();
×
70
        const treeNodes = nodeStore.getData();
×
71
        Ext.each(treeNodes.items, function (node) {
×
72
            const inRange = me.layerInResolutionRange(
×
73
                node.getOlLayer(),
74
                resolution
75
            );
76
            node[inRange ? 'removeCls' : 'addCls']('cpsi-tree-node-disabled');
×
77
            const descriptionBefore = node.getOlLayer().get('description');
×
78
            const description = me.getTooltipText(node, inRange, unit);
×
79
            const changed = description !== descriptionBefore;
×
80
            const layer = node.getOlLayer();
×
81
            if (layer) {
×
82
                layer.set('description', description);
×
83
            } else {
84
                Ext.log.warn(
×
85
                    'No layer associated with the tree node ' + node.get('text')
86
                );
87
            }
88

89
            if (changed) {
×
90
                node.set('qtip', description);
×
91
            }
92
        });
93
        // This triggers the rendering if any existing StyleSwitcherRadioGroups
94
        treepanel.fireEvent('itemupdate');
×
95
    },
96

97
    /**
98
     * Check if layer is visible in current resolution range
99
     *
100
     * @param {ol.layer.Base} layer The OpenLayers layer
101
     * @param {Number} currentRes The current map resolution
102
     *
103
     * @returns {Boolean} layer is in resolution range?
104
     */
105
    layerInResolutionRange: function (layer, currentRes) {
106
        if (!layer || !currentRes) {
×
107
            // It is questionable what we should return in this case, I opted for
108
            // false, since we cannot sanely determine a correct answer.
109
            return false;
×
110
        }
111
        const layerMinRes = layer.getMinResolution(); // default: 0 if unset
×
112
        const layerMaxRes = layer.getMaxResolution(); // default: Infinity if unset
×
113
        // minimum resolution is inclusive, maximum resolution exclusive
114
        const within = currentRes >= layerMinRes && currentRes < layerMaxRes;
×
115
        return within;
×
116
    },
117

118
    /**
119
     * Get tooltip text for node
120
     *
121
     * @param {Ext.data.NodeInterface} node The layer tree node
122
     * @param {Boolean} inRange Is layer in range
123
     * @param {String} unit The unit defined in current map projection
124
     *
125
     * @returns {String} The toolip text valid for current range
126
     */
127
    getTooltipText: function (node, inRange, unit) {
128
        const staticMe = CpsiMapview.plugin.TreeColumnInResolutionRange;
×
129
        if (!Ext.isDefined(node.originalQtip)) {
×
130
            node.originalQtip = node.getOlLayer().get('description') || '';
×
131
        }
132

133
        if (inRange) {
×
134
            return node.originalQtip.length > 0 ? node.originalQtip : undefined;
×
135
        }
136

137
        const currentTip = node.getOlLayer().get('description');
×
138
        if (
×
139
            currentTip &&
×
140
            (currentTip.indexOf(staticMe.LINE_BREAK) > -1 ||
141
                currentTip.indexOf('Visible') > -1)
142
        ) {
143
            return currentTip;
×
144
        }
145

146
        const description = this.enhanceTooltip(node.getOlLayer(), unit);
×
147
        return description;
×
148
    },
149

150
    /**
151
     * Adds scale restriction information to decription text
152
     * @param {ol.layer.Base} layer The OpenLayers layer
153
     * @param {String} unit The unit defined in current map projection
154
     *
155
     * @returns {String} The enhanced toolip text
156
     */
157
    enhanceTooltip: function (layer, unit) {
158
        const staticMe = CpsiMapview.plugin.TreeColumnInResolutionRange;
×
159
        let scale = '',
×
160
            maxScale,
161
            minScale;
162
        maxScale = BasiGX.util.Map.getScaleForResolution(
×
163
            layer.getMaxResolution(),
164
            unit
165
        );
166
        minScale = BasiGX.util.Map.getScaleForResolution(
×
167
            layer.getMinResolution(),
168
            unit
169
        );
170
        if (maxScale) {
×
171
            // round to nearest 10
172
            maxScale = Math.round(maxScale / 10) * 10;
×
173
            maxScale = Ext.util.Format.number(maxScale, '0,000');
×
174
        }
175
        if (minScale) {
×
176
            // round both to nearest 10
177
            minScale = Math.round(minScale / 10) * 10;
×
178
            minScale = Ext.util.Format.number(minScale, '0,000');
×
179
        }
180

181
        if (maxScale && minScale) {
×
182
            scale = Ext.String.format(
×
183
                'Visible between <b>1:{0}</b> and <b>1:{1}</b>',
184
                minScale,
185
                maxScale
186
            );
187
        } else {
188
            if (maxScale) {
×
189
                scale = Ext.String.format(
×
190
                    'Visible at <b>1:{0}</b> and above',
191
                    maxScale
192
                );
193
            }
194
            if (minScale) {
×
195
                scale = Ext.String.format(
×
196
                    'Visible at <b>1:{0}<b> and below',
197
                    minScale
198
                );
199
            }
200
        }
201
        return layer.get('description')
×
202
            ? layer.get('description').trim() + staticMe.LINE_BREAK + scale
203
            : scale;
204
    }
205
});
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