• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In
You are now the owner of this repo.

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

1.09
/app/controller/MapController.js
1
/**
2
 * This class is the controller for the map view of cpsi mapview
3
 *
4
 */
5
Ext.define('CpsiMapview.controller.MapController', {
1✔
6
    extend: 'Ext.app.ViewController',
7

8
    alias: 'controller.cmv_map',
9

10
    requires: ['BasiGX.util.Map'],
11

12
    mixins: {
13
        editWindowOpenerMixin: 'CpsiMapview.util.EditWindowOpenerMixin'
14
    },
15

16
    /**
17
     * A configuration object to store settings relating to opening forms when clicking on a feature.
18
     * This should be overridden in inherited projects and should be in the following form:
19
     *
20
     * {
21
     *   layerKeyName: {
22
     *       keyField: 'ObjectId', // the field containing the unique feature Id to open in a form
23
     *       modelClass: 'CpsiMapview.model.ModelName', // the name of the class used to load a model
24
     *       editWindowClass: 'CpsiMapview.view.EditWindow' // the name of the form view class to open when clicking on a feature
25
     *   }
26
     * }
27
     *
28
     * You also use a function to return a configuration object which returns an Id instead of a
29
     * keyField which allows custom logic to be applied. The function receives a single argument which
30
     * is the clicked ol.Feature
31
     * {
32
     *   layerKeyName: function (feat) {
33
     *       return {
34
     *           id: Math.abs(feat.get('ObjectId')), // the unique feature Id to open in a form
35
     *           modelClass: 'CpsiMapview.model.ModelName', // the name of the class used to load a model
36
     *           editWindowClass: 'CpsiMapview.view.EditWindow' // the name of the form view class to open when clicking on a feature
37
     *       }
38
     *   }
39
     * }
40
     *
41
     * Multiple configurations can be provided to support clicks on multiple layers
42
     */
43
    clickableLayerConfigs: {},
44

45
    /**
46
     * Handle map clicks so data entry forms can be opened by clicking directly
47
     * on vector features
48
     * @param {any} clickedFeatures
49
     */
50
    onMapClick: function (clickedFeatures) {
51
        let feat, recId;
52
        const me = this;
×
53

54
        // Prevent triggering other map events, if we click on the coordinate marker
55
        const coordinateMousePanel = Ext.ComponentQuery.query(
×
56
            'basigx-panel-coordinatemouseposition'
57
        )[0];
58
        if (coordinateMousePanel) {
×
59
            const coordinateMarker = Ext.Array.findBy(
×
60
                clickedFeatures,
61
                function (clickedFeature) {
62
                    return coordinateMousePanel.fireEvent(
×
63
                        'isMapMarker',
64
                        clickedFeature.feature
65
                    );
66
                }
67
            );
68
            if (coordinateMarker) {
×
69
                coordinateMousePanel.fireEvent('removeMarker');
×
70
                return false;
×
71
            }
72
        }
73
        // avoid opening the form if another tool is active (see CpsiMapview.util.ApplicationMixin)
74
        const map = me.getView().map;
×
75
        if (map.get('defaultClickEnabled') === false) {
×
76
            return;
×
77
        }
78

79
        // filter out any features without the layer we want
80
        const editableFeatures = [];
×
81

82
        Ext.each(clickedFeatures, function (f) {
×
83
            if (f.layer) {
×
84
                const layerKey = f.layer.get('layerKey');
×
85
                if (
×
86
                    Object.prototype.hasOwnProperty.call(
87
                        me.clickableLayerConfigs,
88
                        layerKey
89
                    )
90
                ) {
91
                    editableFeatures.push(f);
×
92
                }
93
            }
94
        });
95

96
        if (editableFeatures.length > 0) {
×
97
            const editableFeature = editableFeatures[0].feature; // get the first feature
×
98
            const selectedLayerKey = editableFeatures[0].layer.get('layerKey'); // get layer for feature
×
99

100
            const featureCluster = editableFeature.getProperties().features;
×
101

102
            if (featureCluster) {
×
103
                feat = featureCluster[0];
×
104
            } else {
105
                feat = editableFeature;
×
106
            }
107

108
            // get the window and model types
109
            const selectedLayerConfig =
110
                me.clickableLayerConfigs[selectedLayerKey];
×
111
            let configObject;
112

113
            if (typeof selectedLayerConfig === 'function') {
×
114
                configObject = selectedLayerConfig(feat) || {};
×
115
                recId = configObject.id;
×
116
            } else {
117
                configObject = selectedLayerConfig;
×
118
                recId = feat.get(configObject.keyField);
×
119
            }
120

121
            if (!recId) {
×
122
                // return early and stop other map handlers
123
                return false;
×
124
            }
125

126
            const modelClass = configObject.modelClass;
×
127
            const editWindowClass = configObject.editWindowClass;
×
128

129
            const modelPrototype = Ext.ClassManager.get(modelClass);
×
130

131
            // check if the window is already open
132
            let win = me.getExistingEditingFormWindow(recId, editWindowClass);
×
133

134
            // if the record is not already opened, create a new window and load the record
135
            if (win === null) {
×
136
                modelPrototype.load(recId, {
×
137
                    success: function (rec) {
138
                        win = Ext.create(editWindowClass);
×
139
                        const vm = win.getViewModel();
×
140
                        vm.set('currentRecord', rec);
×
141
                        win.show();
×
142
                    },
143
                    failure: function () {
144
                        Ext.toast({
×
145
                            html: 'Cannot load the record with id ' + recId,
146
                            title: 'Record Loading Failed',
147
                            width: 200,
148
                            align: 'br'
149
                        });
150
                    }
151
                });
152
            } else {
153
                // if the window is minimised make sure it is restored
154
                if (win.isMinimized) {
×
155
                    win.show();
×
156
                }
157
                Ext.WindowManager.bringToFront(win);
×
158
            }
159

160
            return false; // stop other map handlers
×
161
        }
162
    },
163

164
    /**
165
     * Function called after render of map component
166
     */
167
    afterMapRender: function () {
168
        const me = this;
×
169
        const mapPanel = me.getView();
×
170

171
        if (mapPanel.addScaleBarToMap) {
×
172
            const removeCtrls = [];
×
173
            // Cleanup existing controls first
174
            mapPanel.olMap.getControls().forEach(function (ctrl) {
×
175
                if (ctrl instanceof ol.control.ScaleLine) {
×
176
                    removeCtrls.push(ctrl);
×
177
                }
178
            });
179
            Ext.each(removeCtrls, function (removeCtrl) {
×
180
                mapPanel.olMap.removeControl(removeCtrl);
×
181
            });
182

183
            const sbTarget =
184
                mapPanel.body && mapPanel.body.dom
×
185
                    ? mapPanel.body.dom
186
                    : mapPanel.getEl().dom;
187
            const scaleLineCtrl = new ol.control.ScaleLine({
×
188
                target: sbTarget
189
            });
190
            mapPanel.olMap.addControl(scaleLineCtrl);
×
191
        }
192
    }
193
});
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