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

geographika / cpsi-mapview / 12356785512

16 Dec 2024 04:17PM UTC coverage: 26.211% (+2.1%) from 24.092%
12356785512

push

github

geographika
Disable SSL

487 of 2328 branches covered (20.92%)

Branch coverage included in aggregate %.

1445 of 5043 relevant lines covered (28.65%)

1.16 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
        var me = this;
1✔
22
        if (!(column instanceof Ext.grid.column.Column)) {
1!
23
            Ext.log.warn('Plugin shall only be applied to instances of' +
×
24
                  ' Ext.grid.column.Column');
25
            return;
×
26
        }
27
        var mapComponent = BasiGX.util.Map.getMapComponent();
1✔
28
        mapComponent.getStore().setChangeLayerFilterFn(me.changeLayerFilterFn);
1✔
29

30
        var map = mapComponent.getMap();
1✔
31
        var mapView = map.getView();
1✔
32

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

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

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

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

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

82
            if (changed) {
×
83
                node.set('qtip', description);
×
84
            }
85
        });
86
        // This triggers the rendering if any existing StyleSwitcherRadioGroups
87
        treepanel.fireEvent('itemupdate');
×
88
    },
89

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

111
    /**
112
     * Get tooltip text for node
113
     *
114
     * @param {Ext.data.NodeInterface} node The layer tree node
115
     * @param {Boolean} inRange Is layer in range
116
     * @param {String} unit The unit defined in current map projection
117
     *
118
     * @returns {String} The toolip text valid for current range
119
     */
120
    getTooltipText: function (node, inRange, unit) {
121
        var staticMe = CpsiMapview.plugin.TreeColumnInResolutionRange;
×
122
        if (!Ext.isDefined(node.originalQtip)) {
×
123
            node.originalQtip = node.getOlLayer().get('description') || '';
×
124
        }
125

126
        if (inRange) {
×
127
            return node.originalQtip.length > 0 ? node.originalQtip : undefined;
×
128
        }
129

130
        var currentTip = node.getOlLayer().get('description');
×
131
        if (currentTip && (currentTip.indexOf(staticMe.LINE_BREAK) > -1 ||
×
132
            currentTip.indexOf('Visible') > -1)) {
133
            return currentTip;
×
134
        }
135

136
        var description = this.enhanceTooltip(node.getOlLayer(), unit);
×
137
        return description;
×
138
    },
139

140
    /**
141
     * Adds scale restriction information to decription text
142
     * @param {ol.layer.Base} layer The OpenLayers layer
143
     * @param {String} unit The unit defined in current map projection
144
     *
145
     * @returns {String} The enhanced toolip text
146
     */
147
    enhanceTooltip: function (layer, unit) {
148
        var staticMe = CpsiMapview.plugin.TreeColumnInResolutionRange;
×
149
        var scale = '', maxScale, minScale;
×
150
        maxScale = BasiGX.util.Map.getScaleForResolution(layer.getMaxResolution(), unit);
×
151
        minScale = BasiGX.util.Map.getScaleForResolution(layer.getMinResolution(), unit);
×
152
        if (maxScale) {
×
153
            // round to nearest 10
154
            maxScale = Math.round(maxScale / 10) * 10;
×
155
            maxScale = Ext.util.Format.number(maxScale, '0,000');
×
156
        }
157
        if (minScale) {
×
158
            // round both to nearest 10
159
            minScale = Math.round(minScale / 10) * 10;
×
160
            minScale = Ext.util.Format.number(minScale, '0,000');
×
161
        }
162

163
        if (maxScale && minScale) {
×
164
            scale = Ext.String.format('Visible between <b>1:{0}</b> and <b>1:{1}</b>', minScale, maxScale);
×
165
        } else {
166
            if (maxScale) {
×
167
                scale = Ext.String.format('Visible at <b>1:{0}</b> and above', maxScale);
×
168
            }
169
            if (minScale) {
×
170
                scale = Ext.String.format('Visible at <b>1:{0}<b> and below', minScale);
×
171
            }
172
        }
173
        return layer.get('description') ?
×
174
            (layer.get('description').trim() + staticMe.LINE_BREAK + scale) :
175
            scale;
176
    }
177

178
});
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